BUGFIX Setting ParentID of translated record if recursively creating parents in Translatable::onBeforeWrite()

BUGFIX Fixing inline form action for "create translation"
BUGFIX Removed link to "original page" for a translation - no longer valid
MINOR documentation for Translatable

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@73342 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-03-18 17:13:23 +00:00
parent 835b2e40c4
commit 93bb76dd10

View File

@ -19,16 +19,45 @@
* </example> * </example>
* Make sure to rebuild the database through /dev/build after enabling translatable. * Make sure to rebuild the database through /dev/build after enabling translatable.
* *
* <h2>Usage</h2>
*
* Getting a translation for an existing instance:
* <example>
* $translatedObj = DataObject::get_one_by_lang('MyObject', 'de');
* </example>
*
* Getting a translation for an existing instance:
* <example>
* $obj = DataObject::get_by_id('MyObject', 99); // original language
* $translatedObj = $obj->getTranslation('de');
* </example>
*
* Getting translations through {@link Translatable::set_reading_lang()}.
* This is *not* a recommended approach, but sometimes inavoidable (e.g. for {@link Versioned} methods).
* <example>
* $obj = DataObject::get_by_id('MyObject', 99); // original language
* $translatedObj = $obj->getTranslation('de');
* </example>
*
* Creating a translation:
* <example>
* $obj = new MyObject();
* $translatedObj = $obj->createTranslation('de');
* </example>
*
* <h2>Usage for SiteTree</h2> * <h2>Usage for SiteTree</h2>
* Translatable can be used for pages as well.
* *
* * Translatable can be used for subclasses of {@link SiteTree} as well.
* <h2>"Default" languages</h2> * If a child page translation is requested without the parent
* * page already having a translation in this language, the extension
* Important: If the "default language" of your site is not english (en_US), * will recursively create translations up the tree.
* please ensure to set the appropriate default language for * Caution: The "URLSegment" property is enforced to be unique across
* your content before building the database with Translatable enabled: * languages by auto-appending the language code at the end.
* Translatable::set_default_language(<locale>); * You'll need to ensure that the appropriate "reading language" is set
* before showing links to other pages on a website: Either
* through setting $_COOKIE['lang'], $_SESSION['lang'] or $_GET['lang'].
* Pages in different languages can have different publication states
* through the {@link Versioned} extension.
* *
* <h2>Translation groups</h2> * <h2>Translation groups</h2>
* *
@ -47,6 +76,13 @@
* is stored and represented in UTF-8 (Unicode). Please make sure your database and * is stored and represented in UTF-8 (Unicode). Please make sure your database and
* HTML-templates adjust to this. * HTML-templates adjust to this.
* *
* <h2>"Default" languages</h2>
*
* Important: If the "default language" of your site is not english (en_US),
* please ensure to set the appropriate default language for
* your content before building the database with Translatable enabled:
* Translatable::set_default_language(<locale>);
*
* <h2>Uninstalling/Disabling</h2> * <h2>Uninstalling/Disabling</h2>
* *
* Disabling Translatable after creating translations will lead to all * Disabling Translatable after creating translations will lead to all
@ -578,6 +614,8 @@ class Translatable extends DataObjectDecorator {
} }
// Specific logic for SiteTree subclasses. // Specific logic for SiteTree subclasses.
// If page has untranslated parents, create (unpublished) translations
// of those as well to avoid having inaccessible children in the sitetree.
// Caution: This logic is very sensitve to eternal loops when translation status isn't determined properly // Caution: This logic is very sensitve to eternal loops when translation status isn't determined properly
if($this->owner->hasField('ParentID')) { if($this->owner->hasField('ParentID')) {
if( if(
@ -585,7 +623,8 @@ class Translatable extends DataObjectDecorator {
&& $this->owner->ParentID && $this->owner->ParentID
&& !$this->owner->Parent()->hasTranslation($this->owner->Lang) && !$this->owner->Parent()->hasTranslation($this->owner->Lang)
) { ) {
$this->owner->Parent()->createTranslation($this->owner->Lang); $parentTranslation = $this->owner->Parent()->createTranslation($this->owner->Lang);
$this->owner->ParentID = $parentTranslation->ID;
} }
} }
@ -722,23 +761,6 @@ class Translatable extends DataObjectDecorator {
} }
} }
$origLangName = i18n::get_language_name($originalRecord->Lang);
// add link back to original page
$originalRecordLink = sprintf(
_t('Translatable.ORIGINALLINK', 'Show original page in %s', PR_MEDIUM, 'Show in specific language'),
$origLangName
);
$originalRecordHTML = sprintf('<p><a href="%s">%s</a></p>',
sprintf('admin/show/%d/?lang=%s', $originalRecord->ID, Translatable::default_lang()),
$originalRecordLink
);
$fields->addFieldsToTab(
'Root',
new Tab(_t('Translatable.TRANSLATIONS', 'Translations'),
new LiteralField('OriginalTranslationLink', $originalRecordHTML)
)
);
} elseif($this->owner->isNew()) { } elseif($this->owner->isNew()) {
$fields->addFieldsToTab( $fields->addFieldsToTab(
'Root', 'Root',
@ -760,7 +782,7 @@ class Translatable extends DataObjectDecorator {
// We'd still want to show the default lang though, // We'd still want to show the default lang though,
// as records in this language might have NULL values in their $Lang property // as records in this language might have NULL values in their $Lang property
// and otherwise wouldn't show up here // and otherwise wouldn't show up here
$alreadyTranslatedLangs[Translatable::default_lang()] = i18n::get_language_name(Translatable::default_lang()); //$alreadyTranslatedLangs[Translatable::default_lang()] = i18n::get_language_name(Translatable::default_lang());
// Exclude the current language from being shown. // Exclude the current language from being shown.
if(Translatable::current_lang() != Translatable::default_lang()) { if(Translatable::current_lang() != Translatable::default_lang()) {
@ -776,6 +798,7 @@ class Translatable extends DataObjectDecorator {
$createButton = new InlineFormAction('createtranslation',_t('Translatable.CREATEBUTTON', 'Create')) $createButton = new InlineFormAction('createtranslation',_t('Translatable.CREATEBUTTON', 'Create'))
) )
); );
$createButton->includeDefaultJS(false);
if($alreadyTranslatedLangs) { if($alreadyTranslatedLangs) {
$fields->addFieldToTab( $fields->addFieldToTab(