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() {
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()}).
if(Translatable::is_enabled()) {
// $Lang serves as a "context" which can be inspected by Translatable - hence it
// has the same name as the database property on Translatable.
if($this->getRequest()->requestVar("Lang")) {
$this->Lang = $this->getRequest()->requestVar("Lang");
} elseif($this->getRequest()->requestVar("lang")) {
$this->Lang = $this->getRequest()->requestVar("lang");
if($this->getRequest()->requestVar("Locale")) {
$this->Locale = $this->getRequest()->requestVar("Locale");
} elseif($this->getRequest()->requestVar("locale")) {
$this->Locale = $this->getRequest()->requestVar("locale");
} 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
if(Translatable::is_enabled()) {
$spellcheckLangs = Translatable::get_existing_content_languages();
} else {
$defaultLang = Translatable::default_lang();
$spellcheckLangs = array($defaultLang => i18n::get_language_name($defaultLang));
$defaultLang = Translatable::default_locale();
$spellcheckLangs = array($defaultLang => i18n::get_locale_name($defaultLang));
}
$spellcheckSpec = array();
foreach($spellcheckLangs as $lang => $title) $spellcheckSpec[] = "{$title}={$lang}";
@ -485,7 +485,7 @@ JS;
if(!singleton($className)->canCreate()) return Security::permissionFailure($this);
$p = $this->getNewItem("new-$className-$parent".$suffix, false);
$p->Lang = $_REQUEST['Lang'];
$p->Locale = $_REQUEST['Locale'];
$p->write();
return $this->returnItemToUser($p);
@ -1163,7 +1163,7 @@ JS;
$fields = new FieldSet(
new HiddenField("ParentID"),
new HiddenField("Lang", 'Lang', Translatable::current_lang()),
new HiddenField("Locale", 'Locale', Translatable::current_locale()),
new DropdownField("PageType", "", $pageTypes, 'Page')
);
@ -1314,8 +1314,8 @@ JS;
$record = $this->getRecord($originalLangID);
$this->Lang = $langCode;
Translatable::set_reading_lang($langCode);
$this->Locale = $langCode;
Translatable::set_reading_locale($langCode);
// Create a new record in the database - this is different
// to the usual "create page" pattern of storing the record
@ -1325,7 +1325,7 @@ JS;
$translatedRecord = $record->createTranslation($langCode);
$url = sprintf(
"%s/%d/?lang=%s",
"%s/%d/?locale=%s",
$this->Link('show'),
$translatedRecord->ID,
$langCode
@ -1369,7 +1369,7 @@ JS;
$member = Member::currentUser(); //check to see if the current user can switch langs or not
if(Permission::checkMember($member, 'VIEW_LANGS')) {
$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
if( $used && count($used) ) {
foreach($used as $index => $code) {
@ -1380,11 +1380,11 @@ JS;
$langs[ _t('Form.LANGAVAIL', "Available languages") ] = (isset( $available )) ? $available : array();
}
$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
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
*/
function EditingLang() {
if(!Translatable::is_default_lang()) {
return i18n::get_language_name(Translatable::current_lang());
if(!Translatable::is_default_locale()) {
return i18n::get_locale_name(Translatable::current_locale());
} else {
return false;
}

View File

@ -902,7 +902,7 @@ JS;
$id = $this->currentPageID();
if($id && is_numeric($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;
} else {
return $page;

View File

@ -15,7 +15,7 @@ LangSelectorClass.prototype = {
onchange: function(e, val) {
if(this.value != _TRANSLATING_LANG) {
_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()
var lang = $('LangSelector') ? $F('LangSelector') : null;
if(lang) {
url += '&lang='+lang;
url += '&locale='+lang;
}
statusMessage("loading...");
@ -429,7 +429,7 @@ StageLink.prototype = {
if(this.id != 'viewArchivedSite') this.style.display = 'none';
}
if($('Form_EditForm_Lang')) {
this.href += "&lang=" + $('Form_EditForm_Lang').value;
this.href += "&locale=" + $('Form_EditForm_Lang').value;
}
},
onclick : function() {