本文整理汇总了PHP中Symfony\Component\Translation\Translator::loadCatalogue方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::loadCatalogue方法的具体用法?PHP Translator::loadCatalogue怎么用?PHP Translator::loadCatalogue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Translation\Translator
的用法示例。
在下文中一共展示了Translator::loadCatalogue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rebuildCache
public function rebuildCache($locale)
{
$cache = new ConfigCache($this->options['cache_dir'] . '/catalogue.' . $locale . '.php', $this->options['debug']);
$this->initialize();
// one of the rare situations to "skip" to the grandparent implementation.
\Symfony\Component\Translation\Translator::loadCatalogue($locale);
$fallbackContent = '';
$current = '';
foreach ($this->computeFallbackLocales($locale) as $fallback) {
$fallbackSuffix = ucfirst(str_replace('-', '_', $fallback));
$fallbackContent .= sprintf(<<<EOF
\$catalogue%s = new MessageCatalogue('%s', %s);
\$catalogue%s->addFallbackCatalogue(\$catalogue%s);
EOF
, $fallbackSuffix, $fallback, var_export($this->catalogues[$fallback]->all(), true), ucfirst(str_replace('-', '_', $current)), $fallbackSuffix);
$current = $fallback;
}
$content = sprintf(<<<EOF
<?php
use Symfony\\Component\\Translation\\MessageCatalogue;
\$catalogue = new MessageCatalogue('%s', %s);
%s
return \$catalogue;
EOF
, $locale, var_export($this->catalogues[$locale]->all(), true), $fallbackContent);
$cache->write($content, $this->catalogues[$locale]->getResources());
}
示例2: loadCatalogue
/**
* @{inheritDoc}
*/
public function loadCatalogue($locale)
{
$cacheKey = sprintf('cog.localisation.translations1.%s', $locale);
if (false === $this->_cacheEnabled or false === ($this->catalogues = $this->_container['cache']->fetch($cacheKey))) {
$parser = $this->_container['reference_parser'];
// Load translation files from modules
foreach ($this->_container['module.loader']->getModules() as $moduleName) {
$moduleName = str_replace('\\', $parser::SEPARATOR, $moduleName);
$dir = 'cog://@' . $moduleName . $parser::MODULE_SEPARATOR . 'translations';
if (file_exists($dir)) {
foreach ($this->_container['filesystem.finder']->in($dir) as $file) {
$this->addResource('yml', $file->getPathname(), $file->getFilenameWithoutExtension());
}
}
}
// Load application translation files
$dir = $this->_container['app.loader']->getBaseDir() . 'translations';
if (file_exists($dir)) {
foreach ($this->_container['filesystem.finder']->in($dir) as $file) {
$this->addResource('yml', $file->getPathname(), $file->getFilenameWithoutExtension());
}
}
parent::loadCatalogue($locale);
$this->_container['cache']->store($cacheKey, $this->catalogues);
}
}
示例3: loadCatalogue
/**
* {@inheritdoc}
*/
protected function loadCatalogue($locale)
{
if (isset($this->catalogues[$locale])) {
return;
}
if (null === $this->options['cache_dir']) {
$this->initialize();
return parent::loadCatalogue($locale);
}
$this->assertValidLocale($locale);
$cache = new ConfigCache($this->options['cache_dir'] . '/catalogue.' . $locale . '.php', $this->options['debug']);
if (!$cache->isFresh()) {
$this->initialize();
parent::loadCatalogue($locale);
$fallbackContent = '';
$current = '';
$replacementPattern = '/[^a-z0-9_]/i';
foreach ($this->computeFallbackLocales($locale) as $fallback) {
$fallbackSuffix = ucfirst(preg_replace($replacementPattern, '_', $fallback));
$currentSuffix = ucfirst(preg_replace($replacementPattern, '_', $current));
$fallbackContent .= sprintf(<<<EOF
\$catalogue%s = new MessageCatalogue('%s', %s);
\$catalogue%s->addFallbackCatalogue(\$catalogue%s);
EOF
, $fallbackSuffix, $fallback, var_export($this->catalogues[$fallback]->all(), true), $currentSuffix, $fallbackSuffix);
$current = $fallback;
}
$content = sprintf(<<<EOF
<?php
use Symfony\\Component\\Translation\\MessageCatalogue;
\$catalogue = new MessageCatalogue('%s', %s);
%s
return \$catalogue;
EOF
, $locale, var_export($this->catalogues[$locale]->all(), true), $fallbackContent);
$cache->write($content, $this->catalogues[$locale]->getResources());
return;
}
$this->catalogues[$locale] = (include $cache);
}
示例4: loadCatalogue
/**
* {@inheritdoc}
*/
protected function loadCatalogue($locale)
{
if (isset($this->catalogues[$locale])) {
return;
}
if (null === $this->options['cache_dir']) {
$this->initialize();
return parent::loadCatalogue($locale);
}
if ($this->needsReload($locale)) {
$this->initialize();
parent::loadCatalogue($locale);
$this->updateCache($locale);
return;
}
$this->catalogues[$locale] = (include $this->getCacheFile($locale));
}
示例5: loadCatalogue
/**
* {@inheritdoc}
*/
protected function loadCatalogue($locale)
{
if (isset($this->catalogues[$locale])) {
return;
}
if (null === $this->options['cache_dir']) {
$this->initialize();
return parent::loadCatalogue($locale);
}
$cache = new ConfigCache($this->options['cache_dir'] . '/catalogue.' . $locale . '.php', $this->options['debug']);
if (!$cache->isFresh()) {
$this->initialize();
parent::loadCatalogue($locale);
$content = sprintf("<?php use Symfony\\Component\\Translation\\MessageCatalogue; return new MessageCatalogue('%s', %s);", $locale, var_export($this->catalogues[$locale]->all(), true));
$cache->write($content, $this->catalogues[$locale]->getResources());
return;
}
$this->catalogues[$locale] = (include $cache);
}
示例6: loadCatalogue
/**
* {@inheritdoc}
*/
protected function loadCatalogue($locale)
{
if (isset($this->catalogues[$locale])) {
return;
}
if (null === $this->options['cache_dir']) {
$this->initialize();
return parent::loadCatalogue($locale);
}
$cache = new ConfigCache($this->options['cache_dir'] . '/catalogue.' . $locale . '.php', $this->options['debug']);
if (!$cache->isFresh()) {
$this->initialize();
parent::loadCatalogue($locale);
$fallbackContent = '';
$fallback = $this->computeFallbackLocale($locale);
if ($fallback && $fallback != $locale) {
$fallbackContent = sprintf(<<<EOF
\$catalogue->addFallbackCatalogue(new MessageCatalogue('%s', %s));
EOF
, $fallback, var_export($this->catalogues[$fallback]->all(), true));
}
$content = sprintf(<<<EOF
<?php
use Symfony\\Component\\Translation\\MessageCatalogue;
\$catalogue = new MessageCatalogue('%s', %s);
%s
return \$catalogue;
EOF
, $locale, var_export($this->catalogues[$locale]->all(), true), $fallbackContent);
$cache->write($content, $this->catalogues[$locale]->getResources());
return;
}
$this->catalogues[$locale] = (include $cache);
}