当前位置: 首页>>代码示例>>PHP>>正文


PHP Translator\Translator类代码示例

本文整理汇总了PHP中Zend\I18n\Translator\Translator的典型用法代码示例。如果您正苦于以下问题:PHP Translator类的具体用法?PHP Translator怎么用?PHP Translator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Translator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init

 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;
 }
开发者ID:cyantree,项目名称:grout-translator-module,代码行数:25,代码来源:TranslatorModule.php

示例2: __invoke

 /**
  * 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);
 }
开发者ID:navassouza,项目名称:zf2,代码行数:18,代码来源:TranslatePlural.php

示例3: setUp

 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}']]]];
 }
开发者ID:zendframework,项目名称:zend-mvc-i18n,代码行数:8,代码来源:TranslatorAwareTreeRouteStackTest.php

示例4: __invoke

 /**
  * @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);
 }
开发者ID:cityware,项目名称:city-mvc,代码行数:13,代码来源:TranslatePlugin.php

示例5: getTranslator

 /**
  * 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;
 }
开发者ID:no-reply,项目名称:cbpl-vufind,代码行数:14,代码来源:DisplayLanguageOption.php

示例6: onBootstrap

 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);
 }
开发者ID:spoorey,项目名称:hangman,代码行数:12,代码来源:Module.php

示例7: createTranslatorAdapter

 /**
  * {@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;
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:17,代码来源:TranslatorAdapterFactory.php

示例8: setUp

 public function setUp()
 {
     $command = new GenerateCharsetCommand(Translator::factory([]));
     $app = new Application();
     $app->add($command);
     $this->commandTester = new CommandTester($command);
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:7,代码来源:GenerateCharsetCommandTest.php

示例9: createService

 /**
  * @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());
 }
开发者ID:JeoffScott,项目名称:dyplom,代码行数:32,代码来源:TranslatorServiceFactory.php

示例10: setUp

 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());
 }
开发者ID:kukoman,项目名称:website-expressive,代码行数:8,代码来源:RendererFactoryTest.php

示例11: setUp

 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);
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:8,代码来源:GenerateShortcodeCommandTest.php

示例12: __invoke

 /**
  * 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;
 }
开发者ID:axelmdev,项目名称:ecommerce,代码行数:16,代码来源:TranslatorServiceFactory.php

示例13: translatePlural

 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);
 }
开发者ID:evolic,项目名称:loculus,代码行数:7,代码来源:HttpControllerTestCase.php

示例14: testLanguage

 public function testLanguage()
 {
     $this->assertEquals('en', $this->translator->getLocale());
     $this->middleware->__invoke($this->request, new Response(), function ($req, $resp) {
         return $resp;
     });
     $this->assertEquals('es', $this->translator->getLocale());
 }
开发者ID:kukoman,项目名称:website-expressive,代码行数:8,代码来源:LanguageMiddlewareTest.php

示例15: addErrorMessage

 public function addErrorMessage($message)
 {
     if ($this->translator) {
         $namespace = explode('\\', get_class($this))[0];
         $message = $this->translator->translate($message, $namespace);
     }
     $this->errorMessages[] = $message;
 }
开发者ID:hoangpt,项目名称:nextcms,代码行数:8,代码来源:Entity.php


注:本文中的Zend\I18n\Translator\Translator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。