aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2016-01-15 11:25:35 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2016-01-26 14:02:31 +0100
commit7ec7464ee249f15d377a44c1b8b23e127e07385e (patch)
tree95a39bdd668a183ca2fca388d1cafae5ea164b86
parent043625ee522357e25bb786c4b439c90ab21bbfd1 (diff)
downloadnextcloud-server-7ec7464ee249f15d377a44c1b8b23e127e07385e.tar.gz
nextcloud-server-7ec7464ee249f15d377a44c1b8b23e127e07385e.zip
Move validation and fallbacks of app and lang to the constructor/factory
-rw-r--r--lib/private/l10n.php30
-rw-r--r--lib/private/l10n/factory.php7
2 files changed, 23 insertions, 14 deletions
diff --git a/lib/private/l10n.php b/lib/private/l10n.php
index 43e1121b983..4405491cb78 100644
--- a/lib/private/l10n.php
+++ b/lib/private/l10n.php
@@ -82,9 +82,21 @@ class OC_L10N implements \OCP\IL10N {
*
* If language is not set, the constructor tries to find the right
* language.
+ * @deprecated 9.0.0 Use \OC::$server->getL10NFactory()->get() instead
*/
public function __construct($app, $lang = null) {
+ $app = \OC_App::cleanAppId($app);
$this->app = $app;
+
+ if ($lang !== null) {
+ $lang = str_replace(array('\0', '/', '\\', '..'), '', $lang);
+ }
+
+ // Find the right language
+ if (!\OC::$server->getL10NFactory()->languageExists($app, $lang)) {
+ $lang = \OC::$server->getL10NFactory()->findLanguage($app);
+ }
+
$this->lang = $lang;
}
@@ -119,13 +131,9 @@ class OC_L10N implements \OCP\IL10N {
if ($this->app === true) {
return;
}
- $app = OC_App::cleanAppId($this->app);
- $lang = str_replace(array('\0', '/', '\\', '..'), '', $this->lang);
+ $app = $this->app;
+ $lang = $this->lang;
$this->app = true;
- // Find the right language
- if(is_null($lang) || $lang == '') {
- $lang = self::findLanguage($app);
- }
// Use cache if possible
if(array_key_exists($app.'::'.$lang, self::$cache)) {
@@ -323,12 +331,8 @@ class OC_L10N implements \OCP\IL10N {
$value->setTimestamp($data);
}
- // Use the language of the instance, before falling back to the current user's language
- $locale = $this->lang;
- if ($locale === null) {
- $locale = self::findLanguage();
- }
- $locale = $this->transformToCLDRLocale($locale);
+ // Use the language of the instance
+ $locale = $this->transformToCLDRLocale($this->getLanguageCode());
$options = array_merge(array('width' => 'long'), $options);
$width = $options['width'];
@@ -350,7 +354,7 @@ class OC_L10N implements \OCP\IL10N {
* @return string language
*/
public function getLanguageCode() {
- return $this->lang ? $this->lang : self::findLanguage();
+ return $this->lang;
}
/**
diff --git a/lib/private/l10n/factory.php b/lib/private/l10n/factory.php
index ecc2318893a..39d69c81935 100644
--- a/lib/private/l10n/factory.php
+++ b/lib/private/l10n/factory.php
@@ -71,9 +71,14 @@ class Factory implements IFactory {
* @return \OCP\IL10N
*/
public function get($app, $lang = null) {
+ $app = \OC_App::cleanAppId($app);
+ if ($lang !== null) {
+ $lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang);
+ }
$key = $lang;
- if ($key === null) {
+ if ($key === null || !$this->languageExists($app, $lang)) {
$key = 'null';
+ $lang = $this->findLanguage($app);
}
if (!isset($this->instances[$key][$app])) {