diff --git a/module/VuFind/src/VuFind/Bootstrapper.php b/module/VuFind/src/VuFind/Bootstrapper.php index d5b6f4e78d09dc31363acf494e9025b1e16c2693..f43f8fe6fb3599526d9054db737da86ca8e8872d 100644 --- a/module/VuFind/src/VuFind/Bootstrapper.php +++ b/module/VuFind/src/VuFind/Bootstrapper.php @@ -322,10 +322,18 @@ class Bootstrapper } $sm = $event->getApplication()->getServiceManager(); - $sm->get('VuFind\Translator') - ->addTranslationFile('ExtendedIni', null, 'default', $language) - ->setLocale($language); - + try { + $sm->get('VuFind\Translator') + ->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: $viewModel = $sm->get('viewmanager')->getViewModel(); $viewModel->setVariable('userLang', $language); diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php index 1982865785bbc900f5339c73a8c6b60c81ff05ff..72ca05e285ec9ce7fb219d07fe143601ab131bea 100644 --- a/module/VuFind/src/VuFind/Service/Factory.php +++ b/module/VuFind/src/VuFind/Service/Factory.php @@ -739,7 +739,15 @@ class Factory $fallbackLocales = $config->Site->language == 'en' ? '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', new \VuFind\I18n\Translator\Loader\ExtendedIni( $pathStack, $fallbackLocales diff --git a/module/VuFind/src/VuFind/View/Helper/Root/DisplayLanguageOption.php b/module/VuFind/src/VuFind/View/Helper/Root/DisplayLanguageOption.php index b552f55c062f878344642fba17d3e96864805060..adea7d7d75fcbbdd3f6c9d76d038817e9b0d0980 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/DisplayLanguageOption.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/DisplayLanguageOption.php @@ -56,12 +56,21 @@ class DisplayLanguageOption extends \Zend\View\Helper\AbstractHelper // Clone the translator; we need to switch language for the purposes // of this plugin, but we don't want that change to happen globally. $this->translator = clone($translator); - $this->translator->addTranslationFile( - 'ExtendedIni', - APPLICATION_PATH . '/languages/native.ini', - 'default', 'native' - ); - $this->translator->setLocale('native'); + try { + $this->translator->addTranslationFile( + 'ExtendedIni', + APPLICATION_PATH . '/languages/native.ini', + 'default', '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.' + ); + } + } } /**