ENHANCEMENT Adjusted SearchForm, Debug, ErrorPage, SiteTree to using locales instead of lang codes

API CHANGE Changed Translatable datamodel to use locales ("en_US") instead of lang values ("en).
API CHANGE Changed Translatable::$default_lang to $default_locale, Translatable::$reading_lang to $reading_locale
API CHANGE Using "locale" instead of "lang" in Translatable::choose_site_lang() to auto-detect language from cookies or GET parameters
API CHANGE Deprecated Translatable::is_default_lang(), set_default_lang(), get_default_lang(), current_lang(), set_reading_lang(), get_reading_lang(), get_by_lang(), get_one_by_lang()
API CHANGE Removed Translatable::get_original() - with the new "translation groups" concept there no longer is an original for a translation
BUGFIX Updated MigrateTranslatableTask to new Locale based datamodel

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@73468 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-03-20 08:47:06 +00:00
parent 4e5bc0f7fa
commit 7ad7f8dcf2
12 changed files with 288 additions and 236 deletions

View File

@ -318,7 +318,7 @@ HTML;
* Returns the xml:lang and lang attributes * Returns the xml:lang and lang attributes
*/ */
function LangAttributes() { function LangAttributes() {
$lang = Translatable::current_lang(); $lang = Translatable::current_locale();
return "xml:lang=\"$lang\" lang=\"$lang\""; return "xml:lang=\"$lang\" lang=\"$lang\"";
} }

View File

@ -63,7 +63,7 @@ class ModelAsController extends Controller implements NestedController {
if(isset($_REQUEST['debug'])) Debug::message("Using record #$child->ID of type $child->class with URL {$this->urlParams['URLSegment']}"); if(isset($_REQUEST['debug'])) Debug::message("Using record #$child->ID of type $child->class with URL {$this->urlParams['URLSegment']}");
// set language // set language
if($child->Lang) Translatable::set_reading_lang($child->Lang); if($child->Locale) Translatable::set_reading_locale($child->Locale);
$controllerClass = "{$child->class}_Controller"; $controllerClass = "{$child->class}_Controller";

View File

@ -68,7 +68,7 @@ class RootURLController extends Controller {
if($homePageOBJ) { if($homePageOBJ) {
$urlSegment = $homePageOBJ->URLSegment; $urlSegment = $homePageOBJ->URLSegment;
} elseif(Translatable::is_enabled()) { } elseif(Translatable::is_enabled()) {
$urlSegment = Translatable::get_homepage_urlsegment_by_language(Translatable::current_lang()); $urlSegment = Translatable::get_homepage_urlsegment_by_language(Translatable::current_locale());
} }
return ($urlSegment) ? $urlSegment : self::get_default_homepage_urlsegment(); return ($urlSegment) ? $urlSegment : self::get_default_homepage_urlsegment();

View File

@ -110,7 +110,7 @@ class ErrorPage extends Page {
// if the page is published in a language other than default language, // if the page is published in a language other than default language,
// write a specific language version of the HTML page // write a specific language version of the HTML page
$filePath = self::get_filepath_for_errorcode($this->ErrorCode, $this->Lang); $filePath = self::get_filepath_for_errorcode($this->ErrorCode, $this->Locale);
if($fh = fopen($filePath, "w")) { if($fh = fopen($filePath, "w")) {
fwrite($fh, $errorContent); fwrite($fh, $errorContent);
fclose($fh); fclose($fh);
@ -149,7 +149,7 @@ class ErrorPage extends Page {
* @return String * @return String
*/ */
static function get_filepath_for_errorcode($statusCode, $lang = null) { static function get_filepath_for_errorcode($statusCode, $lang = null) {
if(Translatable::is_enabled() && $lang && $lang != Translatable::default_lang()) { if(Translatable::is_enabled() && $lang && $lang != Translatable::default_locale()) {
return self::$static_filepath . "/error-{$statusCode}-{$lang}.html"; return self::$static_filepath . "/error-{$statusCode}-{$lang}.html";
} else { } else {
return self::$static_filepath . "/error-{$statusCode}.html"; return self::$static_filepath . "/error-{$statusCode}.html";

View File

@ -885,8 +885,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
} }
// get the "long" lang name suitable for the HTTP content-language flag (with hyphens instead of underscores) // get the "long" lang name suitable for the HTTP content-language flag (with hyphens instead of underscores)
$currentLang = (Translatable::is_enabled()) ? Translatable::current_lang() : i18n::convert_rfc1766(i18n::get_locale()); $currentLang = (Translatable::is_enabled()) ? Translatable::current_locale() : i18n::get_locale();
$tags .= "<meta http-equiv=\"Content-Language\" content=\"". $currentLang ."\"/>\n"; $tags .= "<meta http-equiv=\"Content-Language\" content=\"". i18n::convert_rfc1766($currentLang) ."\"/>\n";
// DEPRECATED 2.3: Use MetaTags // DEPRECATED 2.3: Use MetaTags
$this->extend('updateMetaTags', $tags); $this->extend('updateMetaTags', $tags);
@ -1747,7 +1747,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
//TODO: Add integration //TODO: Add integration
/* /*
if(Translatable::is_enabled() && $controller->Lang != Translatable::default_lang() && !$this->isTranslation()) if(Translatable::is_enabled() && $controller->Locale != Translatable::default_locale() && !$this->isTranslation())
$classes .= " untranslated "; $classes .= " untranslated ";
*/ */
$classes .= $this->markingClasses(); $classes .= $this->markingClasses();

View File

@ -3,7 +3,7 @@
* The Translatable decorator allows your DataObjects to have versions in different languages, * The Translatable decorator allows your DataObjects to have versions in different languages,
* defining which fields are can be translated. * defining which fields are can be translated.
* *
* Common language names (e.g. 'en') are used in Translatable for * Common language names (e.g. 'en_US') are used in Translatable for
* database-entities. On the other hand, the file-based i18n-translations * database-entities. On the other hand, the file-based i18n-translations
* always have a "locale" (e.g. 'en_US'). * always have a "locale" (e.g. 'en_US').
* *
@ -23,26 +23,26 @@
* *
* Getting a translation for an existing instance: * Getting a translation for an existing instance:
* <example> * <example>
* $translatedObj = DataObject::get_one_by_lang('MyObject', 'de'); * $translatedObj = DataObject::get_one_by_locale('MyObject', 'de_DE');
* </example> * </example>
* *
* Getting a translation for an existing instance: * Getting a translation for an existing instance:
* <example> * <example>
* $obj = DataObject::get_by_id('MyObject', 99); // original language * $obj = DataObject::get_by_id('MyObject', 99); // original language
* $translatedObj = $obj->getTranslation('de'); * $translatedObj = $obj->getTranslation('de_DE');
* </example> * </example>
* *
* Getting translations through {@link Translatable::set_reading_lang()}. * Getting translations through {@link Translatable::set_reading_locale()}.
* This is *not* a recommended approach, but sometimes inavoidable (e.g. for {@link Versioned} methods). * This is *not* a recommended approach, but sometimes inavoidable (e.g. for {@link Versioned} methods).
* <example> * <example>
* $obj = DataObject::get_by_id('MyObject', 99); // original language * $obj = DataObject::get_by_id('MyObject', 99); // original language
* $translatedObj = $obj->getTranslation('de'); * $translatedObj = $obj->getTranslation('de_DE');
* </example> * </example>
* *
* Creating a translation: * Creating a translation:
* <example> * <example>
* $obj = new MyObject(); * $obj = new MyObject();
* $translatedObj = $obj->createTranslation('de'); * $translatedObj = $obj->createTranslation('de_DE');
* </example> * </example>
* *
* <h2>Usage for SiteTree</h2> * <h2>Usage for SiteTree</h2>
@ -55,7 +55,7 @@
* languages by auto-appending the language code at the end. * languages by auto-appending the language code at the end.
* You'll need to ensure that the appropriate "reading language" is set * You'll need to ensure that the appropriate "reading language" is set
* before showing links to other pages on a website: Either * before showing links to other pages on a website: Either
* through setting $_COOKIE['lang'], $_SESSION['lang'] or $_GET['lang']. * through setting $_COOKIE['locale'], $_SESSION['locale'] or $_GET['locale'].
* Pages in different languages can have different publication states * Pages in different languages can have different publication states
* through the {@link Versioned} extension. * through the {@link Versioned} extension.
* *
@ -93,14 +93,14 @@
* Important: If the "default language" of your site is not english (en_US), * Important: If the "default language" of your site is not english (en_US),
* please ensure to set the appropriate default language for * please ensure to set the appropriate default language for
* your content before building the database with Translatable enabled: * your content before building the database with Translatable enabled:
* Translatable::set_default_language(<locale>); * Translatable::set_default_locale(<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
* pages being shown in the default sitetree regardless of their language. * pages being shown in the default sitetree regardless of their language.
* It is advised to start with a new database after uninstalling Translatable, * It is advised to start with a new database after uninstalling Translatable,
* or manually filter out translated objects through their "Lang" property * or manually filter out translated objects through their "Locale" property
* in the database. * in the database.
* *
* @author Michael Gall <michael (at) wakeless (dot) net> * @author Michael Gall <michael (at) wakeless (dot) net>
@ -123,7 +123,7 @@ class Translatable extends DataObjectDecorator {
* The 'default' language. * The 'default' language.
* @var string * @var string
*/ */
protected static $default_lang = 'en'; protected static $default_locale = 'en_US';
/** /**
* The language in which we are reading dataobjects. * The language in which we are reading dataobjects.
@ -132,7 +132,7 @@ class Translatable extends DataObjectDecorator {
* @see Director::get_site_mode() * @see Director::get_site_mode()
* @var string * @var string
*/ */
protected static $reading_lang = null; protected static $reading_locale = null;
/** /**
* Indicates if the start language has been determined using choose_site_lang * Indicates if the start language has been determined using choose_site_lang
@ -141,7 +141,7 @@ class Translatable extends DataObjectDecorator {
protected static $language_decided = false; protected static $language_decided = false;
/** /**
* Indicates whether the 'Lang' transformation when modifying queries should be bypassed * Indicates whether the 'Locale' transformation when modifying queries should be bypassed
* If it's true * If it's true
* *
* @var boolean * @var boolean
@ -175,7 +175,7 @@ class Translatable extends DataObjectDecorator {
protected $original_values = null; protected $original_values = null;
/** /**
* @var boolean Temporarily override the "auto-filter" for {@link current_lang()} * @var boolean Temporarily override the "auto-filter" for {@link current_locale()}
* in {@link augmentSQL()}. IMPORTANT: You must set this value back to TRUE * in {@link augmentSQL()}. IMPORTANT: You must set this value back to TRUE
* after the temporary usage. * after the temporary usage.
*/ */
@ -183,7 +183,7 @@ class Translatable extends DataObjectDecorator {
/** /**
* Choose the language the site is currently on. * Choose the language the site is currently on.
* If $_GET['lang'] or $_COOKIE['lang'] is set, then it will use that language, and store it in the session. * If $_GET['locale'] or $_COOKIE['locale'] is set, then it will use that language, and store it in the session.
* Otherwise it checks the session for a possible stored language, either from namespace to the site_mode * Otherwise it checks the session for a possible stored language, either from namespace to the site_mode
* ('site' or 'cms'), or for a 'global' language setting. * ('site' or 'cms'), or for a 'global' language setting.
* The final option is the member preference. * The final option is the member preference.
@ -192,25 +192,25 @@ class Translatable extends DataObjectDecorator {
* *
* @uses Director::get_site_mode() * @uses Director::get_site_mode()
* @param $langsAvailable array A numerical array of languages which are valid choices (optional) * @param $langsAvailable array A numerical array of languages which are valid choices (optional)
* @return string Selected language (also saved in $reading_lang). * @return string Selected language (also saved in $reading_locale).
*/ */
static function choose_site_lang($langsAvailable = array()) { static function choose_site_lang($langsAvailable = array()) {
$siteMode = Director::get_site_mode(); // either 'cms' or 'site' $siteMode = Director::get_site_mode(); // either 'cms' or 'site'
if(self::$reading_lang) { if(self::$reading_locale) {
self::$language_decided = true; self::$language_decided = true;
return self::$reading_lang; return self::$reading_locale;
} }
if((isset($_GET['lang']) && !$langsAvailable) || (isset($_GET['lang']) && in_array($_GET['lang'], $langsAvailable))) { if((isset($_GET['locale']) && !$langsAvailable) || (isset($_GET['locale']) && in_array($_GET['locale'], $langsAvailable))) {
// get from GET parameter // get from GET parameter
self::set_reading_lang($_GET['lang']); self::set_reading_locale($_GET['locale']);
} else { } else {
self::set_reading_lang(self::default_lang()); self::set_reading_locale(self::default_locale());
} }
self::$language_decided = true; self::$language_decided = true;
return self::$reading_lang; return self::$reading_locale;
} }
/** /**
@ -220,34 +220,34 @@ class Translatable extends DataObjectDecorator {
* *
* @return string * @return string
*/ */
static function default_lang() { static function default_locale() {
return self::$default_lang; return self::$default_locale;
} }
/** /**
* Set default language. * Set default language.
* *
* @param $lang String * @param $locale String
*/ */
static function set_default_lang($lang) { static function set_default_locale($locale) {
self::$default_lang = $lang; self::$default_locale = $locale;
} }
/** /**
* Check whether the default and current reading language are the same. * Check whether the default and current reading language are the same.
* @return boolean Return true if both default and reading language are the same. * @return boolean Return true if both default and reading language are the same.
*/ */
static function is_default_lang() { static function is_default_locale() {
return (!self::current_lang() || self::$default_lang == self::current_lang()); return (!self::current_locale() || self::$default_locale == self::current_locale());
} }
/** /**
* Get the current reading language. * Get the current reading language.
* @return string * @return string
*/ */
static function current_lang() { static function current_locale() {
if (!self::$language_decided) self::choose_site_lang(); if (!self::$language_decided) self::choose_site_lang();
return self::$reading_lang; return self::$reading_locale;
} }
/** /**
@ -258,25 +258,25 @@ class Translatable extends DataObjectDecorator {
* *
* @param string $lang New reading language. * @param string $lang New reading language.
*/ */
static function set_reading_lang($lang) { static function set_reading_locale($locale) {
self::$reading_lang = $lang; self::$reading_locale = $locale;
self::$language_decided = true; self::$language_decided = true;
} }
/** /**
* Get a singleton instance of a class in the given language. * Get a singleton instance of a class in the given language.
* @param string $class The name of the class. * @param string $class The name of the class.
* @param string $lang The name of the language. * @param string $locale The name of the language.
* @param string $filter A filter to be inserted into the WHERE clause. * @param string $filter A filter to be inserted into the WHERE clause.
* @param boolean $cache Use caching (default: false) * @param boolean $cache Use caching (default: false)
* @param string $orderby A sort expression to be inserted into the ORDER BY clause. * @param string $orderby A sort expression to be inserted into the ORDER BY clause.
* @return DataObject * @return DataObject
*/ */
static function get_one_by_lang($class, $lang, $filter = '', $cache = false, $orderby = "") { static function get_one_by_locale($class, $locale, $filter = '', $cache = false, $orderby = "") {
$orig = Translatable::current_lang(); $orig = Translatable::current_locale();
Translatable::set_reading_lang($lang); Translatable::set_reading_locale($locale);
$do = DataObject::get_one($class, $filter, $cache, $orderby); $do = DataObject::get_one($class, $filter, $cache, $orderby);
Translatable::set_reading_lang($orig); Translatable::set_reading_locale($orig);
return $do; return $do;
} }
@ -284,7 +284,7 @@ class Translatable extends DataObjectDecorator {
* Get all the instances of the given class translated to the given language * Get all the instances of the given class translated to the given language
* *
* @param string $class The name of the class * @param string $class The name of the class
* @param string $lang The name of the language * @param string $locale The name of the language
* @param string $filter A filter to be inserted into the WHERE clause. * @param string $filter A filter to be inserted into the WHERE clause.
* @param string $sort A sort expression to be inserted into the ORDER BY clause. * @param string $sort A sort expression to be inserted into the ORDER BY clause.
* @param string $join A single join clause. This can be used for filtering, only 1 instance of each DataObject will be returned. * @param string $join A single join clause. This can be used for filtering, only 1 instance of each DataObject will be returned.
@ -293,26 +293,14 @@ class Translatable extends DataObjectDecorator {
* @param string $having A filter to be inserted into the HAVING clause. * @param string $having A filter to be inserted into the HAVING clause.
* @return mixed The objects matching the conditions. * @return mixed The objects matching the conditions.
*/ */
static function get_by_lang($class, $lang, $filter = '', $sort = '', $join = "", $limit = "", $containerClass = "DataObjectSet", $having = "") { static function get_by_locale($class, $locale, $filter = '', $sort = '', $join = "", $limit = "", $containerClass = "DataObjectSet", $having = "") {
$oldLang = self::current_lang(); $oldLang = self::current_locale();
self::set_reading_lang($lang); self::set_reading_locale($locale);
$result = DataObject::get($class, $filter, $sort, $join, $limit, $containerClass, $having); $result = DataObject::get($class, $filter, $sort, $join, $limit, $containerClass, $having);
self::set_reading_lang($oldLang); self::set_reading_locale($oldLang);
return $result; return $result;
} }
/**
* Get a record in his original language version.
* @param string $class The name of the class.
* @param string $originalLangID The original record id.
* @return DataObject
*/
static function get_original($class, $originalLangID) {
$baseClass = $class;
while( ($p = get_parent_class($baseClass)) != "DataObject") $baseClass = $p;
return self::get_one_by_lang($class,self::default_lang(),"\"$baseClass\".\"ID\" = $originalLangID");
}
/** /**
* Gets all translations for this specific page. * Gets all translations for this specific page.
* Doesn't include the language of the current record. * Doesn't include the language of the current record.
@ -331,7 +319,7 @@ class Translatable extends DataObjectDecorator {
$translationGroupID = $this->owner->getTranslationGroup(); $translationGroupID = $this->owner->getTranslationGroup();
if(is_numeric($translationGroupID)) { if(is_numeric($translationGroupID)) {
$query = new SQLQuery( $query = new SQLQuery(
'DISTINCT Lang', 'DISTINCT Locale',
sprintf( sprintf(
'"%s" LEFT JOIN "%s" ON "%s"."OriginalID" = "%s"."ID"', '"%s" LEFT JOIN "%s" ON "%s"."OriginalID" = "%s"."ID"',
$baseDataClass, $baseDataClass,
@ -340,11 +328,11 @@ class Translatable extends DataObjectDecorator {
$baseDataClass $baseDataClass
), // from ), // from
sprintf( sprintf(
'"%s"."TranslationGroupID" = %d AND "%s"."Lang" != \'%s\'', '"%s"."TranslationGroupID" = %d AND "%s"."Locale" != \'%s\'',
$translationGroupClass, $translationGroupClass,
$translationGroupID, $translationGroupID,
$baseDataClass, $baseDataClass,
$this->owner->Lang $this->owner->Locale
) // where ) // where
); );
$langs = $query->execute()->column(); $langs = $query->execute()->column();
@ -445,11 +433,11 @@ class Translatable extends DataObjectDecorator {
if(get_class($this->owner) == ClassInfo::baseDataClass(get_class($this->owner))) { if(get_class($this->owner) == ClassInfo::baseDataClass(get_class($this->owner))) {
return array( return array(
"db" => array( "db" => array(
"Lang" => "Varchar(12)", "Locale" => "Varchar(12)",
"TranslationMasterID" => "Int" // optional relation to a "translation master" "TranslationMasterID" => "Int" // optional relation to a "translation master"
), ),
"defaults" => array( "defaults" => array(
"Lang" => Translatable::default_lang() // as an overloaded getter as well: getLang() "Locale" => Translatable::default_locale() // as an overloaded getter as well: getLang()
) )
); );
} else { } else {
@ -459,8 +447,8 @@ class Translatable extends DataObjectDecorator {
/** /**
* Changes any SELECT query thats not filtering on an ID * Changes any SELECT query thats not filtering on an ID
* to limit by the current language defined in {@link current_lang()}. * to limit by the current language defined in {@link current_locale()}.
* It falls back to "Lang='' OR Lang IS NULL" and assumes that * It falls back to "Locale='' OR Lang IS NULL" and assumes that
* this implies querying for the default language. * this implies querying for the default language.
* *
* Use {@link $enable_lang_filter} to temporarily disable this "auto-filtering". * Use {@link $enable_lang_filter} to temporarily disable this "auto-filtering".
@ -468,7 +456,7 @@ class Translatable extends DataObjectDecorator {
function augmentSQL(SQLQuery &$query) { function augmentSQL(SQLQuery &$query) {
if(!Translatable::is_enabled()) return; if(!Translatable::is_enabled()) return;
$lang = Translatable::current_lang(); $lang = Translatable::current_locale();
$baseTable = ClassInfo::baseDataClass($this->owner->class); $baseTable = ClassInfo::baseDataClass($this->owner->class);
$where = $query->where; $where = $query->where;
if( if(
@ -484,10 +472,10 @@ class Translatable extends DataObjectDecorator {
&& !preg_match('/("|\')Lang("|\')/', $query->getFilter()) && !preg_match('/("|\')Lang("|\')/', $query->getFilter())
//&& !$query->filtersOnFK() //&& !$query->filtersOnFK()
) { ) {
$qry = "\"Lang\" = '$lang'"; $qry = "\"Locale\" = '$lang'";
if(Translatable::is_default_lang()) { if(Translatable::is_default_locale()) {
$qry .= " OR \"Lang\" = '' "; $qry .= " OR \"Locale\" = '' ";
$qry .= " OR \"Lang\" IS NULL "; $qry .= " OR \"Locale\" IS NULL ";
} }
$query->where[] = $qry; $query->where[] = $qry;
} }
@ -592,7 +580,7 @@ class Translatable extends DataObjectDecorator {
function contentcontrollerInit($controller) { function contentcontrollerInit($controller) {
if(!Translatable::is_enabled()) return; if(!Translatable::is_enabled()) return;
Translatable::choose_site_lang(); Translatable::choose_site_lang();
$controller->Lang = Translatable::current_lang(); $controller->Locale = Translatable::current_locale();
} }
function modelascontrollerInit($controller) { function modelascontrollerInit($controller) {
@ -617,12 +605,12 @@ class Translatable extends DataObjectDecorator {
function onBeforeWrite() { function onBeforeWrite() {
if(!Translatable::is_enabled()) return; if(!Translatable::is_enabled()) return;
// If language is not set explicitly, set it to current_lang. // If language is not set explicitly, set it to current_locale.
// This might be a bit overzealous in assuming the language // This might be a bit overzealous in assuming the language
// of the content, as a "single language" website might be expanded // of the content, as a "single language" website might be expanded
// later on. // later on.
if(!$this->owner->ID && !$this->owner->Lang) { if(!$this->owner->ID && !$this->owner->Locale) {
$this->owner->Lang = Translatable::current_lang(); $this->owner->Locale = Translatable::current_locale();
} }
// Specific logic for SiteTree subclasses. // Specific logic for SiteTree subclasses.
@ -633,9 +621,9 @@ class Translatable extends DataObjectDecorator {
if( if(
!$this->owner->ID !$this->owner->ID
&& $this->owner->ParentID && $this->owner->ParentID
&& !$this->owner->Parent()->hasTranslation($this->owner->Lang) && !$this->owner->Parent()->hasTranslation($this->owner->Locale)
) { ) {
$parentTranslation = $this->owner->Parent()->createTranslation($this->owner->Lang); $parentTranslation = $this->owner->Parent()->createTranslation($this->owner->Locale);
$this->owner->ParentID = $parentTranslation->ID; $this->owner->ParentID = $parentTranslation->ID;
} }
} }
@ -645,10 +633,10 @@ class Translatable extends DataObjectDecorator {
// will save as "myfrenchpage-fr" (only if we're not in the "default language"). // will save as "myfrenchpage-fr" (only if we're not in the "default language").
// Its bad SEO to have multiple resources with different content (=language) under the same URL. // Its bad SEO to have multiple resources with different content (=language) under the same URL.
if($this->owner->hasField('URLSegment')) { if($this->owner->hasField('URLSegment')) {
if(!$this->owner->ID && $this->owner->Lang != Translatable::default_lang()) { if(!$this->owner->ID && $this->owner->Locale != Translatable::default_locale()) {
$SQL_URLSegment = Convert::raw2sql($this->owner->URLSegment); $SQL_URLSegment = Convert::raw2sql($this->owner->URLSegment);
$existingOriginalPage = Translatable::get_one_by_lang('SiteTree', Translatable::default_lang(), "\"URLSegment\" = '{$SQL_URLSegment}'"); $existingOriginalPage = Translatable::get_one_by_lang('SiteTree', Translatable::default_locale(), "\"URLSegment\" = '{$SQL_URLSegment}'");
if($existingOriginalPage) $this->owner->URLSegment .= "-{$this->owner->Lang}"; if($existingOriginalPage) $this->owner->URLSegment .= "-{$this->owner->Locale}";
} }
} }
@ -733,7 +721,7 @@ class Translatable extends DataObjectDecorator {
if(!($this->owner instanceof SiteTree)) return; if(!($this->owner instanceof SiteTree)) return;
// used in CMSMain->init() to set language state when reading/writing record // used in CMSMain->init() to set language state when reading/writing record
$fields->push(new HiddenField("Lang", "Lang", $this->owner->Lang) ); $fields->push(new HiddenField("Locale", "Locale", $this->owner->Locale) );
// if a language other than default language is used, we're in "translation mode", // if a language other than default language is used, we're in "translation mode",
// hence have to modify the original fields // hence have to modify the original fields
@ -743,14 +731,14 @@ class Translatable extends DataObjectDecorator {
while( ($p = get_parent_class($baseClass)) != "DataObject") $baseClass = $p; while( ($p = get_parent_class($baseClass)) != "DataObject") $baseClass = $p;
// try to get the record in "default language" // try to get the record in "default language"
$originalRecord = $this->owner->getTranslation(Translatable::default_lang()); $originalRecord = $this->owner->getTranslation(Translatable::default_locale());
// if no translation in "default language", fall back to first translation // if no translation in "default language", fall back to first translation
if(!$originalRecord) { if(!$originalRecord) {
$translations = $this->owner->getTranslations(); $translations = $this->owner->getTranslations();
$originalRecord = ($translations) ? $translations->First() : null; $originalRecord = ($translations) ? $translations->First() : null;
} }
$isTranslationMode = $this->owner->Lang != Translatable::default_lang(); $isTranslationMode = $this->owner->Locale != Translatable::default_locale();
if($originalRecord && $isTranslationMode) { if($originalRecord && $isTranslationMode) {
$originalLangID = Session::get($this->owner->ID . '_originalLangID'); $originalLangID = Session::get($this->owner->ID . '_originalLangID');
@ -794,11 +782,11 @@ 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_locale()] = i18n::get_locale_name(Translatable::default_locale());
// Exclude the current language from being shown. // Exclude the current language from being shown.
if(Translatable::current_lang() != Translatable::default_lang()) { if(Translatable::current_locale() != Translatable::default_locale()) {
$currentLangKey = array_search(Translatable::current_lang(), $alreadyTranslatedLangs); $currentLangKey = array_search(Translatable::current_locale(), $alreadyTranslatedLangs);
if($currentLangKey) unset($alreadyTranslatedLangs[$currentLangKey]); if($currentLangKey) unset($alreadyTranslatedLangs[$currentLangKey]);
} }
@ -806,7 +794,13 @@ class Translatable extends DataObjectDecorator {
'Root', 'Root',
new Tab(_t('Translatable.TRANSLATIONS', 'Translations'), new Tab(_t('Translatable.TRANSLATIONS', 'Translations'),
new HeaderField('CreateTransHeader', _t('Translatable.CREATE', 'Create new translation'), 2), new HeaderField('CreateTransHeader', _t('Translatable.CREATE', 'Create new translation'), 2),
$langDropdown = new LanguageDropdownField("NewTransLang", _t('Translatable.NEWLANGUAGE', 'New language'), $alreadyTranslatedLangs), $langDropdown = new LanguageDropdownField(
"NewTransLang",
_t('Translatable.NEWLANGUAGE', 'New language'),
$alreadyTranslatedLangs,
'SiteTree',
'Locale-English'
),
$createButton = new InlineFormAction('createtranslation',_t('Translatable.CREATEBUTTON', 'Create')) $createButton = new InlineFormAction('createtranslation',_t('Translatable.CREATEBUTTON', 'Create'))
) )
); );
@ -822,8 +816,8 @@ class Translatable extends DataObjectDecorator {
$existingTranslation = $this->owner->getTranslation($langCode); $existingTranslation = $this->owner->getTranslation($langCode);
if($existingTranslation) { if($existingTranslation) {
$existingTransHTML .= sprintf('<li><a href="%s">%s</a></li>', $existingTransHTML .= sprintf('<li><a href="%s">%s</a></li>',
sprintf('admin/show/%d/?lang=%s', $existingTranslation->ID, $langCode), sprintf('admin/show/%d/?locale=%s', $existingTranslation->ID, $langCode),
i18n::get_language_name($langCode) i18n::get_locale_name($langCode)
); );
} }
} }
@ -879,10 +873,10 @@ class Translatable extends DataObjectDecorator {
* excluding itself. See {@link getTranslation()} to retrieve * excluding itself. See {@link getTranslation()} to retrieve
* a single translated object. * a single translated object.
* *
* @param string $lang * @param string $locale
* @return DataObjectSet * @return DataObjectSet
*/ */
function getTranslations($lang = null) { function getTranslations($locale = null) {
if($this->owner->exists()) { if($this->owner->exists()) {
// HACK need to disable language filtering in augmentSQL(), // HACK need to disable language filtering in augmentSQL(),
// as we purposely want to get different language // as we purposely want to get different language
@ -892,11 +886,11 @@ class Translatable extends DataObjectDecorator {
$baseDataClass = ClassInfo::baseDataClass($this->owner->class); $baseDataClass = ClassInfo::baseDataClass($this->owner->class);
$filter = sprintf('"%s_translationgroups"."TranslationGroupID" = %d', $baseDataClass, $translationGroupID); $filter = sprintf('"%s_translationgroups"."TranslationGroupID" = %d', $baseDataClass, $translationGroupID);
if($lang) { if($locale) {
$filter .= sprintf(' AND "%s"."Lang" = \'%s\'', $baseDataClass, Convert::raw2sql($lang)); $filter .= sprintf(' AND "%s"."Locale" = \'%s\'', $baseDataClass, Convert::raw2sql($locale));
} else { } else {
// exclude the language of the current owner // exclude the language of the current owner
$filter .= sprintf(' AND "%s"."Lang" != \'%s\'', $baseDataClass, $this->owner->Lang); $filter .= sprintf(' AND "%s"."Locale" != \'%s\'', $baseDataClass, $this->owner->Locale);
} }
$join = sprintf('LEFT JOIN "%s_translationgroups" ON "%s_translationgroups"."OriginalID" = "%s"."ID"', $join = sprintf('LEFT JOIN "%s_translationgroups" ON "%s_translationgroups"."OriginalID" = "%s"."ID"',
$baseDataClass, $baseDataClass,
@ -921,11 +915,11 @@ class Translatable extends DataObjectDecorator {
* Use {@link hasTranslation()} as a quicker alternative to check * Use {@link hasTranslation()} as a quicker alternative to check
* for an existing translation without getting the actual object. * for an existing translation without getting the actual object.
* *
* @param String $lang * @param String $locale
* @return DataObject Translated object * @return DataObject Translated object
*/ */
function getTranslation($lang) { function getTranslation($locale) {
$translations = $this->getTranslations($lang); $translations = $this->getTranslations($locale);
return ($translations) ? $translations->First() : null; return ($translations) ? $translations->First() : null;
} }
@ -938,15 +932,15 @@ class Translatable extends DataObjectDecorator {
* it belongs to. For "original records" which are not created through this * it belongs to. For "original records" which are not created through this
* method, the "translation group" is set in {@link onAfterWrite()}. * method, the "translation group" is set in {@link onAfterWrite()}.
* *
* @param string $lang * @param string $locale
* @return DataObject The translated object * @return DataObject The translated object
*/ */
function createTranslation($lang) { function createTranslation($locale) {
if(!$this->owner->exists()) { if(!$this->owner->exists()) {
user_error('Translatable::createTranslation(): Please save your record before creating a translation', E_USER_ERROR); user_error('Translatable::createTranslation(): Please save your record before creating a translation', E_USER_ERROR);
} }
$existingTranslation = $this->getTranslation($lang); $existingTranslation = $this->getTranslation($locale);
if($existingTranslation) return $existingTranslation; if($existingTranslation) return $existingTranslation;
$class = $this->owner->class; $class = $this->owner->class;
@ -954,7 +948,7 @@ class Translatable extends DataObjectDecorator {
// copy all fields from owner (apart from ID) // copy all fields from owner (apart from ID)
$newTranslation->update($this->owner->toMap()); $newTranslation->update($this->owner->toMap());
$newTranslation->ID = 0; $newTranslation->ID = 0;
$newTranslation->Lang = $lang; $newTranslation->Locale = $locale;
// hacky way to set an existing translation group in onAfterWrite() // hacky way to set an existing translation group in onAfterWrite()
$translationGroupID = $this->owner->getTranslationGroup(); $translationGroupID = $this->owner->getTranslationGroup();
$newTranslation->_TranslationGroupID = $translationGroupID ? $translationGroupID : $this->owner->ID; $newTranslation->_TranslationGroupID = $translationGroupID ? $translationGroupID : $this->owner->ID;
@ -968,10 +962,11 @@ class Translatable extends DataObjectDecorator {
* Use {@link getTranslation()} to get the actual translated record from * Use {@link getTranslation()} to get the actual translated record from
* the database. * the database.
* *
* @param string $locale
* @return boolean * @return boolean
*/ */
function hasTranslation($lang) { function hasTranslation($locale) {
return (array_search($lang, $this->getTranslatedLangs()) !== false); return (array_search($locale, $this->getTranslatedLangs()) !== false);
} }
/* /*
@ -1007,12 +1002,12 @@ class Translatable extends DataObjectDecorator {
$find = array(); $find = array();
$replace = array(); $replace = array();
if($context && $context->Lang && $context->Lang != Translatable::default_lang()) { if($context && $context->Locale && $context->Locale != Translatable::default_locale()) {
if($children) { if($children) {
foreach($children as $child) { foreach($children as $child) {
if($child->hasTranslation($context->Lang)) { if($child->hasTranslation($context->Locale)) {
$trans = $child->getTranslation($context->Lang); $trans = $child->getTranslation($context->Locale);
if($trans) { if($trans) {
$find[] = $child; $find[] = $child;
$replace[] = $trans; $replace[] = $trans;
@ -1032,16 +1027,16 @@ class Translatable extends DataObjectDecorator {
* Get a list of languages with at least one element translated in (including the default language) * Get a list of languages with at least one element translated in (including the default language)
* *
* @param string $className Look for languages in elements of this class * @param string $className Look for languages in elements of this class
* @return array Map of languages in the form langCode => langName * @return array Map of languages in the form locale => langName
*/ */
static function get_existing_content_languages($className = 'SiteTree', $where = '') { static function get_existing_content_languages($className = 'SiteTree', $where = '') {
if(!Translatable::is_enabled()) return false; if(!Translatable::is_enabled()) return false;
$baseTable = ClassInfo::baseDataClass($className); $baseTable = ClassInfo::baseDataClass($className);
$query = new SQLQuery('Distinct Lang',$baseTable,$where,"",'Lang'); $query = new SQLQuery('Distinct Locale',$baseTable,$where,"",'Locale');
$dbLangs = $query->execute()->column(); $dbLangs = $query->execute()->column();
$langlist = array_merge((array)Translatable::default_lang(), (array)$dbLangs); $langlist = array_merge((array)Translatable::default_locale(), (array)$dbLangs);
$returnMap = array(); $returnMap = array();
$allCodes = array_merge(i18n::$all_locales, i18n::$common_languages); $allCodes = array_merge(i18n::$all_locales, i18n::$common_locales);
foreach ($langlist as $langCode) { foreach ($langlist as $langCode) {
if($langCode) if($langCode)
$returnMap[$langCode] = (is_array($allCodes[$langCode]) ? $allCodes[$langCode][0] : $allCodes[$langCode]); $returnMap[$langCode] = (is_array($allCodes[$langCode]) ? $allCodes[$langCode][0] : $allCodes[$langCode]);
@ -1055,17 +1050,17 @@ class Translatable extends DataObjectDecorator {
* (as identified by RootURLController::$default_homepage_urlsegment). * (as identified by RootURLController::$default_homepage_urlsegment).
* Returns NULL if no translated page can be found. * Returns NULL if no translated page can be found.
* *
* @param string $Lang * @param string $locale
* @return string|boolean URLSegment (e.g. "home") * @return string|boolean URLSegment (e.g. "home")
*/ */
static function get_homepage_urlsegment_by_language($lang) { static function get_homepage_urlsegment_by_language($locale) {
$origHomepageObj = Translatable::get_one_by_lang( $origHomepageObj = Translatable::get_one_by_locale(
'SiteTree', 'SiteTree',
Translatable::default_lang(), Translatable::default_locale(),
sprintf('"URLSegment" = \'%s\'', RootUrlController::get_default_homepage_urlsegment()) sprintf('"URLSegment" = \'%s\'', RootUrlController::get_default_homepage_urlsegment())
); );
if($origHomepageObj) { if($origHomepageObj) {
$translatedHomepageObj = $origHomepageObj->getTranslation(Translatable::current_lang()); $translatedHomepageObj = $origHomepageObj->getTranslation(Translatable::current_locale());
if($translatedHomepageObj) { if($translatedHomepageObj) {
return $translatedHomepageObj->URLSegment; return $translatedHomepageObj->URLSegment;
} }
@ -1074,6 +1069,62 @@ class Translatable extends DataObjectDecorator {
return null; return null;
} }
/**
* @deprecated 2.4 Use is_default_locale()
*/
static function is_default_lang() {
return self::is_default_locale();
}
/**
* @deprecated 2.4 Use set_default_locale()
*/
static function set_default_lang($lang) {
self::set_default_locale($lang);
}
/**
* @deprecated 2.4 Use get_default_locale()
*/
static function get_default_lang() {
return self::get_default_locale();
}
/**
* @deprecated 2.4 Use current_locale()
*/
static function current_lang() {
return self::current_locale();
}
/**
* @deprecated 2.4 Use set_reading_locale()
*/
static function set_reading_lang($lang) {
self::set_reading_locale($lang);
}
/**
* @deprecated 2.4 Use get_reading_locale()
*/
static function get_reading_lang() {
return self::get_reading_locale();
}
/**
* @deprecated 2.4 Use get_by_locale()
*/
static function get_by_lang($class, $lang, $filter = '', $sort = '', $join = "", $limit = "", $containerClass = "DataObjectSet", $having = "") {
return self::get_by_locale($class, $lang, $filter, $sort, $join, $limit, $containerClass, $having);
}
/**
* @deprecated 2.4 Use get_one_by_locale()
*/
static function get_one_by_lang($class, $lang, $filter = '', $cache = false, $orderby = "") {
return self::get_one_by_locale($class, $lang, $filter, $cache, $orderby);
}
} }
/** /**

View File

@ -255,7 +255,7 @@ class Debug {
if(Director::is_ajax()) { if(Director::is_ajax()) {
echo $friendlyErrorMessage; echo $friendlyErrorMessage;
} else { } else {
$errorFilePath = ErrorPage::get_filepath_for_errorcode($statusCode, Translatable::current_lang()); $errorFilePath = ErrorPage::get_filepath_for_errorcode($statusCode, Translatable::current_locale());
if(file_exists($errorfilePath)) { if(file_exists($errorfilePath)) {
echo file_get_contents(ASSETS_PATH . "/error-$statusCode.html"); echo file_get_contents(ASSETS_PATH . "/error-$statusCode.html");
} else { } else {

View File

@ -6,7 +6,7 @@
* If multilingual content is enabled through the {@link Translatable} extension, * If multilingual content is enabled through the {@link Translatable} extension,
* only pages the currently set language on the holder for this searchform are found. * only pages the currently set language on the holder for this searchform are found.
* The language is set through a hidden field in the form, which is prepoluated * The language is set through a hidden field in the form, which is prepoluated
* with {@link Translatable::current_lang()} when then form is constructed. * with {@link Translatable::current_locale()} when then form is constructed.
* *
* @see Use ModelController and SearchContext for a more generic search implementation based around DataObject * @see Use ModelController and SearchContext for a more generic search implementation based around DataObject
* @package sapphire * @package sapphire
@ -55,7 +55,7 @@ class SearchForm extends Form {
} }
if(Translatable::is_enabled()) { if(Translatable::is_enabled()) {
$fields->push(new HiddenField('lang', 'lang', Translatable::current_lang())); $fields->push(new HiddenField('lang', 'lang', Translatable::current_locale()));
} }
if(!$actions) { if(!$actions) {
@ -105,7 +105,7 @@ class SearchForm extends Form {
// set language (if present) // set language (if present)
if(Translatable::is_enabled() && isset($data['lang'])) { if(Translatable::is_enabled() && isset($data['lang'])) {
Translatable::set_reading_lang($data['lang']); Translatable::set_reading_locale($data['lang']);
} }
$keywords = $data['Search']; $keywords = $data['Search'];

View File

@ -35,7 +35,8 @@ class MigrateTranslatableTask extends BuildTask {
// Clone the original, and set it up as a translation // Clone the original, and set it up as a translation
$newtrans = $original->duplicate(false); $newtrans = $original->duplicate(false);
$newtrans->OriginalID = $original->ID; $newtrans->OriginalID = $original->ID;
$newtrans->Lang = $oldtrans['Lang']; // we have to "guess" a locale based on the language
$newtrans->Locale = i18n::get_locale_from_lang($oldtrans['Lang']);
if($stage == 'Live' && array_key_exists($original->ID, $ids)) { if($stage == 'Live' && array_key_exists($original->ID, $ids)) {
$newtrans->ID = $ids[$original->ID]; $newtrans->ID = $ids[$original->ID];
} }
@ -53,7 +54,7 @@ class MigrateTranslatableTask extends BuildTask {
// Copy each translated field into the new translation // Copy each translated field into the new translation
if($oldtransitem) foreach($oldtransitem as $key => $value) { if($oldtransitem) foreach($oldtransitem as $key => $value) {
if(!in_array($key, array('ID', 'OriginalLangID', 'ClassName', 'Lang'))) { if(!in_array($key, array('ID', 'OriginalLangID', 'ClassName'))) {
$newtrans->$key = $value; $newtrans->$key = $value;
} }
} }
@ -62,10 +63,10 @@ class MigrateTranslatableTask extends BuildTask {
// Write the new translation to the database // Write the new translation to the database
$sitelang = Translatable::current_lang(); $sitelang = Translatable::current_locale();
Translatable::set_reading_lang($newtrans->Lang); Translatable::set_reading_locale($newtrans->Locale);
$newtrans->writeToStage($stage, true); $newtrans->writeToStage($stage, true);
Translatable::set_reading_lang($sitelang); Translatable::set_reading_locale($sitelang);
if($stage == 'Stage') { if($stage == 'Stage') {
$ids[$original->ID] = $newtrans->ID; $ids[$original->ID] = $newtrans->ID;

View File

@ -16,9 +16,9 @@ class TranslatableTest extends FunctionalTest {
function setUp() { function setUp() {
$this->origTranslatableSettings['enabled'] = Translatable::is_enabled(); $this->origTranslatableSettings['enabled'] = Translatable::is_enabled();
$this->origTranslatableSettings['default_lang'] = Translatable::default_lang(); $this->origTranslatableSettings['default_locale'] = Translatable::default_locale();
Translatable::enable(); Translatable::enable();
Translatable::set_default_lang("en"); Translatable::set_default_locale("en_US");
// needs to recreate the database schema with language properties // needs to recreate the database schema with language properties
self::kill_temp_db(); self::kill_temp_db();
@ -34,7 +34,7 @@ class TranslatableTest extends FunctionalTest {
function tearDown() { function tearDown() {
if(!$this->origTranslatableSettings['enabled']) Translatable::disable(); if(!$this->origTranslatableSettings['enabled']) Translatable::disable();
Translatable::set_default_lang($this->origTranslatableSettings['default_lang']); Translatable::set_default_locale($this->origTranslatableSettings['default_locale']);
self::kill_temp_db(); self::kill_temp_db();
self::create_temp_db(); self::create_temp_db();
@ -45,68 +45,68 @@ class TranslatableTest extends FunctionalTest {
function testTranslationGroups() { function testTranslationGroups() {
// first in french // first in french
$frPage = new SiteTree(); $frPage = new SiteTree();
$frPage->Lang = 'fr'; $frPage->Locale = 'fr_FR';
$frPage->write(); $frPage->write();
// second in english (from french "original") // second in english (from french "original")
$enPage = $frPage->createTranslation('en'); $enPage = $frPage->createTranslation('en_US');
// third in spanish (from the english translation) // third in spanish (from the english translation)
$esPage = $enPage->createTranslation('es'); $esPage = $enPage->createTranslation('es_ES');
// test french // test french
$this->assertEquals( $this->assertEquals(
$frPage->getTranslations()->column('Lang'), $frPage->getTranslations()->column('Locale'),
array('en','es') array('en_US','es_ES')
); );
$this->assertNotNull($frPage->getTranslation('en')); $this->assertNotNull($frPage->getTranslation('en_US'));
$this->assertEquals( $this->assertEquals(
$frPage->getTranslation('en')->ID, $frPage->getTranslation('en_US')->ID,
$enPage->ID $enPage->ID
); );
$this->assertNotNull($frPage->getTranslation('es')); $this->assertNotNull($frPage->getTranslation('es_ES'));
$this->assertEquals( $this->assertEquals(
$frPage->getTranslation('es')->ID, $frPage->getTranslation('es_ES')->ID,
$esPage->ID $esPage->ID
); );
// test english // test english
$this->assertEquals( $this->assertEquals(
$enPage->getTranslations()->column('Lang'), $enPage->getTranslations()->column('Locale'),
array('fr','es') array('fr_FR','es_ES')
); );
$this->assertNotNull($frPage->getTranslation('fr')); $this->assertNotNull($frPage->getTranslation('fr_FR'));
$this->assertEquals( $this->assertEquals(
$enPage->getTranslation('fr')->ID, $enPage->getTranslation('fr_FR')->ID,
$frPage->ID $frPage->ID
); );
$this->assertNotNull($frPage->getTranslation('es')); $this->assertNotNull($frPage->getTranslation('es_ES'));
$this->assertEquals( $this->assertEquals(
$enPage->getTranslation('es')->ID, $enPage->getTranslation('es_ES')->ID,
$esPage->ID $esPage->ID
); );
// test spanish // test spanish
$this->assertEquals( $this->assertEquals(
$esPage->getTranslations()->column('Lang'), $esPage->getTranslations()->column('Locale'),
array('fr','en') array('fr_FR','en_US')
); );
$this->assertNotNull($esPage->getTranslation('fr')); $this->assertNotNull($esPage->getTranslation('fr_FR'));
$this->assertEquals( $this->assertEquals(
$esPage->getTranslation('fr')->ID, $esPage->getTranslation('fr_FR')->ID,
$frPage->ID $frPage->ID
); );
$this->assertNotNull($esPage->getTranslation('en')); $this->assertNotNull($esPage->getTranslation('en_US'));
$this->assertEquals( $this->assertEquals(
$esPage->getTranslation('en')->ID, $esPage->getTranslation('en_US')->ID,
$enPage->ID $enPage->ID
); );
} }
function testGetTranslationOnSiteTree() { function testGetTranslationOnSiteTree() {
$origPage = $this->objFromFixture('Page', 'testpage_en'); $origPage = $this->objFromFixture('Page', 'testpage_en');
$translatedPage = $origPage->createTranslation('fr'); $translatedPage = $origPage->createTranslation('fr_FR');
$getTranslationPage = $origPage->getTranslation('fr'); $getTranslationPage = $origPage->getTranslation('fr_FR');
$this->assertNotNull($getTranslationPage); $this->assertNotNull($getTranslationPage);
$this->assertEquals($getTranslationPage->ID, $translatedPage->ID); $this->assertEquals($getTranslationPage->ID, $translatedPage->ID);
@ -116,18 +116,18 @@ class TranslatableTest extends FunctionalTest {
$origPage = $this->objFromFixture('Page', 'testpage_en'); $origPage = $this->objFromFixture('Page', 'testpage_en');
// through createTranslation() // through createTranslation()
$translationAf = $origPage->createTranslation('af'); $translationAf = $origPage->createTranslation('af_ZA');
// create a new language on an unrelated page which shouldnt be returned from $origPage // create a new language on an unrelated page which shouldnt be returned from $origPage
$otherPage = new Page(); $otherPage = new Page();
$otherPage->write(); $otherPage->write();
$otherTranslationEs = $otherPage->createTranslation('es'); $otherTranslationEs = $otherPage->createTranslation('es_ES');
$this->assertEquals( $this->assertEquals(
$origPage->getTranslatedLangs(), $origPage->getTranslatedLangs(),
array( array(
'af', 'af_ZA',
//'en', // default language is not included //'en_US', // default language is not included
), ),
'Language codes are returned specifically for the queried page through getTranslatedLangs()' 'Language codes are returned specifically for the queried page through getTranslatedLangs()'
); );
@ -143,7 +143,7 @@ class TranslatableTest extends FunctionalTest {
// manual creation of page without an original link // manual creation of page without an original link
$translationDeWithoutOriginal = new Page(); $translationDeWithoutOriginal = new Page();
$translationDeWithoutOriginal->Lang = 'de'; $translationDeWithoutOriginal->Locale = 'de_DE';
$translationDeWithoutOriginal->write(); $translationDeWithoutOriginal->write();
$this->assertEquals( $this->assertEquals(
$translationDeWithoutOriginal->getTranslatedLangs(), $translationDeWithoutOriginal->getTranslatedLangs(),
@ -154,7 +154,7 @@ class TranslatableTest extends FunctionalTest {
function testTranslationCanHaveSameURLSegment() { function testTranslationCanHaveSameURLSegment() {
$origPage = $this->objFromFixture('Page', 'testpage_en'); $origPage = $this->objFromFixture('Page', 'testpage_en');
$translatedPage = $origPage->createTranslation('de'); $translatedPage = $origPage->createTranslation('de_DE');
$translatedPage->URLSegment = 'testpage'; $translatedPage->URLSegment = 'testpage';
$this->assertEquals($origPage->URLSegment, $translatedPage->URLSegment); $this->assertEquals($origPage->URLSegment, $translatedPage->URLSegment);
@ -176,7 +176,7 @@ class TranslatableTest extends FunctionalTest {
); );
// then in "translation mode" // then in "translation mode"
$pageTranslated = $pageOrigLang->createTranslation('fr'); $pageTranslated = $pageOrigLang->createTranslation('fr_FR');
$fields = $pageTranslated->getCMSFields(); $fields = $pageTranslated->getCMSFields();
$this->assertType( $this->assertType(
'TextField', 'TextField',
@ -195,7 +195,7 @@ class TranslatableTest extends FunctionalTest {
function testDataObjectGetWithReadingLanguage() { function testDataObjectGetWithReadingLanguage() {
$origTestPage = $this->objFromFixture('Page', 'testpage_en'); $origTestPage = $this->objFromFixture('Page', 'testpage_en');
$otherTestPage = $this->objFromFixture('Page', 'othertestpage_en'); $otherTestPage = $this->objFromFixture('Page', 'othertestpage_en');
$translatedPage = $origTestPage->createTranslation('de'); $translatedPage = $origTestPage->createTranslation('de_DE');
// test in default language // test in default language
$resultPagesDefaultLang = DataObject::get( $resultPagesDefaultLang = DataObject::get(
@ -208,7 +208,7 @@ class TranslatableTest extends FunctionalTest {
$this->assertNotContains($translatedPage->ID, $resultPagesDefaultLang->column('ID')); $this->assertNotContains($translatedPage->ID, $resultPagesDefaultLang->column('ID'));
// test in custom language // test in custom language
Translatable::set_reading_lang('de'); Translatable::set_reading_locale('de_DE');
$resultPagesCustomLang = DataObject::get( $resultPagesCustomLang = DataObject::get(
'Page', 'Page',
sprintf("\"SiteTree\".\"MenuTitle\" = '%s'", 'A Testpage') sprintf("\"SiteTree\".\"MenuTitle\" = '%s'", 'A Testpage')
@ -219,12 +219,12 @@ class TranslatableTest extends FunctionalTest {
// casting as a workaround for types not properly set on duplicated dataobjects from createTranslation() // casting as a workaround for types not properly set on duplicated dataobjects from createTranslation()
$this->assertContains((string)$translatedPage->ID, $resultPagesCustomLang->column('ID')); $this->assertContains((string)$translatedPage->ID, $resultPagesCustomLang->column('ID'));
Translatable::set_reading_lang('en'); Translatable::set_reading_locale('en_US');
} }
function testDataObjectGetByIdWithReadingLanguage() { function testDataObjectGetByIdWithReadingLanguage() {
$origPage = $this->objFromFixture('Page', 'testpage_en'); $origPage = $this->objFromFixture('Page', 'testpage_en');
$translatedPage = $origPage->createTranslation('de'); $translatedPage = $origPage->createTranslation('de_DE');
$compareOrigPage = DataObject::get_by_id('Page', $origPage->ID); $compareOrigPage = DataObject::get_by_id('Page', $origPage->ID);
$this->assertEquals( $this->assertEquals(
@ -236,10 +236,10 @@ class TranslatableTest extends FunctionalTest {
function testDataObjectGetOneWithReadingLanguage() { function testDataObjectGetOneWithReadingLanguage() {
$origPage = $this->objFromFixture('Page', 'testpage_en'); $origPage = $this->objFromFixture('Page', 'testpage_en');
$translatedPage = $origPage->createTranslation('de'); $translatedPage = $origPage->createTranslation('de_DE');
// running the same query twice with different // running the same query twice with different
Translatable::set_reading_lang('de'); Translatable::set_reading_locale('de_DE');
$compareTranslatedPage = DataObject::get_one( $compareTranslatedPage = DataObject::get_one(
'Page', 'Page',
sprintf("\"SiteTree\".\"Title\" = '%s'", $translatedPage->Title) sprintf("\"SiteTree\".\"Title\" = '%s'", $translatedPage->Title)
@ -252,17 +252,17 @@ class TranslatableTest extends FunctionalTest {
); );
// reset language to default // reset language to default
Translatable::set_reading_lang('de'); Translatable::set_reading_locale('de_DE');
} }
function testModifyTranslationWithDefaultReadingLang() { function testModifyTranslationWithDefaultReadingLang() {
$origPage = $this->objFromFixture('Page', 'testpage_en'); $origPage = $this->objFromFixture('Page', 'testpage_en');
$translatedPage = $origPage->createTranslation('de'); $translatedPage = $origPage->createTranslation('de_DE');
Translatable::set_reading_lang('en'); Translatable::set_reading_locale('en_US');
$translatedPage->Title = 'De Modified'; $translatedPage->Title = 'De Modified';
$translatedPage->write(); $translatedPage->write();
$savedTranslatedPage = $origPage->getTranslation('de'); $savedTranslatedPage = $origPage->getTranslation('de_DE');
$this->assertEquals( $this->assertEquals(
$savedTranslatedPage->Title, $savedTranslatedPage->Title,
'De Modified', 'De Modified',
@ -277,9 +277,9 @@ class TranslatableTest extends FunctionalTest {
function testSiteTreePublication() { function testSiteTreePublication() {
$origPage = $this->objFromFixture('Page', 'testpage_en'); $origPage = $this->objFromFixture('Page', 'testpage_en');
$translatedPage = $origPage->createTranslation('de'); $translatedPage = $origPage->createTranslation('de_DE');
Translatable::set_reading_lang('en'); Translatable::set_reading_locale('en_US');
$origPage->Title = 'En Modified'; $origPage->Title = 'En Modified';
$origPage->write(); $origPage->write();
// modifying a record in language which is not the reading language should still write the record correctly // modifying a record in language which is not the reading language should still write the record correctly
@ -296,14 +296,14 @@ class TranslatableTest extends FunctionalTest {
function testDeletingTranslationKeepsOriginal() { function testDeletingTranslationKeepsOriginal() {
$origPage = $this->objFromFixture('Page', 'testpage_en'); $origPage = $this->objFromFixture('Page', 'testpage_en');
$translatedPage = $origPage->createTranslation('de'); $translatedPage = $origPage->createTranslation('de_DE');
$translatedPageID = $translatedPage->ID; $translatedPageID = $translatedPage->ID;
$translatedPage->delete(); $translatedPage->delete();
$translatedPage->flushCache(); $translatedPage->flushCache();
$origPage->flushCache(); $origPage->flushCache();
$this->assertNull($origPage->getTranslation('de')); $this->assertNull($origPage->getTranslation('de_DE'));
$this->assertNotNull(DataObject::get_by_id('Page', $origPage->ID)); $this->assertNotNull(DataObject::get_by_id('Page', $origPage->ID));
} }
@ -314,13 +314,13 @@ class TranslatableTest extends FunctionalTest {
$child3Page = $this->objFromFixture('Page', 'child3'); $child3Page = $this->objFromFixture('Page', 'child3');
$grandchildPage = $this->objFromFixture('Page', 'grandchild'); $grandchildPage = $this->objFromFixture('Page', 'grandchild');
$parentPageTranslated = $parentPage->createTranslation('de'); $parentPageTranslated = $parentPage->createTranslation('de_DE');
$child4PageTranslated = new SiteTree(); $child4PageTranslated = new SiteTree();
$child4PageTranslated->Lang = 'de'; $child4PageTranslated->Locale = 'de_DE';
$child4PageTranslated->ParentID = $parentPageTranslated->ID; $child4PageTranslated->ParentID = $parentPageTranslated->ID;
$child4PageTranslated->write(); $child4PageTranslated->write();
Translatable::set_reading_lang('en'); Translatable::set_reading_locale('en_US');
$this->assertEquals( $this->assertEquals(
$parentPage->Children()->column('ID'), $parentPage->Children()->column('ID'),
array( array(
@ -331,7 +331,7 @@ class TranslatableTest extends FunctionalTest {
"Showing Children() in default language doesnt show children in other languages" "Showing Children() in default language doesnt show children in other languages"
); );
Translatable::set_reading_lang('de'); Translatable::set_reading_locale('de_DE');
$parentPage->flushCache(); $parentPage->flushCache();
$this->assertEquals( $this->assertEquals(
$parentPageTranslated->Children()->column('ID'), $parentPageTranslated->Children()->column('ID'),
@ -340,7 +340,7 @@ class TranslatableTest extends FunctionalTest {
); );
// reset language // reset language
Translatable::set_reading_lang('en'); Translatable::set_reading_locale('en_US');
} }
function testHierarchyLiveStageChildren() { function testHierarchyLiveStageChildren() {
@ -351,20 +351,20 @@ class TranslatableTest extends FunctionalTest {
$child3Page = $this->objFromFixture('Page', 'child3'); $child3Page = $this->objFromFixture('Page', 'child3');
$grandchildPage = $this->objFromFixture('Page', 'grandchild'); $grandchildPage = $this->objFromFixture('Page', 'grandchild');
$parentPageTranslated = $parentPage->createTranslation('de'); $parentPageTranslated = $parentPage->createTranslation('de_DE');
$child4PageTranslated = new SiteTree(); $child4PageTranslated = new SiteTree();
$child4PageTranslated->Lang = 'de'; $child4PageTranslated->Locale = 'de_DE';
$child4PageTranslated->ParentID = $parentPageTranslated->ID; $child4PageTranslated->ParentID = $parentPageTranslated->ID;
$child4PageTranslated->write(); $child4PageTranslated->write();
$child4PageTranslated->publish('Stage', 'Live'); $child4PageTranslated->publish('Stage', 'Live');
$child5PageTranslated = new SiteTree(); $child5PageTranslated = new SiteTree();
$child5PageTranslated->Lang = 'de'; $child5PageTranslated->Locale = 'de_DE';
$child5PageTranslated->ParentID = $parentPageTranslated->ID; $child5PageTranslated->ParentID = $parentPageTranslated->ID;
$child5PageTranslated->write(); $child5PageTranslated->write();
Translatable::set_reading_lang('en'); Translatable::set_reading_lang('en_US');
$this->assertNotNull($parentPage->liveChildren()); $this->assertNotNull($parentPage->liveChildren());
$this->assertEquals( $this->assertEquals(
$parentPage->liveChildren()->column('ID'), $parentPage->liveChildren()->column('ID'),
@ -384,7 +384,7 @@ class TranslatableTest extends FunctionalTest {
"Showing stageChildren() in default language doesnt show children in other languages" "Showing stageChildren() in default language doesnt show children in other languages"
); );
Translatable::set_reading_lang('de'); Translatable::set_reading_lang('de_DE');
$parentPage->flushCache(); $parentPage->flushCache();
$this->assertNotNull($parentPageTranslated->liveChildren()); $this->assertNotNull($parentPageTranslated->liveChildren());
$this->assertEquals( $this->assertEquals(
@ -403,35 +403,35 @@ class TranslatableTest extends FunctionalTest {
); );
// reset language // reset language
Translatable::set_reading_lang('en'); Translatable::set_reading_lang('en_US');
} }
function testTranslatablePropertiesOnSiteTree() { function testTranslatablePropertiesOnSiteTree() {
$origObj = $this->objFromFixture('TranslatableTest_Page', 'testpage_en'); $origObj = $this->objFromFixture('TranslatableTest_Page', 'testpage_en');
$translatedObj = $origObj->createTranslation('fr'); $translatedObj = $origObj->createTranslation('fr_FR');
$translatedObj->TranslatableProperty = 'Fr'; $translatedObj->TranslatableProperty = 'fr_FR';
$translatedObj->write(); $translatedObj->write();
$this->assertEquals( $this->assertEquals(
$origObj->TranslatableProperty, $origObj->TranslatableProperty,
'En', 'en_US',
'Creating a translation doesnt affect database field on original object' 'Creating a translation doesnt affect database field on original object'
); );
$this->assertEquals( $this->assertEquals(
$translatedObj->TranslatableProperty, $translatedObj->TranslatableProperty,
'Fr', 'fr_FR',
'Translated object saves database field independently of original object' 'Translated object saves database field independently of original object'
); );
} }
function testCreateTranslationOnSiteTree() { function testCreateTranslationOnSiteTree() {
$origPage = $this->objFromFixture('Page', 'testpage_en'); $origPage = $this->objFromFixture('Page', 'testpage_en');
$translatedPage = $origPage->createTranslation('de'); $translatedPage = $origPage->createTranslation('de_DE');
$this->assertEquals($translatedPage->Lang, 'de'); $this->assertEquals($translatedPage->Locale, 'de_DE');
$this->assertNotEquals($translatedPage->ID, $origPage->ID); $this->assertNotEquals($translatedPage->ID, $origPage->ID);
$subsequentTranslatedPage = $origPage->createTranslation('de'); $subsequentTranslatedPage = $origPage->createTranslation('de_DE');
$this->assertEquals( $this->assertEquals(
$translatedPage->ID, $translatedPage->ID,
$subsequentTranslatedPage->ID, $subsequentTranslatedPage->ID,
@ -441,43 +441,43 @@ class TranslatableTest extends FunctionalTest {
function testTranslatablePropertiesOnDataObject() { function testTranslatablePropertiesOnDataObject() {
$origObj = $this->objFromFixture('TranslatableTest_DataObject', 'testobject_en'); $origObj = $this->objFromFixture('TranslatableTest_DataObject', 'testobject_en');
$translatedObj = $origObj->createTranslation('fr'); $translatedObj = $origObj->createTranslation('fr_FR');
$translatedObj->TranslatableProperty = 'Fr'; $translatedObj->TranslatableProperty = 'fr_FR';
$translatedObj->TranslatableDecoratedProperty = 'Fr'; $translatedObj->TranslatableDecoratedProperty = 'fr_FR';
$translatedObj->write(); $translatedObj->write();
$this->assertEquals( $this->assertEquals(
$origObj->TranslatableProperty, $origObj->TranslatableProperty,
'En', 'en_US',
'Creating a translation doesnt affect database field on original object' 'Creating a translation doesnt affect database field on original object'
); );
$this->assertEquals( $this->assertEquals(
$origObj->TranslatableDecoratedProperty, $origObj->TranslatableDecoratedProperty,
'En', 'en_US',
'Creating a translation doesnt affect decorated database field on original object' 'Creating a translation doesnt affect decorated database field on original object'
); );
$this->assertEquals( $this->assertEquals(
$translatedObj->TranslatableProperty, $translatedObj->TranslatableProperty,
'Fr', 'fr_FR',
'Translated object saves database field independently of original object' 'Translated object saves database field independently of original object'
); );
$this->assertEquals( $this->assertEquals(
$translatedObj->TranslatableDecoratedProperty, $translatedObj->TranslatableDecoratedProperty,
'Fr', 'fr_FR',
'Translated object saves decorated database field independently of original object' 'Translated object saves decorated database field independently of original object'
); );
} }
function testCreateTranslationWithoutOriginal() { function testCreateTranslationWithoutOriginal() {
$origParentPage = $this->objFromFixture('Page', 'testpage_en'); $origParentPage = $this->objFromFixture('Page', 'testpage_en');
$translatedParentPage = $origParentPage->createTranslation('de'); $translatedParentPage = $origParentPage->createTranslation('de_DE');
$translatedPageWithoutOriginal = new SiteTree(); $translatedPageWithoutOriginal = new SiteTree();
$translatedPageWithoutOriginal->ParentID = $translatedParentPage->ID; $translatedPageWithoutOriginal->ParentID = $translatedParentPage->ID;
$translatedPageWithoutOriginal->Lang = 'de'; $translatedPageWithoutOriginal->Locale = 'de_DE';
$translatedPageWithoutOriginal->write(); $translatedPageWithoutOriginal->write();
Translatable::set_reading_lang('de'); Translatable::set_reading_locale('de_DE');
$this->assertEquals( $this->assertEquals(
$translatedParentPage->stageChildren()->column('ID'), $translatedParentPage->stageChildren()->column('ID'),
array( array(
@ -486,7 +486,7 @@ class TranslatableTest extends FunctionalTest {
"Children() still works on a translated page even if no translation group is set" "Children() still works on a translated page even if no translation group is set"
); );
Translatable::set_reading_lang('en'); Translatable::set_reading_locale('en_US');
} }
function testCreateTranslationTranslatesUntranslatedParents() { function testCreateTranslationTranslatesUntranslatedParents() {
@ -495,23 +495,23 @@ class TranslatableTest extends FunctionalTest {
$child1PageOrigID = $child1Page->ID; $child1PageOrigID = $child1Page->ID;
$grandchildPage = $this->objFromFixture('Page', 'grandchild'); $grandchildPage = $this->objFromFixture('Page', 'grandchild');
$this->assertFalse($grandchildPage->hasTranslation('de')); $this->assertFalse($grandchildPage->hasTranslation('de_DE'));
$this->assertFalse($child1Page->hasTranslation('de')); $this->assertFalse($child1Page->hasTranslation('de_DE'));
$this->assertFalse($parentPage->hasTranslation('de')); $this->assertFalse($parentPage->hasTranslation('de_DE'));
$translatedGrandChildPage = $grandchildPage->createTranslation('de'); $translatedGrandChildPage = $grandchildPage->createTranslation('de_DE');
$this->assertTrue($grandchildPage->hasTranslation('de')); $this->assertTrue($grandchildPage->hasTranslation('de_DE'));
$this->assertTrue($child1Page->hasTranslation('de')); $this->assertTrue($child1Page->hasTranslation('de_DE'));
$this->assertTrue($parentPage->hasTranslation('de')); $this->assertTrue($parentPage->hasTranslation('de_DE'));
} }
function testHierarchyAllChildrenIncludingDeleted() { function testHierarchyAllChildrenIncludingDeleted() {
// Original tree in 'en': // Original tree in 'en_US':
// parent // parent
// child1 (Live only, deleted from stage) // child1 (Live only, deleted from stage)
// child2 (Stage only, never published) // child2 (Stage only, never published)
// child3 (Stage only, never published, untranslated) // child3 (Stage only, never published, untranslated)
// Translated tree in 'de': // Translated tree in 'de_DE':
// parent // parent
// child1 (Live only, deleted from stage) // child1 (Live only, deleted from stage)
// child2 (Stage only) // child2 (Stage only)
@ -521,7 +521,7 @@ class TranslatableTest extends FunctionalTest {
$parentPageID = $parentPage->ID; $parentPageID = $parentPage->ID;
// Create parent translation // Create parent translation
$translatedParentPage = $parentPage->createTranslation('de'); $translatedParentPage = $parentPage->createTranslation('de_DE');
$translatedParentPageID = $translatedParentPage->ID; $translatedParentPageID = $translatedParentPage->ID;
// Create child1 // Create child1
@ -530,7 +530,7 @@ class TranslatableTest extends FunctionalTest {
$child1Page->publish('Stage', 'Live'); $child1Page->publish('Stage', 'Live');
// Create child1 translation // Create child1 translation
$child1PageTranslated = $child1Page->createTranslation('de'); $child1PageTranslated = $child1Page->createTranslation('de_DE');
$child1PageTranslatedID = $child1PageTranslated->ID; $child1PageTranslatedID = $child1PageTranslated->ID;
$child1PageTranslated->publish('Stage', 'Live'); $child1PageTranslated->publish('Stage', 'Live');
$child1PageTranslated->deleteFromStage('Stage'); // deleted from stage only, record still exists on live $child1PageTranslated->deleteFromStage('Stage'); // deleted from stage only, record still exists on live
@ -541,7 +541,7 @@ class TranslatableTest extends FunctionalTest {
$child2PageID = $child2Page->ID; $child2PageID = $child2Page->ID;
// Create child2 translation // Create child2 translation
$child2PageTranslated = $child2Page->createTranslation('de'); $child2PageTranslated = $child2Page->createTranslation('de_DE');
$child2PageTranslatedID = $child2PageTranslated->ID; $child2PageTranslatedID = $child2PageTranslated->ID;
// Create child3 // Create child3
@ -549,7 +549,7 @@ class TranslatableTest extends FunctionalTest {
$child3PageID = $child3Page->ID; $child3PageID = $child3Page->ID;
// on original parent in default language // on original parent in default language
Translatable::set_reading_lang('en'); Translatable::set_reading_locale('en_US');
SiteTree::flush_and_destroy_cache(); SiteTree::flush_and_destroy_cache();
$parentPage = $this->objFromFixture('Page', 'parent'); $parentPage = $this->objFromFixture('Page', 'parent');
$children = $parentPage->AllChildrenIncludingDeleted(); $children = $parentPage->AllChildrenIncludingDeleted();
@ -564,7 +564,7 @@ class TranslatableTest extends FunctionalTest {
); );
// on original parent in translation mode // on original parent in translation mode
Translatable::set_reading_lang('de'); Translatable::set_reading_locale('de_DE');
SiteTree::flush_and_destroy_cache(); SiteTree::flush_and_destroy_cache();
$parentPage = $this->objFromFixture('Page', 'parent'); $parentPage = $this->objFromFixture('Page', 'parent');
$this->assertEquals( $this->assertEquals(
@ -576,11 +576,11 @@ class TranslatableTest extends FunctionalTest {
"Showing AllChildrenIncludingDeleted() in translation mode with parent page in default language shows children in default language" "Showing AllChildrenIncludingDeleted() in translation mode with parent page in default language shows children in default language"
); );
// @todo getTranslation() doesn't switch languages for future calls, its handled statically through set_reading_lang() // @todo getTranslation() doesn't switch languages for future calls, its handled statically through set_reading_locale()
// // on translated page in translation mode using getTranslation() // // on translated page in translation mode using getTranslation()
// SiteTree::flush_and_destroy_cache(); // SiteTree::flush_and_destroy_cache();
// $parentPage = $this->objFromFixture('Page', 'parent'); // $parentPage = $this->objFromFixture('Page', 'parent');
// $translatedParentPage = $parentPage->getTranslation('de'); // $translatedParentPage = $parentPage->getTranslation('de_DE');
// $this->assertEquals( // $this->assertEquals(
// $translatedParentPage->AllChildrenIncludingDeleted()->column('ID'), // $translatedParentPage->AllChildrenIncludingDeleted()->column('ID'),
// array( // array(
@ -591,7 +591,7 @@ class TranslatableTest extends FunctionalTest {
// ); // );
// reset language // reset language
Translatable::set_reading_lang('en'); Translatable::set_reading_locale('en_US');
} }
function testRootUrlDefaultsToTranslatedUrlSegment() { function testRootUrlDefaultsToTranslatedUrlSegment() {
@ -599,14 +599,14 @@ class TranslatableTest extends FunctionalTest {
$origPage = $this->objFromFixture('Page', 'homepage_en'); $origPage = $this->objFromFixture('Page', 'homepage_en');
$origPage->publish('Stage', 'Live'); $origPage->publish('Stage', 'Live');
$translationDe = $origPage->createTranslation('de'); $translationDe = $origPage->createTranslation('de_DE');
$translationDe->URLSegment = 'heim'; $translationDe->URLSegment = 'heim';
$translationDe->write(); $translationDe->write();
$translationDe->publish('Stage', 'Live'); $translationDe->publish('Stage', 'Live');
// test with translatable enabled // test with translatable enabled
$_SERVER['HTTP_HOST'] = '/?lang=de'; $_SERVER['HTTP_HOST'] = '/?locale=de';
Translatable::set_reading_lang('de'); Translatable::set_reading_locale('de_DE');
$this->assertEquals( $this->assertEquals(
RootURLController::get_homepage_urlsegment(), RootURLController::get_homepage_urlsegment(),
'heim', 'heim',
@ -624,7 +624,7 @@ class TranslatableTest extends FunctionalTest {
Translatable::enable(); Translatable::enable();
// setting back to default // setting back to default
Translatable::set_reading_lang('en'); Translatable::set_reading_locale('en_US');
$_SERVER['HTTP_HOST'] = $_originalHost; $_SERVER['HTTP_HOST'] = $_originalHost;
} }
} }

View File

@ -2,17 +2,17 @@ Page:
homepage_en: homepage_en:
Title: Home Title: Home
URLSegment: home URLSegment: home
Lang: en Locale: en_US
testpage_en: testpage_en:
Title: Home Title: Home
MenuTitle: A Testpage MenuTitle: A Testpage
URLSegment: testpage URLSegment: testpage
Lang: en Locale: en_US
othertestpage_en: othertestpage_en:
Title: Other Testpage Title: Other Testpage
MenuTitle: A Testpage MenuTitle: A Testpage
URLSegment: othertestpage URLSegment: othertestpage
Lang: en Locale: en_US
parent: parent:
Title: Parent Title: Parent
URLSegment: parent URLSegment: parent
@ -34,10 +34,10 @@ Page:
Parent: =>Page.child1 Parent: =>Page.child1
TranslatableTest_DataObject: TranslatableTest_DataObject:
testobject_en: testobject_en:
TranslatableProperty: En TranslatableProperty: en_US
TranslatableDecoratedProperty: En TranslatableDecoratedProperty: en_US
TranslatableTest_Page: TranslatableTest_Page:
testpage_en: testpage_en:
Title: En Title: En
TranslatableProperty: En TranslatableProperty: en_US
URLSegment: testpage-en URLSegment: testpage-en

View File

@ -12,10 +12,10 @@ class TranslatableSearchFormTest extends FunctionalTest {
protected $recreateTempDb = true; protected $recreateTempDb = true;
function setUp() { function setUp() {
$this->origTranslatableSettings['enabled'] = Translatable::is_enabled(); $this->origTranslatableSettings['enabled'] = Translatable::is_enabled();default_locale
$this->origTranslatableSettings['default_lang'] = Translatable::default_lang(); $this->origTranslatableSettings['default_locale'] = Translatable::default_locale();
Translatable::enable(); Translatable::enable();
Translatable::set_default_lang("en"); Translatable::set_default_locale("en");
// needs to recreate the database schema with language properties // needs to recreate the database schema with language properties
self::kill_temp_db(); self::kill_temp_db();
@ -34,7 +34,7 @@ class TranslatableSearchFormTest extends FunctionalTest {
function tearDown() { function tearDown() {
if(!$this->origTranslatableSettings['enabled']) Translatable::disable(); if(!$this->origTranslatableSettings['enabled']) Translatable::disable();
Translatable::set_default_lang($this->origTranslatableSettings['default_lang']); Translatable::set_default_locale($this->origTranslatableSettings['default_locale']);
self::kill_temp_db(); self::kill_temp_db();
self::create_temp_db(); self::create_temp_db();
@ -53,7 +53,7 @@ class TranslatableSearchFormTest extends FunctionalTest {
$translatedPublishedPage->write(); $translatedPublishedPage->write();
$translatedPublishedPage->publish('Stage', 'Live'); $translatedPublishedPage->publish('Stage', 'Live');
// Translatable::set_reading_lang() can't be used because the context // Translatable::set_reading_locale() can't be used because the context
// from the holder is not present here - we set the language explicitly // from the holder is not present here - we set the language explicitly
// through a pseudo GET variable in getResults() // through a pseudo GET variable in getResults()