diff --git a/core/model/Translatable.php b/core/model/Translatable.php index 5fc2d302f..005631004 100755 --- a/core/model/Translatable.php +++ b/core/model/Translatable.php @@ -193,6 +193,15 @@ class Translatable extends DataObjectDecorator { */ protected static $enable_lang_filter = true; + /** + * @var array All locales in which a translation can be created. + * This limits the choice in the CMS language dropdown in the + * "Translation" tab, as well as the language dropdown above + * the CMS tree. If not set, it will default to showing all + * common locales. + */ + protected static $allowed_locales = null; + /** * Choose the language the site is currently on. * If $_GET['locale'] is set, then it will use that language, and store it in the session. @@ -311,9 +320,9 @@ class Translatable extends DataObjectDecorator { * Gets all translations for this specific page. * Doesn't include the language of the current record. * - * @return array Numeric array of all language codes, sorted alphabetically. + * @return array Numeric array of all locales, sorted alphabetically. */ - function getTranslatedLangs() { + function getTranslatedLocales() { $langs = array(); $baseDataClass = ClassInfo::baseDataClass($this->owner->class); //Base Class @@ -363,7 +372,7 @@ class Translatable extends DataObjectDecorator { */ static function get_langs_by_id($class, $id) { $do = DataObject::get_by_id($class, $id); - return ($do ? $do->getTranslatedLangs() : array()); + return ($do ? $do->getTranslatedLocales() : array()); } /** @@ -774,6 +783,12 @@ class Translatable extends DataObjectDecorator { } $isTranslationMode = $this->owner->Locale != Translatable::default_locale(); + + // Show a dropdown to create a new translation. + // This action is possible both when showing the "default language" + // and a translation. Include the current locale (record might not be saved yet). + $alreadyTranslatedLocales = $this->getTranslatedLocales(); + $alreadyTranslatedLocales[$this->owner->Locale] = $this->owner->Locale; if($originalRecord && $isTranslationMode) { $originalLangID = Session::get($this->owner->ID . '_originalLangID'); @@ -813,12 +828,6 @@ class Translatable extends DataObjectDecorator { ); } - // Show a dropdown to create a new translation. - // This action is possible both when showing the "default language" - // and a translation. Include the current locale (record might not be saved yet). - $alreadyTranslatedLangs = $this->getTranslatedLangs(); - $alreadyTranslatedLangs[$this->owner->Locale] = $this->owner->Locale; - $fields->addFieldsToTab( 'Root', new Tab('Translations', _t('Translatable.TRANSLATIONS', 'Translations'), @@ -826,22 +835,22 @@ class Translatable extends DataObjectDecorator { $langDropdown = new LanguageDropdownField( "NewTransLang", _t('Translatable.NEWLANGUAGE', 'New language'), - $alreadyTranslatedLangs, - 'SiteTree', - 'Locale-English' + $alreadyTranslatedLocales, + 'SiteTree', + $this->owner ), $createButton = new InlineFormAction('createtranslation',_t('Translatable.CREATEBUTTON', 'Create')) ) ); $createButton->includeDefaultJS(false); - if($alreadyTranslatedLangs) { + if($alreadyTranslatedLocales) { $fields->addFieldToTab( 'Root.Translations', new HeaderField('ExistingTransHeader', _t('Translatable.EXISTING', 'Existing translations:'), 3) ); $existingTransHTML = '