php Zend-I18n-Translator-Translator类(方法)实例源码

下面列出了php Zend-I18n-Translator-Translator 类(方法)源码代码实例,从而了解它的用法。

作者:cyantre    项目:grout-translator-modul   
public function init()
 {
     $this->app->configs->setDefaultConfig($this->id, new TranslatorConfig(), $this);
     $this->translator = $translator = new Translator();
     /** @var TranslatorConfig $config */
     $this->moduleConfig = $config = $this->app->configs->getConfig($this->id);
     if (!$this->app->getConfig()->developmentMode) {
         $c = new Filesystem();
         $o = new FilesystemOptions();
         $o->setCacheDir($this->app->cacheStorage->createStorage($this->id));
         $c->setOptions($o);
         $c->addPlugin(new Serializer());
         $translator->setCache($c);
     }
     $translator->setLocale($config->defaultLanguage);
     $folder = $this->app->parseUri($config->translationsDirectory);
     foreach ($config->contexts as $context => $file) {
         if (is_int($context)) {
             $context = $file;
             $file .= '.mo';
         }
         $translator->addTranslationFilePattern('gettext', $folder, '%s/' . $file, $context);
     }
     $this->translator = $translator;
 }

作者:navassouz    项目:zf   
/**
  * Translate a plural message.
  *
  * @param  string  $singular
  * @param  string  $plural
  * @param  integer $number
  * @param  string  $textDomain
  * @param  string  $locale
  * @return string
  * @throws Exception\RuntimeException
  */
 public function __invoke($singular, $plural, $number, $textDomain = 'default', $locale = null)
 {
     if ($this->translator === null) {
         throw new Exception\RuntimeException('Translator has not been set');
     }
     return $this->translator->translatePlural($singular, $plural, $number, $textDomain, $locale);
 }

作者:zendframewor    项目:zend-mvc-i18   
public function setUp()
 {
     $this->testFilesDir = __DIR__ . '/../_files';
     $this->translator = new Translator();
     $this->translator->addTranslationFile('phparray', $this->testFilesDir . '/tokens.en.php', 'route', 'en');
     $this->translator->addTranslationFile('phparray', $this->testFilesDir . '/tokens.de.php', 'route', 'de');
     $this->fooRoute = ['type' => 'Segment', 'options' => ['route' => '/:locale'], 'child_routes' => ['index' => ['type' => 'Segment', 'options' => ['route' => '/{homepage}']]]];
 }

作者:citywar    项目:city-mv   
/**
  * @param $str
  * @param pt_BR $locale
  * @return string
  */
 public function __invoke($str, $locale = 'pt_BR', $typeTranslate = 'PhpArray', $pathFileTranslate = null)
 {
     $translator = new Translator();
     if (!empty($pathFileTranslate)) {
         $translator->addTranslationFile($typeTranslate, $pathFileTranslate, 'default', $locale);
     }
     return $translator->translate($str, $locale);
 }

作者:no-repl    项目:cbpl-vufin   
/**
  * Get translator object.
  *
  * @return \Zend\I18n\Translator\Translator
  */
 public function getTranslator()
 {
     if (null === $this->translator) {
         $this->translator = clone $this->getServiceLocator()->get('Translator');
         $this->translator->addTranslationFile('ExtendedIni', APPLICATION_PATH . '/languages/native.ini', 'default', 'native');
         $this->translator->setLocale('native');
     }
     return $this->translator;
 }

作者:spoore    项目:hangma   
public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $eventManager->attach(MvcEvent::EVENT_ROUTE, [$this, 'protectPage'], -100);
     $t = new I18nTranslator();
     $t->setLocale('de_DE');
     $translator = new Translator($t);
     $translator->addTranslationFile('phpArray', 'vendor/zendframework/zend-i18n-resources/languages/de/Zend_Validate.php', 'default', 'de_DE');
     AbstractValidator::setDefaultTranslator($translator);
 }

作者:ppiedaderawne    项目:concrete   
/**
  * {@inheritDoc}
  */
 public function createTranslatorAdapter($locale)
 {
     $cache = new ZendCacheDriver('cache/expensive');
     $t = new Translator();
     $t->setCache($cache);
     $adapter = new TranslatorAdapter($t);
     $adapter->setLocale($locale);
     if (isset($this->translationLoaderRepository)) {
         foreach ($this->translationLoaderRepository->getTranslationLoaders() as $key => $loader) {
             $loader->loadTranslations($adapter);
         }
     }
     return $adapter;
 }

作者:shlinki    项目:shlin   
public function setUp()
 {
     $command = new GenerateCharsetCommand(Translator::factory([]));
     $app = new Application();
     $app->add($command);
     $this->commandTester = new CommandTester($command);
 }

