/**
  * Process an incoming request and/or response.
  *
  * Accepts a server-side request and a response instance, and does
  * something with them.
  *
  * If the response is not complete and/or further processing would not
  * interfere with the work done in the middleware, or if the middleware
  * wants to delegate to another process, it can use the `$out` callable
  * if present.
  *
  * If the middleware does not return a value, execution of the current
  * request is considered complete, and the response instance provided will
  * be considered the response to return.
  *
  * Alternately, the middleware may return a response instance.
  *
  * Often, middleware will `return $out();`, with the assumption that a
  * later middleware will return a response.
  *
  * @param Request $request
  * @param Response $response
  * @param null|callable $out
  * @return null|Response
  */
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     $matchedRoute = $this->router->match($request);
     $params = $matchedRoute->getMatchedParams();
     // Determine the language to use based on the lang parameter
     $lang = isset($params['lang']) ? $params['lang'] : 'en';
     $this->translator->setLocale($lang);
     return $out($request, $response);
 }
Beispiel #2
0
 /**
  * Constructor
  *
  * @param TranslatorInterface $translator Main VuFind translator
  */
 public function __construct(TranslatorInterface $translator)
 {
     $this->translator = $translator;
     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.');
         }
     }
 }
 public function __construct(AdapterInterface $adapter = null)
 {
     if (null === $adapter) {
         $adapter = new StaticAdapter();
     }
     $this->adapter = $adapter;
     // Translator
     $this->translator = new Translator();
     $this->translator->setLocale('en');
     $this->translator->setFallbackLocale('en');
     $this->translator->addTranslationFilePattern('gettext', dirname(__DIR__) . '/language/', '%s.mo', $this->translatorTextDomain);
 }
 /**
  * Constructor
  *
  * @param TranslatorInterface $translator Main VuFind translator
  */
 public function __construct(TranslatorInterface $translator)
 {
     // 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;
     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.');
         }
     }
 }
 /**
  * Constructor.
  */
 public function __construct()
 {
     $this->continents = array('AF' => new Continent('AF', 'Africa'), 'AN' => new Continent('AN', 'Antarctica'), 'AS' => new Continent('AS', 'Asia'), 'EU' => new Continent('EU', 'Europe'), 'NA' => new Continent('NA', 'North america'), 'OC' => new Continent('OC', 'Oceania'), 'SA' => new Continent('SA', 'South america'));
     if (null !== $this->countryManager) {
         foreach ($this->continents as $continent) {
             if ($continent instanceof CountryManagerAwareInterface) {
                 $country->setCountryManager($countryManager);
             }
         }
     }
     // Translator
     $this->translator = new Translator();
     $this->translator->setLocale('en_US');
     $this->translator->setFallbackLocale('en_US');
     $this->translator->addTranslationFilePattern('gettext', dirname(__DIR__) . '/language/continent/', '%s.mo', $this->translatorTextDomain);
 }