diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-08-29 16:44:08 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-08-29 16:44:08 +0200 |
commit | 723f8c8f1ba8c9859ec2d46515dc06e7236f89c0 (patch) | |
tree | 5cff022dc72e1a8511545888e489efef6dd21344 /lib/private | |
parent | faa62d17993b9467f0041cbca2cafccdcb243385 (diff) | |
parent | 37b00b7443bec09aac84b359a1c2f77caf143b30 (diff) | |
download | nextcloud-server-723f8c8f1ba8c9859ec2d46515dc06e7236f89c0.tar.gz nextcloud-server-723f8c8f1ba8c9859ec2d46515dc06e7236f89c0.zip |
Merge pull request #18620 from owncloud/add-public-interface-for-factory
Add a public interface for the language factory so apps can use it
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/l10n.php | 9 | ||||
-rw-r--r-- | lib/private/l10n/factory.php | 24 | ||||
-rw-r--r-- | lib/private/server.php | 9 |
3 files changed, 26 insertions, 16 deletions
diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 17acaac1692..168011cfcec 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -81,14 +81,11 @@ class OC_L10N implements \OCP\IL10N { * get an L10N instance * @param string $app * @param string|null $lang - * @return \OC_L10N + * @return \OCP\IL10N + * @deprecated Use \OC::$server->getL10NFactory()->get() instead */ public static function get($app, $lang=null) { - if (is_null($lang)) { - return OC::$server->getL10N($app); - } else { - return new \OC_L10N($app, $lang); - } + return \OC::$server->getL10NFactory()->get($app, $lang); } /** diff --git a/lib/private/l10n/factory.php b/lib/private/l10n/factory.php index 4424d014f47..a9ac4da42a2 100644 --- a/lib/private/l10n/factory.php +++ b/lib/private/l10n/factory.php @@ -25,29 +25,35 @@ namespace OC\L10N; +use OCP\L10N\IFactory; + /** - * TODO: Description + * A factory that generates language instances */ -class Factory { +class Factory implements IFactory { /** * cached instances */ protected $instances = array(); /** - * get an L10N instance + * Get a language instance * * @param string $app * @param string|null $lang - * @return \OC_L10N + * @return \OCP\IL10N */ public function get($app, $lang = null) { - if (!is_null($lang)) { - return new \OC_L10N($app, $lang); - } else if (!isset($this->instances[$app])) { - $this->instances[$app] = new \OC_L10N($app); + $key = $lang; + if ($key === null) { + $key = 'null'; + } + + if (!isset($this->instances[$key][$app])) { + $this->instances[$key][$app] = new \OC_L10N($app, $lang); } - return $this->instances[$app]; + + return $this->instances[$key][$app]; } } diff --git a/lib/private/server.php b/lib/private/server.php index 287b70eb806..a47fa2e43f9 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -674,6 +674,13 @@ class Server extends SimpleContainer implements IServerContainer { } /** + * @return \OCP\L10N\IFactory + */ + public function getL10NFactory() { + return $this->query('L10NFactory'); + } + + /** * get an L10N instance * * @param string $app appid @@ -681,7 +688,7 @@ class Server extends SimpleContainer implements IServerContainer { * @return \OC_L10N */ public function getL10N($app, $lang = null) { - return $this->query('L10NFactory')->get($app, $lang); + return $this->getL10NFactory()->get($app, $lang); } /** |