diff options
author | Georg Ehrke <developer@georgehrke.com> | 2018-06-27 19:43:46 +0200 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2018-06-27 21:52:19 +0200 |
commit | b3921c65a68111aa319e75f546953f77ebd8008f (patch) | |
tree | c737f919819c6a60ebbf06316aedcd23fb35848a /lib | |
parent | 51a35c23f6fcaff85be8e5785447092e2b982681 (diff) | |
download | nextcloud-server-b3921c65a68111aa319e75f546953f77ebd8008f.tar.gz nextcloud-server-b3921c65a68111aa319e75f546953f77ebd8008f.zip |
cache available locales to minimize fs access
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/L10N/Factory.php | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index 8c35d75a4b5..6d6f452738c 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -55,6 +55,11 @@ class Factory implements IFactory { protected $availableLanguages = []; /** + * @var array + */ + protected $availableLocales = []; + + /** * @var array Structure: string => callable */ protected $pluralFunctions = []; @@ -195,8 +200,13 @@ class Factory implements IFactory { return 'en'; } - public function findLocale($lang = null) - { + /** + * find the best locale + * + * @param string $lang + * @return null|string + */ + public function findLocale($lang = null) { if ($this->config->getSystemValue('installed', false)) { $userId = null !== $this->userSession->getUser() ? $this->userSession->getUser()->getUID() : null; $userLocale = null; @@ -278,10 +288,18 @@ class Factory implements IFactory { return $available; } - public function findAvailableLocales() - { + /** + * @return array|mixed + */ + public function findAvailableLocales() { + if (!empty($this->availableLocales)) { + return $this->availableLocales; + } + $localeData = file_get_contents(__DIR__ . '/locales.json'); - return json_decode($localeData, true); + $this->availableLocales = \json_decode($localeData, true); + + return $this->availableLocales; } /** @@ -308,7 +326,6 @@ class Factory implements IFactory { } $locales = $this->findAvailableLocales(); - $userLocale = array_filter($locales, function($value) use ($locale) { return $locale === $value['code']; }); |