Skip to content
Snippets Groups Projects
Commit 23b18afa authored by Ere Maijala's avatar Ere Maijala
Browse files

Added language fallback to 'en' in addition to the existing default language.

parent 5ebb022a
Branches
Tags
No related merge requests found
...@@ -49,11 +49,11 @@ class ExtendedIni implements FileLoaderInterface ...@@ -49,11 +49,11 @@ class ExtendedIni implements FileLoaderInterface
protected $pathStack; 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 * List of files loaded during the current run -- avoids infinite loops and
...@@ -66,15 +66,18 @@ class ExtendedIni implements FileLoaderInterface ...@@ -66,15 +66,18 @@ class ExtendedIni implements FileLoaderInterface
/** /**
* Constructor * Constructor
* *
* @param array $pathStack List of directories to search for language * @param array $pathStack List of directories to search for
* files. * language files.
* @param string $fallbackLocale Fallback locale to use for language strings * @param string|string[] $fallbackLocales Fallback locale(s) to use for language
* missing from selected file. * strings missing from selected file.
*/ */
public function __construct($pathStack = array(), $fallbackLocale = null) public function __construct($pathStack = array(), $fallbackLocales = null)
{ {
$this->pathStack = $pathStack; $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 ...@@ -96,10 +99,12 @@ class ExtendedIni implements FileLoaderInterface
$data = $this->loadLanguageFile($locale . '.ini'); $data = $this->loadLanguageFile($locale . '.ini');
// Load fallback data, if any: // Load fallback data, if any:
if (!empty($this->fallbackLocale)) { if (!empty($this->fallbackLocales)) {
$newData = $this->loadLanguageFile($this->fallbackLocale . '.ini'); foreach ($this->fallbackLocales as $fallbackLocale) {
$newData->merge($data); $newData = $this->loadLanguageFile($fallbackLocale . '.ini');
$data = $newData; $newData->merge($data);
$data = $newData;
}
} }
return $data; return $data;
......
...@@ -433,10 +433,13 @@ class Factory ...@@ -433,10 +433,13 @@ class Factory
APPLICATION_PATH . '/languages', APPLICATION_PATH . '/languages',
LOCAL_OVERRIDE_DIR . '/languages' LOCAL_OVERRIDE_DIR . '/languages'
); );
$fallbackLocales = $config->Site->language == 'en'
? 'en'
: array($config->Site->language, 'en');
$translator->getPluginManager()->setService( $translator->getPluginManager()->setService(
'extendedini', 'extendedini',
new \VuFind\I18n\Translator\Loader\ExtendedIni( new \VuFind\I18n\Translator\Loader\ExtendedIni(
$pathStack, $config->Site->language $pathStack, $fallbackLocales
) )
); );
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment