コード例 #1
0
 /** {@inheritdoc} */
 public function __invoke(\Interop\Container\ContainerInterface $container, $name, callable $callback, array $options = null)
 {
     $locale = \Locale::getDefault();
     $primaryLanguage = \Locale::getPrimaryLanguage($locale);
     $mvcTranslator = $callback();
     $mvcTranslator->setPluginManager($container->get('TranslatorPluginManager'));
     $translator = $mvcTranslator->getTranslator();
     // Set language
     $translator->setLocale($locale);
     if ($primaryLanguage != $locale) {
         // Set primary language as fallback, i.e. "de" if locale is "de_DE".
         // This enables translation file patterns for "de" to match all
         // variants.
         $translator->setFallbackLocale($primaryLanguage);
     }
     // Load translations for ZF validator messages
     $translator->addTranslationFilePattern('phparray', \Zend\I18n\Translator\Resources::getBasePath(), \Zend\I18n\Translator\Resources::getPatternForValidator());
     // Set up event listener for missing translations
     if ($primaryLanguage != 'en') {
         $config = $container->get('Library\\UserConfig');
         if (@$config['debug']['report missing translations']) {
             $translator->enableEventManager();
             $translator->getEventManager()->attach(\Zend\I18n\Translator\Translator::EVENT_MISSING_TRANSLATION, array($this, 'onMissingTranslation'));
         }
     }
     return $mvcTranslator;
 }
コード例 #2
0
 public function createDelegatorWithName(ServiceLocatorInterface $services, $name, $requestedName, $callback)
 {
     $translator = $callback();
     $translator->addTranslationFilePattern('phpArray', Resources::getBasePath(), Resources::getPatternForValidator(), 'myApp');
     $translator->addTranslationFilePattern('gettext', Resources::getBasePath(), '%s.mo');
     return $translator;
 }
コード例 #3
0
 public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null)
 {
     $translator = $callback();
     $translator->addTranslationFilePattern(PhpArray::class, Resources::getBasePath(), Resources::getPatternForValidator());
     $translator->addTranslationFilePattern(PhpArray::class, Resources::getBasePath(), Resources::getPatternForCaptcha());
     AbstractValidator::setDefaultTranslator($translator);
     return $translator;
 }
 public function createDelegatorWithName(ServiceLocatorInterface $services, $name, $requestedName, $callback)
 {
     $translator = $callback();
     /* @var $translator \Zend\Mvc\I18n\Translator */
     $translator->addTranslationFilePattern('phpArray', Resources::getBasePath(), Resources::getPatternForValidator());
     $translator->addTranslationFilePattern('phpArray', Resources::getBasePath(), Resources::getPatternForCaptcha());
     return $translator;
 }
コード例 #5
0
 /**
  * @param string $locale
  * @param string $fallbackLocale
  * @return string|null
  */
 protected function getLanguageDirectoryName($locale, $fallbackLocale = null)
 {
     $basePath = Resources::getBasePath() . $locale;
     if (is_dir($basePath)) {
         return $locale;
     }
     $lang = Locale::getPrimaryLanguage($locale);
     $basePath = Resources::getBasePath() . $lang;
     if (!is_dir($basePath)) {
         if ($fallbackLocale) {
             return $this->getLanguageDirectoryName($fallbackLocale);
         }
     } else {
         return $lang;
     }
 }