Skip to content
Snippets Groups Projects
Commit cac7c090 authored by Demian Katz's avatar Demian Katz
Browse files

Made translation logic smarter about missing intl extension.

parent 3590c0f2
No related merge requests found
...@@ -322,10 +322,18 @@ class Bootstrapper ...@@ -322,10 +322,18 @@ class Bootstrapper
} }
$sm = $event->getApplication()->getServiceManager(); $sm = $event->getApplication()->getServiceManager();
$sm->get('VuFind\Translator') try {
->addTranslationFile('ExtendedIni', null, 'default', $language) $sm->get('VuFind\Translator')
->setLocale($language); ->addTranslationFile('ExtendedIni', null, 'default', $language)
->setLocale($language);
} catch (\Zend\Mvc\Exception\BadMethodCallException $e) {
if (!extension_loaded('intl')) {
throw new \Exception(
'Translation broken due to missing PHP intl extension.'
. ' Please disable translation or install the extension.'
);
}
}
// Send key values to view: // Send key values to view:
$viewModel = $sm->get('viewmanager')->getViewModel(); $viewModel = $sm->get('viewmanager')->getViewModel();
$viewModel->setVariable('userLang', $language); $viewModel->setVariable('userLang', $language);
......
...@@ -739,7 +739,15 @@ class Factory ...@@ -739,7 +739,15 @@ class Factory
$fallbackLocales = $config->Site->language == 'en' $fallbackLocales = $config->Site->language == 'en'
? 'en' ? 'en'
: array($config->Site->language, 'en'); : array($config->Site->language, 'en');
$translator->getPluginManager()->setService( try {
$pm = $translator->getPluginManager();
} catch (\Zend\Mvc\Exception\BadMethodCallException $ex) {
// If getPluginManager is missing, this means that the user has
// disabled translation in module.config.php or PHP's intl extension
// is missing. We can do no further configuration of the object.
return $translator;
}
$pm->setService(
'extendedini', 'extendedini',
new \VuFind\I18n\Translator\Loader\ExtendedIni( new \VuFind\I18n\Translator\Loader\ExtendedIni(
$pathStack, $fallbackLocales $pathStack, $fallbackLocales
......
...@@ -56,12 +56,21 @@ class DisplayLanguageOption extends \Zend\View\Helper\AbstractHelper ...@@ -56,12 +56,21 @@ class DisplayLanguageOption extends \Zend\View\Helper\AbstractHelper
// Clone the translator; we need to switch language for the purposes // Clone the translator; we need to switch language for the purposes
// of this plugin, but we don't want that change to happen globally. // of this plugin, but we don't want that change to happen globally.
$this->translator = clone($translator); $this->translator = clone($translator);
$this->translator->addTranslationFile( try {
'ExtendedIni', $this->translator->addTranslationFile(
APPLICATION_PATH . '/languages/native.ini', 'ExtendedIni',
'default', 'native' APPLICATION_PATH . '/languages/native.ini',
); 'default', 'native'
$this->translator->setLocale('native'); );
$this->translator->setLocale('native');
} catch (\Zend\Mvc\Exception\BadMethodCallException $e) {
if (!extension_loaded('intl')) {
throw new \Exception(
'Translation broken due to missing PHP intl extension.'
. ' Please disable translation or install the extension.'
);
}
}
} }
/** /**
......
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