ENHANCEMENT Adjusted CMSMain and LeftAndMain to use locales instead of short lang codes when reading and writing translations. See r73468 for details on the underlying Translatable datamodel change

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@73469 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-03-20 08:49:27 +00:00
parent 15454352bb
commit 893df91e33
4 changed files with 23 additions and 23 deletions

View File

@ -80,27 +80,27 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
public function init() { public function init() {
parent::init(); parent::init();
// "Lang" attribute is either explicitly added by LeftAndMain Javascript logic, // Locale" attribute is either explicitly added by LeftAndMain Javascript logic,
// or implied on a translated record (see {@link Translatable->updateCMSFields()}). // or implied on a translated record (see {@link Translatable->updateCMSFields()}).
if(Translatable::is_enabled()) { if(Translatable::is_enabled()) {
// $Lang serves as a "context" which can be inspected by Translatable - hence it // $Lang serves as a "context" which can be inspected by Translatable - hence it
// has the same name as the database property on Translatable. // has the same name as the database property on Translatable.
if($this->getRequest()->requestVar("Lang")) { if($this->getRequest()->requestVar("Locale")) {
$this->Lang = $this->getRequest()->requestVar("Lang"); $this->Locale = $this->getRequest()->requestVar("Locale");
} elseif($this->getRequest()->requestVar("lang")) { } elseif($this->getRequest()->requestVar("locale")) {
$this->Lang = $this->getRequest()->requestVar("lang"); $this->Locale = $this->getRequest()->requestVar("locale");
} else { } else {
$this->Lang = Translatable::default_lang(); $this->Locale = Translatable::default_locale();
} }
Translatable::set_reading_lang($this->Lang); Translatable::set_reading_locale($this->Locale);
} }
// collect languages for TinyMCE spellchecker plugin // collect languages for TinyMCE spellchecker plugin
if(Translatable::is_enabled()) { if(Translatable::is_enabled()) {
$spellcheckLangs = Translatable::get_existing_content_languages(); $spellcheckLangs = Translatable::get_existing_content_languages();
} else { } else {
$defaultLang = Translatable::default_lang(); $defaultLang = Translatable::default_locale();
$spellcheckLangs = array($defaultLang => i18n::get_language_name($defaultLang)); $spellcheckLangs = array($defaultLang => i18n::get_locale_name($defaultLang));
} }
$spellcheckSpec = array(); $spellcheckSpec = array();
foreach($spellcheckLangs as $lang => $title) $spellcheckSpec[] = "{$title}={$lang}"; foreach($spellcheckLangs as $lang => $title) $spellcheckSpec[] = "{$title}={$lang}";
@ -485,7 +485,7 @@ JS;
if(!singleton($className)->canCreate()) return Security::permissionFailure($this); if(!singleton($className)->canCreate()) return Security::permissionFailure($this);
$p = $this->getNewItem("new-$className-$parent".$suffix, false); $p = $this->getNewItem("new-$className-$parent".$suffix, false);
$p->Lang = $_REQUEST['Lang']; $p->Locale = $_REQUEST['Locale'];
$p->write(); $p->write();
return $this->returnItemToUser($p); return $this->returnItemToUser($p);
@ -1163,7 +1163,7 @@ JS;
$fields = new FieldSet( $fields = new FieldSet(
new HiddenField("ParentID"), new HiddenField("ParentID"),
new HiddenField("Lang", 'Lang', Translatable::current_lang()), new HiddenField("Locale", 'Locale', Translatable::current_locale()),
new DropdownField("PageType", "", $pageTypes, 'Page') new DropdownField("PageType", "", $pageTypes, 'Page')
); );
@ -1314,8 +1314,8 @@ JS;
$record = $this->getRecord($originalLangID); $record = $this->getRecord($originalLangID);
$this->Lang = $langCode; $this->Locale = $langCode;
Translatable::set_reading_lang($langCode); Translatable::set_reading_locale($langCode);
// Create a new record in the database - this is different // Create a new record in the database - this is different
// to the usual "create page" pattern of storing the record // to the usual "create page" pattern of storing the record
@ -1325,7 +1325,7 @@ JS;
$translatedRecord = $record->createTranslation($langCode); $translatedRecord = $record->createTranslation($langCode);
$url = sprintf( $url = sprintf(
"%s/%d/?lang=%s", "%s/%d/?locale=%s",
$this->Link('show'), $this->Link('show'),
$translatedRecord->ID, $translatedRecord->ID,
$langCode $langCode
@ -1369,7 +1369,7 @@ JS;
$member = Member::currentUser(); //check to see if the current user can switch langs or not $member = Member::currentUser(); //check to see if the current user can switch langs or not
if(Permission::checkMember($member, 'VIEW_LANGS')) { if(Permission::checkMember($member, 'VIEW_LANGS')) {
$allKey = _t('Form.LANGAOTHER', "Other languages"); $allKey = _t('Form.LANGAOTHER', "Other languages");
$all = i18n::get_common_languages(); //all languages $all = i18n::get_common_locales(); //all languages
$used = Translatable::get_existing_content_languages(); //languages currently in use $used = Translatable::get_existing_content_languages(); //languages currently in use
if( $used && count($used) ) { if( $used && count($used) ) {
foreach($used as $index => $code) { foreach($used as $index => $code) {
@ -1380,11 +1380,11 @@ JS;
$langs[ _t('Form.LANGAVAIL', "Available languages") ] = (isset( $available )) ? $available : array(); $langs[ _t('Form.LANGAVAIL', "Available languages") ] = (isset( $available )) ? $available : array();
} }
$langs[ _t('Form.LANGAOTHER', "Other languages") ] = $all; $langs[ _t('Form.LANGAOTHER', "Other languages") ] = $all;
return new GroupedDropdownField('LangSelector', 'Language', $langs, Translatable::current_lang()); return new GroupedDropdownField('LangSelector', 'Language', $langs, Translatable::current_locale());
} }
//user doesn't have permission to switch langs so just show a string displaying current language //user doesn't have permission to switch langs so just show a string displaying current language
return i18n::get_language_name( Translatable::current_lang() ); return i18n::get_locale_name( Translatable::current_locale() );
} }
/** /**
@ -1409,8 +1409,8 @@ JS;
* Get the name of the language that we are translating in * Get the name of the language that we are translating in
*/ */
function EditingLang() { function EditingLang() {
if(!Translatable::is_default_lang()) { if(!Translatable::is_default_locale()) {
return i18n::get_language_name(Translatable::current_lang()); return i18n::get_locale_name(Translatable::current_locale());
} else { } else {
return false; return false;
} }

View File

@ -902,7 +902,7 @@ JS;
$id = $this->currentPageID(); $id = $this->currentPageID();
if($id && is_numeric($id)) { if($id && is_numeric($id)) {
$page = DataObject::get_by_id($this->stat('tree_class'), $id); $page = DataObject::get_by_id($this->stat('tree_class'), $id);
if($page && Translatable::is_enabled() && $page->Lang && $page->Lang != Translatable::current_lang()) { if($page && Translatable::is_enabled() && $page->Locale && $page->Locale != Translatable::current_locale()) {
return false; return false;
} else { } else {
return $page; return $page;

View File

@ -15,7 +15,7 @@ LangSelectorClass.prototype = {
onchange: function(e, val) { onchange: function(e, val) {
if(this.value != _TRANSLATING_LANG) { if(this.value != _TRANSLATING_LANG) {
_TRANSLATING_LANG = this.value; _TRANSLATING_LANG = this.value;
document.location = 'admin/?lang=' + this.value; document.location = 'admin/?locale=' + this.value;
} }
}, },

View File

@ -305,7 +305,7 @@ CMSRightForm.prototype = {
// used to set language in CMSMain->init() // used to set language in CMSMain->init()
var lang = $('LangSelector') ? $F('LangSelector') : null; var lang = $('LangSelector') ? $F('LangSelector') : null;
if(lang) { if(lang) {
url += '&lang='+lang; url += '&locale='+lang;
} }
statusMessage("loading..."); statusMessage("loading...");
@ -429,7 +429,7 @@ StageLink.prototype = {
if(this.id != 'viewArchivedSite') this.style.display = 'none'; if(this.id != 'viewArchivedSite') this.style.display = 'none';
} }
if($('Form_EditForm_Lang')) { if($('Form_EditForm_Lang')) {
this.href += "&lang=" + $('Form_EditForm_Lang').value; this.href += "&locale=" + $('Form_EditForm_Lang').value;
} }
}, },
onclick : function() { onclick : function() {