作者:JeoffScot    项目:dyplo   
/**
  * @param ServiceLocatorInterface $serviceLocator
  * @return MvcTranslator
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     // Assume that if a user has registered a service for the
     // TranslatorInterface, it must be valid
     if ($serviceLocator->has('Zend\\I18n\\Translator\\TranslatorInterface')) {
         return new MvcTranslator($serviceLocator->get('Zend\\I18n\\Translator\\TranslatorInterface'));
     }
     // If ext/intl is not loaded, return a dummy translator
     if (!extension_loaded('intl')) {
         return new MvcTranslator(new DummyTranslator());
     }
     // Load a translator from configuration, if possible
     if ($serviceLocator->has('Config')) {
         $config = $serviceLocator->get('Config');
         // 'translator' => false
         if (array_key_exists('translator', $config) && $config['translator'] === false) {
             return new MvcTranslator(new DummyTranslator());
         }
         // 'translator' => array( ... translator options ... )
         if (array_key_exists('translator', $config) && (is_array($config['translator']) && !empty($config['translator']) || $config['translator'] instanceof Traversable)) {
             $i18nTranslator = Translator::factory($config['translator']);
             $serviceLocator->setService('Zend\\I18n\\Translator\\TranslatorInterface', $i18nTranslator);
             return new MvcTranslator($i18nTranslator);
         }
     }
     // For BC purposes (pre-2.3.0), use the I18n Translator
     return new MvcTranslator(new Translator());
 }

作者:kukoma    项目:website-expressiv   
public function setUp()
 {
     $this->factory = new RendererFactory();
     $this->container = $this->prophesize(ContainerInterface::class);
     $this->container->get('translator')->willReturn(Translator::factory([]));
     $this->container->get('config')->willReturn(['navigation' => [], 'recaptcha' => []]);
     $this->container->get(RouteAssembler::class)->willReturn($this->prophesize(RouteAssembler::class)->reveal());
 }

作者:shlinki    项目:shlin   
public function setUp()
 {
     $this->urlShortener = $this->prophesize(UrlShortener::class);
     $command = new GenerateShortcodeCommand($this->urlShortener->reveal(), Translator::factory([]), ['schema' => 'http', 'hostname' => 'foo.com']);
     $app = new Application();
     $app->add($command);
     $this->commandTester = new CommandTester($command);
 }

作者:axelmde    项目:ecommerc   
/**
  * Create a Translator instance.
  *
  * @param ContainerInterface $container
  * @param string $requestedName
  * @param null|array $options
  * @return Translator
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     // Configure the translator
     $config = $container->get('config');
     $trConfig = isset($config['translator']) ? $config['translator'] : [];
     $translator = Translator::factory($trConfig);
     return $translator;
 }

作者:shlinki    项目:shlin   
public function setUp()
 {
     $this->visitsTracker = $this->prophesize(VisitsTrackerInterface::class);
     $command = new GetVisitsCommand($this->visitsTracker->reveal(), Translator::factory([]));
     $app = new Application();
     $app->add($command);
     $this->commandTester = new CommandTester($command);
 }

作者:shlinki    项目:shlin   
public function setUp()
 {
     $this->apiKeyService = $this->prophesize(ApiKeyService::class);
     $command = new ListKeysCommand($this->apiKeyService->reveal(), Translator::factory([]));
     $app = new Application();
     $app->add($command);
     $this->commandTester = new CommandTester($command);
 }

作者:kukoma    项目:website-expressiv   
public function testInvoke()
 {
     $sm = new ServiceManager();
     $sm->setService(Translator::class, Translator::factory([]));
     $sm->setService(RouterInterface::class, $this->prophesize(RouterInterface::class)->reveal());
     $instance = $this->factory->__invoke($sm);
     $this->assertInstanceOf(LanguageMiddleware::class, $instance);
 }

作者:shlinki    项目:shlin   
public function setUp()
 {
     $this->urlShortener = $this->prophesize(UrlShortener::class);
     $command = new ResolveUrlCommand($this->urlShortener->reveal(), Translator::factory([]));
     $app = new Application();
     $app->add($command);
     $this->commandTester = new CommandTester($command);
 }

作者:haoyanfe    项目:zf   
public function createService(ServiceLocatorInterface $serviceLocator)
 {
     // Configure the translator
     $config = $serviceLocator->get('Configuration');
     $trConfig = isset($config['translator']) ? $config['translator'] : array();
     $translator = Translator::factory($trConfig);
     return $translator;
 }

作者:shlinki    项目:shlin   
public function setUp()
 {
     $this->shortUrlService = $this->prophesize(ShortUrlServiceInterface::class);
     $app = new Application();
     $command = new ListShortcodesCommand($this->shortUrlService->reveal(), Translator::factory([]));
     $app->add($command);
     $this->questionHelper = $command->getHelper('question');
     $this->commandTester = new CommandTester($command);
 }

作者:acelay    项目:alejandrocelaya.co   
public function setUp()
 {
     $routeAssemblerProphezy = $this->prophesize(RouteAssembler::class);
     $routeAssemblerProphezy->assembleUrl('home', true)->willReturn('/foo/bar');
     $routeAssemblerProphezy->assembleUrl(null, ['lang' => 'es'])->willReturn('/es');
     $routeAssemblerProphezy->assembleUrl(null, ['lang' => 'en'])->willReturn('/en');
     $routeAssemblerProphezy->getCurrentRouteResult()->willReturn(RouteResult::fromRouteMatch('home', 'HelloWorld', []));
     $this->extension = new NavigationExtension(Translator::factory([]), $routeAssemblerProphezy->reveal(), ['menu' => [['route' => 'home', 'icon' => 'house', 'label' => 'Home'], ['uri' => 'http://foo.com', 'target' => true, 'label' => 'Blog', 'icon' => 'book']], 'lang_menu' => [['label' => 'Español', 'class' => 'es', 'params' => ['lang' => 'es']], ['label' => 'English', 'class' => 'en', 'params' => ['lang' => 'en']]]]);
 }

作者:evoli    项目:loculu   
public function translatePlural($singular, $plural, $number, $textDomain, $locale)
 {
     if ($this->translator === null) {
         $this->translator = $this->getApplicationServiceLocator()->get('translator');
     }
     return $this->translator->translatePlural($singular, $plural, $number, $textDomain, $locale);
 }


问题


面经


文章

微信
公众号

扫码关注公众号