From 29a93064299f57584c6aadc8a6c56b51715d7269 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 15 Jan 2016 10:27:09 +0100 Subject: [PATCH] Move languageExists() to the factory --- lib/private/l10n.php | 10 ++-------- lib/private/l10n/factory.php | 17 +++++++++++++++++ lib/public/l10n/ifactory.php | 8 ++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/private/l10n.php b/lib/private/l10n.php index aa19102b70..085914a68b 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -462,16 +462,10 @@ class OC_L10N implements \OCP\IL10N { * @param string $app * @param string $lang * @return bool + * @deprecated 9.0.0 Use \OC::$server->getL10NFactory()->languageExists() instead */ 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.'.json'); - } - return false; + return \OC::$server->getL10NFactory()->languageExists($app, $lang); } /** diff --git a/lib/private/l10n/factory.php b/lib/private/l10n/factory.php index aaa41f5e64..b130472760 100644 --- a/lib/private/l10n/factory.php +++ b/lib/private/l10n/factory.php @@ -37,6 +37,9 @@ class Factory implements IFactory { */ protected $instances = []; + /** + * @var array Structure: App => string[] + */ protected $availableLanguages = []; /** @@ -93,6 +96,20 @@ class Factory implements IFactory { return $available; } + /** + * @param string|null $app App id or null for core + * @param string $lang + * @return bool + */ + public function languageExists($app, $lang) { + if ($lang === 'en') {//english is always available + return true; + } + + $languages = $this->findAvailableLanguages($app); + return array_search($lang, $languages); + } + /** * find the l10n directory * diff --git a/lib/public/l10n/ifactory.php b/lib/public/l10n/ifactory.php index d6944b375f..09c75e9af7 100644 --- a/lib/public/l10n/ifactory.php +++ b/lib/public/l10n/ifactory.php @@ -42,4 +42,12 @@ interface IFactory { * @since 9.0.0 */ public function findAvailableLanguages($app = null); + + /** + * @param string|null $app App id or null for core + * @param string $lang + * @return bool + * @since 9.0.0 + */ + public function languageExists($app, $lang); }