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


PHP Translator::getCatalogue方法代码示例

本文整理汇总了PHP中Symfony\Component\Translation\Translator::getCatalogue方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::getCatalogue方法的具体用法?PHP Translator::getCatalogue怎么用?PHP Translator::getCatalogue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Translation\Translator的用法示例。


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

示例1: testGetCatalogue

 public function testGetCatalogue()
 {
     $translator = new Translator('en');
     $this->assertEquals(new MessageCatalogue('en'), $translator->getCatalogue());
     $translator->setLocale('fr');
     $this->assertEquals(new MessageCatalogue('fr'), $translator->getCatalogue('fr'));
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:7,代码来源:TranslatorTest.php

示例2: getCatalogue

 /**
  * {@inheritdoc}
  */
 public function getCatalogue($locale = null)
 {
     $catalogue = parent::getCatalogue($locale);
     foreach ($catalogue->all() as $domain => $messages) {
         foreach ($messages as $id => $translation) {
             $catalogue->set($id, $this->getTranslation($catalogue, $id, $domain), $domain);
         }
     }
     return $catalogue;
 }
开发者ID:huangcong12,项目名称:core,代码行数:13,代码来源:Translator.php

示例3: execute

 /**
  * Executes the export by loading the catalogue and writing messages
  * from the defined domains to the defined file.
  */
 public function execute()
 {
     $messages = [];
     /** @var MessageCatalogueInterface $catalogue */
     $catalogue = $this->translator->getCatalogue($this->getLocale());
     if ($this->backend) {
         $messages = array_merge($messages, $this->getMessagesForDomain($catalogue, self::BACKEND_DOMAIN));
     }
     if ($this->frontend) {
         $messages = array_merge($messages, $this->getMessagesForDomain($catalogue, self::FRONTEND_DOMAIN));
     }
     $this->writeMessagesFile($messages);
 }
开发者ID:sulu,项目名称:sulu,代码行数:17,代码来源:Export.php

示例4: getCatalogue

 /**
  * {@inheritdoc}
  */
 public function getCatalogue($locale = null)
 {
     if (null === $locale) {
         $locale = $this->getLocale();
     } else {
         $this->assertValidLocale($locale);
     }
     $parse = !isset($this->catalogues[$locale]);
     $catalogue = parent::getCatalogue($locale);
     if ($parse) {
         $this->parseCatalogue($catalogue);
     }
     return $catalogue;
 }
开发者ID:reesun,项目名称:core,代码行数:17,代码来源:Translator.php

示例5: createInstance

 protected static function createInstance()
 {
     if (config('app.debug') && !config('trans.cache_on_debug')) {
         \Cache::forget('po_cache');
     }
     return \Cache::rememberForever('po_cache', function () {
         $basePath = config('trans.translations_path');
         $locales = config('trans.supported_locales');
         $translator = new SymfonyTranslator(config('app.locale'));
         $translator->addLoader('po', new PoFileLoader());
         $translator->setFallbackLocales([config('app.locale')]);
         foreach ($locales as $locale) {
             $path = base_path($basePath . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES');
             $file = $path . DIRECTORY_SEPARATOR . 'messages.po';
             if (file_exists($file)) {
                 $translator->addResource('po', $file, $locale);
                 $translator->getCatalogue($locale);
             }
         }
         return $translator;
     });
 }
开发者ID:gummibeer,项目名称:laravel-translation,代码行数:22,代码来源:Translator.php

示例6: testPrimaryAndFallbackCataloguesContainTheSameMessagesRegardlessOfCaching

 public function testPrimaryAndFallbackCataloguesContainTheSameMessagesRegardlessOfCaching()
 {
     /*
      * As a safeguard against potential BC breaks, make sure that primary and fallback
      * catalogues (reachable via getFallbackCatalogue()) always contain the full set of
      * messages provided by the loader. This must also be the case when these catalogues
      * are (internally) read from a cache.
      *
      * Optimizations inside the translator must not change this behaviour.
      */
     /*
      * Create a translator that loads two catalogues for two different locales.
      * The catalogues contain distinct sets of messages.
      */
     $translator = new Translator('a', null, $this->tmpDir);
     $translator->setFallbackLocales(array('b'));
     $translator->addLoader('array', new ArrayLoader());
     $translator->addResource('array', array('foo' => 'foo (a)'), 'a');
     $translator->addResource('array', array('foo' => 'foo (b)'), 'b');
     $translator->addResource('array', array('bar' => 'bar (b)'), 'b');
     $catalogue = $translator->getCatalogue('a');
     $this->assertFalse($catalogue->defines('bar'));
     // Sure, the "a" catalogue does not contain that message.
     $fallback = $catalogue->getFallbackCatalogue();
     $this->assertTrue($fallback->defines('foo'));
     // "foo" is present in "a" and "b"
     /*
      * Now, repeat the same test.
      * Behind the scenes, the cache is used. But that should not matter, right?
      */
     $translator = new Translator('a', null, $this->tmpDir);
     $translator->setFallbackLocales(array('b'));
     $translator->addLoader('array', new ArrayLoader());
     $translator->addResource('array', array('foo' => 'foo (a)'), 'a');
     $translator->addResource('array', array('foo' => 'foo (b)'), 'b');
     $translator->addResource('array', array('bar' => 'bar (b)'), 'b');
     $catalogue = $translator->getCatalogue('a');
     $this->assertFalse($catalogue->defines('bar'));
     $fallback = $catalogue->getFallbackCatalogue();
     $this->assertTrue($fallback->defines('foo'));
 }
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:41,代码来源:TranslatorCacheTest.php

示例7: testGetCatalogueReturnsConsolidatedCatalogue

 public function testGetCatalogueReturnsConsolidatedCatalogue()
 {
     /*
      * This will be useful once we refactor so that different domains will be loaded lazily (on-demand).
      * In that case, getCatalogue() will probably have to load all missing domains in order to return
      * one complete catalogue.
      */
     $locale = 'whatever';
     $translator = new Translator($locale);
     $translator->addLoader('loader-a', new ArrayLoader());
     $translator->addLoader('loader-b', new ArrayLoader());
     $translator->addResource('loader-a', array('foo' => 'foofoo'), $locale, 'domain-a');
     $translator->addResource('loader-b', array('bar' => 'foobar'), $locale, 'domain-b');
     /*
      * Test that we get a single catalogue comprising messages
      * from different loaders and different domains
      */
     $catalogue = $translator->getCatalogue($locale);
     $this->assertTrue($catalogue->defines('foo', 'domain-a'));
     $this->assertTrue($catalogue->defines('bar', 'domain-b'));
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:21,代码来源:TranslatorTest.php

示例8: createTranslator

 /**
  * Creates a new translator instance
  *
  * @return SymfonyTranslator
  */
 protected function createTranslator()
 {
     $translator = new SymfonyTranslator($this->getLocale());
     $translator->addLoader('po', new PoFileLoader());
     $file = $this->fileSystem->makePOFilePath($this->getLocale(), $this->getDomain());
     $translator->addResource('po', $file, $this->getLocale(), $this->getDomain());
     $translator->getCatalogue($this->getLocale());
     return $translator;
 }
开发者ID:xinax,项目名称:laravel-gettext,代码行数:14,代码来源:Symfony.php

示例9: testFallbackCatalogueResources

 public function testFallbackCatalogueResources()
 {
     $translator = new Translator('en_GB', new MessageSelector());
     $translator->addLoader('yml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
     $translator->addResource('yml', __DIR__ . '/fixtures/empty.yml', 'en_GB');
     $translator->addResource('yml', __DIR__ . '/fixtures/resources.yml', 'en');
     // force catalogue loading
     $this->assertEquals('bar', $translator->trans('foo', array()));
     $resources = $translator->getCatalogue('en')->getResources();
     $this->assertCount(1, $resources);
     $this->assertContains(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'resources.yml', $resources);
     $resources = $translator->getCatalogue('en_GB')->getResources();
     $this->assertCount(2, $resources);
     $this->assertContains(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'empty.yml', $resources);
     $this->assertContains(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'resources.yml', $resources);
 }
开发者ID:ayoah,项目名称:symfony,代码行数:16,代码来源:TranslatorTest.php


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