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


PHP MessageCatalogue::getLocale方法代码示例

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


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

示例1: write

 public function write(MessageCatalogue $catalogue, $domain, $filePath, $format)
 {
     $newCatalogue = new MessageCatalogue();
     $newCatalogue->setLocale($catalogue->getLocale());
     foreach (array_keys($catalogue->getDomains()) as $catalogueDomainString) {
         if ($catalogue->getLocale() !== 'en' && $this->hasEnglishCatalogue($filePath)) {
             $englishCatalogue = $this->loadEnglishCatalogue($filePath, $domain, $format);
         }
         $domainMessageCollection = $catalogue->getDomain($catalogueDomainString);
         /** @var Message $message */
         foreach ($domainMessageCollection->all() as $message) {
             if ($message->getDomain() !== $domain) {
                 continue;
             }
             $newMessage = $this->makeXliffMessage($message);
             if ($message->getId() === $message->getSourceString()) {
                 if (isset($englishCatalogue)) {
                     try {
                         $newMessage->setDesc($englishCatalogue->get($message->getId(), $message->getDomain())->getLocaleString());
                     } catch (InvalidArgumentException $e) {
                         continue;
                     }
                 } else {
                     $newMessage->setDesc($message->getLocaleString());
                 }
             }
             $newCatalogue->add($newMessage);
         }
     }
     $this->innerFileWriter->write($newCatalogue, $domain, $filePath, $format);
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:31,代码来源:CatalogueMapperFileWriter.php

示例2: testGetSetLocale

 public function testGetSetLocale()
 {
     $catalogue = new MessageCatalogue();
     $this->assertNull($catalogue->getLocale());
     $catalogue->setLocale('en');
     $this->assertEquals('en', $catalogue->getLocale());
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:7,代码来源:MessageCatalogueTest.php

示例3: 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);
             }
         }
     }
 }
开发者ID:clytemnestra,项目名称:JMSTranslationBundle,代码行数:56,代码来源:Updater.php

示例4: dump

 public function dump(MessageCatalogue $catalogue, $domain = 'messages', $filePath = null)
 {
     $symfonyCatalogue = new SymfonyCatalogue($catalogue->getLocale());
     foreach ($catalogue->getDomain($domain)->all() as $id => $message) {
         $symfonyCatalogue->add(array($id => $message->getLocaleString()), $domain);
     }
     $tmpPath = sys_get_temp_dir() . '/' . uniqid('translation', false);
     if (!is_dir($tmpPath) && false === @mkdir($tmpPath, 0777, true)) {
         throw new RuntimeException(sprintf('Could not create temporary directory "%s".', $tmpPath));
     }
     $this->dumper->dump($symfonyCatalogue, array('path' => $tmpPath));
     if (!is_file($tmpFile = $tmpPath . '/' . $domain . '.' . $catalogue->getLocale() . '.' . $this->format)) {
         throw new RuntimeException(sprintf('Could not find dumped translation file "%s".', $tmpFile));
     }
     $contents = file_get_contents($tmpFile);
     $fs = new Filesystem();
     $fs->remove($tmpPath);
     if ('' === $contents) {
         throw new RuntimeException(sprintf('Could not dump message catalogue using dumper "%s". It could be that it is not compatible.', get_class($this->dumper)));
     }
     return $contents;
 }
开发者ID:Kofel,项目名称:JMSTranslationBundle,代码行数:22,代码来源:SymfonyDumperAdapter.php

示例5: dump

 /**
  * @param \JMS\TranslationBundle\Model\MessageCatalogue $domain
  * @return string
  */
 public function dump(MessageCatalogue $catalogue, $domain = 'messages')
 {
     $doc = new \DOMDocument('1.0', 'utf-8');
     $doc->formatOutput = true;
     $doc->appendChild($root = $doc->createElement('xliff'));
     $root->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
     $root->setAttribute('xmlns:jms', 'urn:jms:translation');
     $root->setAttribute('version', '1.2');
     $root->appendChild($file = $doc->createElement('file'));
     if ($this->addDate) {
         $date = new \DateTime();
         $file->setAttribute('date', $date->format('Y-m-d\\TH:i:s\\Z'));
     }
     $file->setAttribute('source-language', $this->sourceLanguage);
     $file->setAttribute('target-language', $catalogue->getLocale());
     $file->setAttribute('datatype', 'plaintext');
     $file->setAttribute('original', 'not.available');
     $file->appendChild($header = $doc->createElement('header'));
     $header->appendChild($tool = $doc->createElement('tool'));
     $tool->setAttribute('tool-id', 'JMSTranslationBundle');
     $tool->setAttribute('tool-name', 'JMSTranslationBundle');
     $tool->setAttribute('tool-version', JMSTranslationBundle::VERSION);
     $header->appendChild($note = $doc->createElement('note'));
     $note->appendChild($doc->createTextNode('The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.'));
     $file->appendChild($body = $doc->createElement('body'));
     foreach ($catalogue->getDomain($domain)->all() as $id => $message) {
         $body->appendChild($unit = $doc->createElement('trans-unit'));
         $unit->setAttribute('id', hash('sha1', $id));
         $unit->setAttribute('resname', $id);
         $unit->appendChild($source = $doc->createElement('source'));
         if (preg_match('/[<>&]/', $message->getSourceString())) {
             $source->appendChild($doc->createCDATASection($message->getSourceString()));
         } else {
             $source->appendChild($doc->createTextNode($message->getSourceString()));
         }
         $unit->appendChild($target = $doc->createElement('target'));
         if (preg_match('/[<>&]/', $message->getLocaleString())) {
             $target->appendChild($doc->createCDATASection($message->getLocaleString()));
         } else {
             $target->appendChild($doc->createTextNode($message->getLocaleString()));
         }
         if ($message->isNew()) {
             $target->setAttribute('state', 'new');
         }
         // As per the OASIS XLIFF 1.2 non-XLIFF elements must be at the end of the <trans-unit>
         if ($sources = $message->getSources()) {
             foreach ($sources as $source) {
                 if ($source instanceof FileSource) {
                     $unit->appendChild($refFile = $doc->createElement('jms:reference-file', $source->getPath()));
                     if ($source->getLine()) {
                         $refFile->setAttribute('line', $source->getLine());
                     }
                     if ($source->getColumn()) {
                         $refFile->setAttribute('column', $source->getColumn());
                     }
                     continue;
                 }
                 $unit->appendChild($doc->createElementNS('jms:reference', (string) $source));
             }
         }
         if ($meaning = $message->getMeaning()) {
             $unit->setAttribute('extradata', 'Meaning: ' . $meaning);
         }
     }
     return $doc->saveXML();
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:70,代码来源:XliffDumper.php

示例6: dump

 public function dump(MessageCatalogue $catalogue, $domain = 'messages')
 {
     $this->catalogue = $catalogue;
     $this->locale = $catalogue->getLocale();
     return parent::dump($catalogue, $domain);
 }
开发者ID:it-blaster,项目名称:translation-bundle,代码行数:6,代码来源:PhpDumper.php


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