From 23b18afa73a4c28f765abdda0b8322dd9c1c15e3 Mon Sep 17 00:00:00 2001 From: Ere Maijala <ere.maijala@helsinki.fi> Date: Wed, 10 Sep 2014 17:08:50 +0300 Subject: [PATCH] Added language fallback to 'en' in addition to the existing default language. --- .../I18n/Translator/Loader/ExtendedIni.php | 31 +++++++++++-------- module/VuFind/src/VuFind/Service/Factory.php | 5 ++- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/module/VuFind/src/VuFind/I18n/Translator/Loader/ExtendedIni.php b/module/VuFind/src/VuFind/I18n/Translator/Loader/ExtendedIni.php index 4c6f922b7cc..ad9e7f6c0fd 100644 --- a/module/VuFind/src/VuFind/I18n/Translator/Loader/ExtendedIni.php +++ b/module/VuFind/src/VuFind/I18n/Translator/Loader/ExtendedIni.php @@ -49,11 +49,11 @@ class ExtendedIni implements FileLoaderInterface protected $pathStack; /** - * Fallback locale to use for language strings missing from selected file. + * Fallback locales to use for language strings missing from selected file. * - * @var string + * @var string[] */ - protected $fallbackLocale; + protected $fallbackLocales; /** * List of files loaded during the current run -- avoids infinite loops and @@ -66,15 +66,18 @@ class ExtendedIni implements FileLoaderInterface /** * Constructor * - * @param array $pathStack List of directories to search for language - * files. - * @param string $fallbackLocale Fallback locale to use for language strings - * missing from selected file. + * @param array $pathStack List of directories to search for + * language files. + * @param string|string[] $fallbackLocales Fallback locale(s) to use for language + * strings missing from selected file. */ - public function __construct($pathStack = array(), $fallbackLocale = null) + public function __construct($pathStack = array(), $fallbackLocales = null) { $this->pathStack = $pathStack; - $this->fallbackLocale = $fallbackLocale; + $this->fallbackLocales = $fallbackLocales; + if (!empty($this->fallbackLocales) && !is_array($this->fallbackLocales)) { + $this->fallbackLocales = array($this->fallbackLocales); + } } /** @@ -96,10 +99,12 @@ class ExtendedIni implements FileLoaderInterface $data = $this->loadLanguageFile($locale . '.ini'); // Load fallback data, if any: - if (!empty($this->fallbackLocale)) { - $newData = $this->loadLanguageFile($this->fallbackLocale . '.ini'); - $newData->merge($data); - $data = $newData; + if (!empty($this->fallbackLocales)) { + foreach ($this->fallbackLocales as $fallbackLocale) { + $newData = $this->loadLanguageFile($fallbackLocale . '.ini'); + $newData->merge($data); + $data = $newData; + } } return $data; diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php index fb8f70f5e98..d21a0a64d16 100644 --- a/module/VuFind/src/VuFind/Service/Factory.php +++ b/module/VuFind/src/VuFind/Service/Factory.php @@ -433,10 +433,13 @@ class Factory APPLICATION_PATH . '/languages', LOCAL_OVERRIDE_DIR . '/languages' ); + $fallbackLocales = $config->Site->language == 'en' + ? 'en' + : array($config->Site->language, 'en'); $translator->getPluginManager()->setService( 'extendedini', new \VuFind\I18n\Translator\Loader\ExtendedIni( - $pathStack, $config->Site->language + $pathStack, $fallbackLocales ) ); -- GitLab