Move languageExists() to the factory

This commit is contained in:
Joas Schilling 2016-01-15 10:27:09 +01:00
parent 6aec550d6e
commit 29a9306429
3 changed files with 27 additions and 8 deletions

View File

@ -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);
}
/**

View File

@ -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
*

View File

@ -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);
}