本文整理汇总了PHP中JMS\TranslationBundle\Model\MessageCatalogue::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP MessageCatalogue::merge方法的具体用法?PHP MessageCatalogue::merge怎么用?PHP MessageCatalogue::merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JMS\TranslationBundle\Model\MessageCatalogue
的用法示例。
在下文中一共展示了MessageCatalogue::merge方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setConfig
/**
* @param Config $config
*/
private function setConfig(Config $config)
{
$this->config = $config;
$this->logger->info(sprintf("Loading catalogues from \"%s\"", $config->getTranslationsDir()));
$this->existingCatalogue = new MessageCatalogue();
// load external resources, so current translations can be reused in the final translation
foreach ($config->getLoadResources() as $resource) {
$this->existingCatalogue->merge($this->loader->loadFromDirectory($resource, $config->getLocale()));
}
$this->existingCatalogue->merge($this->loader->loadFromDirectory($config->getTranslationsDir(), $config->getLocale()));
$this->extractor->reset();
$this->extractor->setDirectories($config->getScanDirs());
$this->extractor->setExcludedDirs($config->getExcludedDirs());
$this->extractor->setExcludedNames($config->getExcludedNames());
$this->extractor->setEnabledExtractors($config->getEnabledExtractors());
$this->logger->info("Extracting translation keys");
$this->scannedCatalogue = $this->extractor->extract();
$this->scannedCatalogue->setLocale($config->getLocale());
// merge existing messages into scanned messages
foreach ($this->scannedCatalogue->getDomains() as $domainCatalogue) {
foreach ($domainCatalogue->all() as $message) {
if (!$this->existingCatalogue->has($message)) {
continue;
}
$existingMessage = clone $this->existingCatalogue->get($message->getId(), $message->getDomain());
$existingMessage->mergeScanned($message);
$this->scannedCatalogue->set($existingMessage, true);
}
}
if ($this->config->isKeepOldMessages()) {
foreach ($this->existingCatalogue->getDomains() as $domainCatalogue) {
foreach ($domainCatalogue->all() as $message) {
if ($this->scannedCatalogue->has($message)) {
continue;
}
$this->scannedCatalogue->add($message);
}
}
}
//keep old translations translated
if ($this->config->isKeepOldTranslationMessages()) {
$locale = $this->scannedCatalogue->getLocale();
/** @var MessageCatalogue $domainCatalogue */
foreach ($this->scannedCatalogue->getDomains() as $domainCatalogue) {
/** @var Message $message */
foreach ($domainCatalogue->all() as $message) {
$translated = $this->translator->trans($message->getId(), array(), $message->getDomain(), $locale);
$message->setLocaleString($translated);
$message->setNew(false);
}
}
}
}
示例2: loadFromDirectory
/**
* @param $dir
* @param $targetLocale
* @return \JMS\TranslationBundle\Model\MessageCatalogue
*/
public function loadFromDirectory($dir, $targetLocale)
{
$files = FileUtils::findTranslationFiles($dir);
$catalogue = new MessageCatalogue();
$catalogue->setLocale($targetLocale);
foreach ($files as $domain => $locales) {
foreach ($locales as $locale => $data) {
if ($locale !== $targetLocale) {
continue;
}
list($format, $file) = $data;
$catalogue->merge($this->getLoader($format)->load($file, $locale, $domain));
}
}
return $catalogue;
}
示例3: getAllTranslations
private function getAllTranslations($locale)
{
$catalogue = new MessageCatalogue();
$loader = $this->get('jms_translation.loader_manager');
// load external resources, so current translations can be reused in the final translation
foreach ($this->retrieveDirs() as $resource) {
$catalogue->merge($loader->loadFromDirectory($resource, $locale));
}
$localesArray = array();
foreach ($catalogue->getDomains() as $domain => $collection) {
foreach ($collection->all() as $key => $translation) {
$localesArray[$key] = $translation->getLocaleString();
}
}
return $localesArray;
}
示例4: extract
/**
* @return \JMS\TranslationBundle\Model\MessageCatalogue
*/
public function extract()
{
$catalogue = new MessageCatalogue();
foreach ($this->directories as $directory) {
$this->logger->info(sprintf('Extracting messages from directory : %s', $directory));
$this->fileExtractor->setDirectory($directory);
$catalogue->merge($this->fileExtractor->extract());
}
foreach ($this->customExtractors as $alias => $extractor) {
if (!isset($this->enabledExtractors[$alias])) {
$this->logger->debug(sprintf('Skipping custom extractor "%s" as it is not enabled.', $alias));
continue;
}
$this->logger->info(sprintf('Extracting messages with custom extractor : %s', $alias));
$catalogue->merge($extractor->extract());
}
return $catalogue;
}
示例5: testMerge
public function testMerge()
{
$cat = new MessageCatalogue();
$cat->add(new Message('foo', 'foo'));
$cat2 = new MessageCatalogue();
$cat2->add(new Message('foo', 'bar'));
$cat->merge($cat2);
$this->assertEquals(array('foo', 'bar'), array_keys($domains = $cat->getDomains()));
$this->assertEquals(array('bar'), array_keys($cat2->getDomains()));
$this->assertEquals(array('foo'), array_keys($domains['foo']->all()));
$this->assertEquals(array('foo'), array_keys($domains['bar']->all()));
}