diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2016-01-15 10:04:41 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2016-01-26 14:02:30 +0100 |
commit | 6aec550d6efb1cb50f6404bf72eb78ea37f36266 (patch) | |
tree | ec61ca3cc962acd8081323cd419dd97921c615f4 /lib/private | |
parent | 3da78c8f1c9355a726f289e834fa237366c3df20 (diff) | |
download | nextcloud-server-6aec550d6efb1cb50f6404bf72eb78ea37f36266.tar.gz nextcloud-server-6aec550d6efb1cb50f6404bf72eb78ea37f36266.zip |
Move findAvailableLanguages() to the factory
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/l10n.php | 20 | ||||
-rw-r--r-- | lib/private/l10n/factory.php | 56 |
2 files changed, 57 insertions, 19 deletions
diff --git a/lib/private/l10n.php b/lib/private/l10n.php index b53fadc2bdd..aa19102b70c 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -452,26 +452,10 @@ class OC_L10N implements \OCP\IL10N { * find all available languages for an app * @param string $app App that needs to be translated * @return array an array of available languages + * @deprecated 9.0.0 Use \OC::$server->getL10NFactory()->findAvailableLanguages() instead */ public static function findAvailableLanguages($app=null) { - // also works with null as key - if(isset(self::$availableLanguages[$app]) && !empty(self::$availableLanguages[$app])) { - return self::$availableLanguages[$app]; - } - $available=array('en');//english is always available - $dir = self::findI18nDir($app); - if(is_dir($dir)) { - $files=scandir($dir); - foreach($files as $file) { - if(substr($file, -5, 5) === '.json' && substr($file, 0, 4) !== 'l10n') { - $i = substr($file, 0, -5); - $available[] = $i; - } - } - } - - self::$availableLanguages[$app] = $available; - return $available; + return \OC::$server->getL10NFactory()->findAvailableLanguages($app); } /** diff --git a/lib/private/l10n/factory.php b/lib/private/l10n/factory.php index c3c7cc21bba..aaa41f5e645 100644 --- a/lib/private/l10n/factory.php +++ b/lib/private/l10n/factory.php @@ -33,8 +33,11 @@ use OCP\L10N\IFactory; class Factory implements IFactory { /** * cached instances + * @var array Structure: Lang => App => \OCP\IL10N */ - protected $instances = array(); + protected $instances = []; + + protected $availableLanguages = []; /** * Get a language instance @@ -56,4 +59,55 @@ class Factory implements IFactory { return $this->instances[$key][$app]; } + /** + * Find all available languages for an app + * + * @param string|null $app App id or null for core + * @return array an array of available languages + */ + public function findAvailableLanguages($app = null) { + $key = $app; + if ($key === null) { + $key = 'null'; + } + + // also works with null as key + if (!empty($this->availableLanguages[$key])) { + return $this->availableLanguages[$key]; + } + + $available = ['en']; //english is always available + $dir = $this->findL10nDir($app); + if (is_dir($dir)) { + $files = scandir($dir); + if ($files !== false) { + foreach ($files as $file) { + if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { + $available[] = substr($file, 0, -5); + } + } + } + } + + $this->availableLanguages[$key] = $available; + return $available; + } + + /** + * find the l10n directory + * + * @param string $app App id or empty string for core + * @return string directory + */ + protected function findL10nDir($app = '') { + if ($app !== '') { + // Check if the app is in the app folder + if (file_exists(\OC_App::getAppPath($app) . '/l10n/')) { + return \OC_App::getAppPath($app) . '/l10n/'; + } else { + return \OC::$SERVERROOT . '/' . $app . '/l10n/'; + } + } + return \OC::$SERVERROOT.'/core/l10n/'; + } } |