diff options
author | Brice Maron <brice@bmaron.net> | 2012-06-21 17:15:35 +0000 |
---|---|---|
committer | Brice Maron <brice@bmaron.net> | 2012-06-21 17:15:35 +0000 |
commit | e5c56b2433b1987e4b6b8020e01f4da03623c4b8 (patch) | |
tree | a650870f7bbc497833b8ea00051f9046e1779f5e /lib/l10n.php | |
parent | df83df5263db57056d0bd70edfa3b28e7b5e6b6b (diff) | |
parent | 6707e4187e4c1186eff8dfe06999c4539ab80de7 (diff) | |
download | nextcloud-server-e5c56b2433b1987e4b6b8020e01f4da03623c4b8.tar.gz nextcloud-server-e5c56b2433b1987e4b6b8020e01f4da03623c4b8.zip |
Merge branch 'master' into multi_app_dir
Conflicts:
lib/app.php
lib/base.php
lib/minimizer/css.php
lib/minimizer/js.php
lib/template.php
lib/util.php
Diffstat (limited to 'lib/l10n.php')
-rw-r--r-- | lib/l10n.php | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/lib/l10n.php b/lib/l10n.php index 887652e2b85..4acbc5dcebc 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -40,6 +40,16 @@ class OC_L10N{ protected static $language = ''; /** + * App of this object + */ + protected $app; + + /** + * Language of this object + */ + protected $lang; + + /** * Translations */ private $translations = array(); @@ -77,10 +87,17 @@ class OC_L10N{ * language. */ public function __construct($app, $lang = null){ - $this->init($app, $lang); + $this->app = $app; + $this->lang = $lang; } - protected function init($app, $lang = null){ + protected function init(){ + if ($this->app === true) { + return; + } + $app = $this->app; + $lang = $this->lang; + $this->app = true; // Find the right language if(is_null($lang)){ $lang = self::findLanguage($app); @@ -127,10 +144,7 @@ class OC_L10N{ * returned. */ public function t($text, $parameters = array()){ - if(array_key_exists($text, $this->translations)){ - return vsprintf($this->translations[$text], $parameters); - } - return vsprintf($text, $parameters); + return new OC_L10N_String($this, $text, $parameters); } /** @@ -144,7 +158,7 @@ class OC_L10N{ public function tA($textArray){ $result = array(); foreach($textArray as $key => $text){ - $result[$key] = $this->t($text); + $result[$key] = (string)$this->t($text); } return $result; } @@ -156,6 +170,7 @@ class OC_L10N{ * Returns an associative array with all translations */ public function getTranslations(){ + $this->init(); return $this->translations; } @@ -182,6 +197,7 @@ class OC_L10N{ * - params: timestamp (int/string) */ public function l($type, $data){ + $this->init(); switch($type){ // If you add something don't forget to add it to $localizations // at the top of the page @@ -228,23 +244,29 @@ class OC_L10N{ return self::$language; } - $available = array(); - if(is_array($app)){ - $available = $app; - } - else{ - $available=self::findAvailableLanguages($app); - } if(OC_User::getUser() && OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang')){ $lang = OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang'); self::$language = $lang; - if(array_search($lang, $available) !== false){ + if(is_array($app)){ + $available = $app; + $lang_exists = array_search($lang, $available) !== false; + } + else { + $lang_exists = self::languageExists($app, $lang); + } + if($lang_exists){ return $lang; } } if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){ $accepted_languages = preg_split('/,\s*/', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + if(is_array($app)){ + $available = $app; + } + else{ + $available = self::findAvailableLanguages($app); + } foreach($accepted_languages as $i){ $temp = explode(';', $i); if(array_search($temp[0], $available) !== false){ @@ -296,4 +318,15 @@ class OC_L10N{ } return $available; } + + public static function languageExists($app, $lang){ + if ($lang == 'en'){//english is always available + return true; + } + $dir = self::findI18nDir($app); + if(is_dir($dir)){ + return file_exists($dir.'/'.$lang.'.php'); + } + return false; + } } |