本文整理汇总了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'));
}
示例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;
}
示例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);
}
示例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;
}
示例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;
});
}
示例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'));
}
示例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'));
}
示例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;
}
示例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);
}