ENHANCEMENT Added proxy-functions for Translatable to provide a consistent interface for developers

ENHANCEMENT Explicit attribute-visibility
ENHANCEMENT Empty $current_locale by default, get_locale() falls back to $default_locale (avoid duplication)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@43657 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-10-21 00:50:31 +00:00
parent c5ec4314b4
commit bbe86015d7

View File

@ -9,23 +9,23 @@
class i18n extends Controller { class i18n extends Controller {
/** /**
* This static variable is used to store the current defined locale. Default value is 'en_US' * This static variable is used to store the current defined locale.
*/ */
static $current_locale = 'en_US'; protected static $current_locale = '';
/** /**
* This is the locale in which generated language files are (we assume US English) * This is the locale in which generated language files are (we assume US English)
* *
* @var string * @var string
*/ */
static $default_locale = 'en_US'; protected static $default_locale = 'en_US';
/** /**
* An exhaustive list of possible locales (code => language and country) * An exhaustive list of possible locales (code => language and country)
* *
* @var array * @var array
*/ */
static $all_locales = array( public static $all_locales = array(
'aa_DJ' => 'Afar (Djibouti)', 'aa_DJ' => 'Afar (Djibouti)',
'ab_GE' => 'Abkhazian (Georgia)', 'ab_GE' => 'Abkhazian (Georgia)',
'abr_GH' => 'Abron (Ghana)', 'abr_GH' => 'Abron (Ghana)',
@ -504,7 +504,7 @@ class i18n extends Controller {
* A list of commonly used languages, in the form * A list of commonly used languages, in the form
* langcode => array( EnglishName, NativeName) * langcode => array( EnglishName, NativeName)
*/ */
static $common_languages = array( public static $common_languages = array(
'af' => array('Afrikaans', 'Afrikaans'), 'af' => array('Afrikaans', 'Afrikaans'),
'sq' => array('Albanian', 'shqip'), 'sq' => array('Albanian', 'shqip'),
'ar' => array('Arabic', 'العربية'), 'ar' => array('Arabic', 'العربية'),
@ -1052,10 +1052,26 @@ class i18n extends Controller {
* @return string Current locale in the system * @return string Current locale in the system
*/ */
static function get_locale() { static function get_locale() {
return self::$current_locale; return (!empty(self::$current_locale)) ? self::$current_locale : self::$default_locale;
} }
/**
* Set default language (proxy for Translatable::set_default_lang())
*
* @param $lang String
*/
static function set_default_lang($lang) {
Translatable::set_default_lang($lang);
}
/**
* Get default language (proxy for Translatable::default_lang())
*
* @return String
*/
static function default_lang() {
return Translatable::default_lang();
}
/** /**
* Include a locale file determined by module name and locale * Include a locale file determined by module name and locale