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


PHP Translation\MessageCatalogue类代码示例

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


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

示例1: execute

 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // get bundle directory
     $foundBundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
     $bundleTransPath = $foundBundle->getPath() . '/Resources/translations';
     $writer = $this->getContainer()->get('translation.writer');
     $supportedFormats = $writer->getFormats();
     if (!in_array($input->getOption('output-format'), $supportedFormats)) {
         $output->writeln('<error>Wrong output format</error>');
         $output->writeln('Supported formats are ' . implode(', ', $supportedFormats) . '.');
         return 1;
     }
     $this->orm = $this->getContainer()->get('doctrine.orm.default_entity_manager');
     $languages = $this->orm->getRepository('RaindropTranslationBundle:Language')->findAll();
     $tokens = $this->orm->getRepository('RaindropTranslationBundle:LanguageToken')->findAll();
     foreach ($languages as $language) {
         $output->writeln(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $language, $foundBundle->getName()));
         // create catalogue
         $catalogue = new MessageCatalogue($language);
         foreach ($tokens as $token) {
             $translation = $this->orm->getRepository('RaindropTranslationBundle:LanguageTranslation')->findOneBy(array('language' => $language, 'languageToken' => $token, 'catalogue' => $token->getCatalogue()));
             if (!empty($translation)) {
                 $content = $translation->getTranslation() != '' ? $translation->getTranslation() : null;
                 $catalogue->set($token->getToken(), $content);
             }
         }
         $writer->writeTranslations($catalogue, $input->getOption('output-format'), array('path' => $bundleTransPath));
     }
 }
开发者ID:kyaroslav,项目名称:RaindropTranslationBundle,代码行数:32,代码来源:ExportLanguageTranslationCommand.php

示例2: load

 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     list($xml, $encoding) = $this->parseFile($resource);
     $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
     $catalogue = new MessageCatalogue($locale);
     foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
         $attributes = $translation->attributes();
         if (!(isset($attributes['resname']) || isset($translation->source))) {
             continue;
         }
         $source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
         // If the xlf file has another encoding specified, try to convert it because
         // simple_xml will always return utf-8 encoded values
         $target = $this->utf8ToCharset((string) (isset($translation->target) ? $translation->target : $source), $encoding);
         $catalogue->set((string) $source, $target, $domain);
         $metadata = array();
         if ($notes = $this->parseNotesMetadata($translation->note, $encoding)) {
             $metadata['notes'] = $notes;
         }
         if ($translation->target->attributes()) {
             $metadata['target-attributes'] = $translation->target->attributes();
         }
         $catalogue->setMetadata((string) $source, $metadata, $domain);
     }
     if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
         $catalogue->addResource(new FileResource($resource));
     }
     return $catalogue;
 }
开发者ID:symstriker,项目名称:symfony,代码行数:40,代码来源:XliffFileLoader.php

示例3: extractFile

 /**
  * Extracts translation messages from a file to the catalogue.
  *
  * @param string           $file The path to look into
  * @param MessageCatalogue $catalogue The catalogue
  */
 public function extractFile($file, MessageCatalogue $catalogue)
 {
     $buffer = NULL;
     $parser = new Parser();
     $parser->shortNoEscape = TRUE;
     foreach ($tokens = $parser->parse(file_get_contents($file)) as $token) {
         if ($token->type !== $token::MACRO_TAG || !in_array($token->name, array('_', '/_'), TRUE)) {
             if ($buffer !== NULL) {
                 $buffer .= $token->text;
             }
             continue;
         }
         if ($token->name === '/_') {
             $catalogue->set(($this->prefix ? $this->prefix . '.' : '') . $buffer, $buffer);
             $buffer = NULL;
         } elseif ($token->name === '_' && empty($token->value)) {
             $buffer = '';
         } else {
             $args = new MacroTokens($token->value);
             $writer = new PhpWriter($args, $token->modifiers);
             $message = $writer->write('%node.word');
             if (in_array(substr(trim($message), 0, 1), array('"', '\''), TRUE)) {
                 $message = substr(trim($message), 1, -1);
             }
             $catalogue->set(($this->prefix ? $this->prefix . '.' : '') . $message, $message);
         }
     }
 }
开发者ID:tomasstrejcek,项目名称:Translation,代码行数:34,代码来源:LatteExtractor.php

示例4: dump

 /**
  * Dumps the message catalogue.
  *
  * @param MessageCatalogue $messages The message catalogue
  * @param array            $options  Options that are used by the dumper
  */
 public function dump(MessageCatalogue $messages, $options = array())
 {
     $this->loadAll = false;
     $locale = $messages->getLocale();
     try {
         foreach ($messages->getDomains() as $eachDomain) {
             foreach ($messages->all($eachDomain) as $eachKey => $eachTranslation) {
                 $queryBuilder = $this->entityManager->createQueryBuilder();
                 $queryBuilder->select('t')->from('MjrLibraryEntitiesBundle:System\\Translation', 't')->where($queryBuilder->expr()->andX($queryBuilder->expr()->eq('t.Identity', '?1'), $queryBuilder->expr()->eq('t.Locale', '?2')));
                 $query = $this->entityManager->createQuery($queryBuilder->getDQL());
                 $query->setParameters(array(1 => $eachKey, 2 => $locale));
                 $result = $query->getArrayResult();
                 if (count($result) < 1) {
                     $entry = new Translation();
                     $entry->setLocale($locale);
                     $entry->setIdentity($eachKey);
                     $entry->setTranslation($eachKey);
                     $this->entityManager->persist($entry);
                     $this->entityManager->flush();
                 }
                 unset($query, $queryBuilder, $entry, $eachKey, $eachTranslation);
             }
         }
     } catch (\Exception $ex) {
         var_dump($ex);
         die;
     }
 }
开发者ID:ChrisWesterfield,项目名称:MJR.ONE-CP,代码行数:34,代码来源:DbDumper.php

示例5: testLinearFormatCatalogue

 public function testLinearFormatCatalogue()
 {
     $catalogue = new MessageCatalogue('en');
     $catalogue->add(array('foo.bar1' => 'value1', 'foo.bar2' => 'value2'));
     $dumper = new YamlFileDumper();
     $this->assertStringEqualsFile(__DIR__ . '/../fixtures/messages_linear.yml', $dumper->formatCatalogue($catalogue, 'messages'));
 }
开发者ID:saj696,项目名称:pipe,代码行数:7,代码来源:YamlFileDumperTest.php

示例6: format

 /**
  * {@inheritDoc}
  */
 protected function format(MessageCatalogue $messages, $domain)
 {
     $dom = new \DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $xliff = $dom->appendChild($dom->createElement('xliff'));
     $xliff->setAttribute('version', '1.2');
     $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
     $xliffFile = $xliff->appendChild($dom->createElement('file'));
     $xliffFile->setAttribute('source-language', $messages->getLocale());
     $xliffFile->setAttribute('datatype', 'plaintext');
     $xliffFile->setAttribute('original', 'file.ext');
     $xliffBody = $xliffFile->appendChild($dom->createElement('body'));
     $id = 1;
     foreach ($messages->all($domain) as $source => $target) {
         $trans = $dom->createElement('trans-unit');
         $trans->setAttribute('id', $id);
         $s = $trans->appendChild($dom->createElement('source'));
         $s->appendChild($dom->createTextNode($source));
         $t = $trans->appendChild($dom->createElement('target'));
         $t->appendChild($dom->createTextNode($target));
         $xliffBody->appendChild($trans);
         $id++;
     }
     return $dom->saveXML();
 }
开发者ID:laubosslink,项目名称:lab,代码行数:28,代码来源:XliffFileDumper.php

示例7: execute

 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $writer = $this->getContainer()->get('translation.writer');
     if (!$this->checkParameters($input, $output, $writer)) {
         return 1;
     }
     // get bundle directory
     $foundBundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
     $bundleTransPath = $foundBundle->getPath() . '/Resources/translations';
     $output->writeln(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $foundBundle->getName()));
     // create catalogue
     $catalogue = new MessageCatalogue($input->getArgument('locale'));
     $output->writeln('Parsing templates');
     $annotations = $this->getContainer()->get('oro_security.acl.annotation_provider')->getBundleAnnotations(array($foundBundle->getPath()));
     /** @var  $annotation Acl*/
     /** @var  $annotations AclAnnotationStorage*/
     foreach ($annotations->getAnnotations() as $annotation) {
         if ($label = $annotation->getLabel()) {
             $catalogue->set($label, $input->getOption('prefix') . $label);
         }
     }
     // load any existing messages from the translation files
     $output->writeln('Loading translation files');
     $loader = $this->getContainer()->get('translation.loader');
     $loader->loadMessages($bundleTransPath, $catalogue);
     // show compiled list of messages
     if ($input->getOption('dump-messages') === true) {
         $this->dumpMessages($input, $output, $catalogue);
     }
     // save the files
     if ($input->getOption('force') === true) {
         $this->saveMessages($input, $output, $catalogue, $writer, $bundleTransPath);
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:38,代码来源:AclTranslationUpdateCommand.php

示例8: testDumpWithCustomEncoding

 public function testDumpWithCustomEncoding()
 {
     $catalogue = new MessageCatalogue('en');
     $catalogue->add(array('foo' => '"bar"'));
     $dumper = new JsonFileDumper();
     $this->assertStringEqualsFile(__DIR__ . '/../fixtures/resources.dump.json', $dumper->formatCatalogue($catalogue, 'messages', array('json_encoding' => JSON_HEX_QUOT)));
 }
开发者ID:sapwoo,项目名称:portfolio,代码行数:7,代码来源:JsonFileDumperTest.php

示例9: submitFormTranslate

 public function submitFormTranslate(Form $form)
 {
     $values = $form->getValues();
     //existuje preklad ?
     $translatesLocale = $this->row->related('translate_locale')->where('language_id', $this->webLanguage)->fetch();
     if ($translatesLocale) {
         if ($values['translate'] != '') {
             $translatesLocale->update(array('translate' => $values['translate']));
         } else {
             $translatesLocale->delete();
         }
     } else {
         $this->row->related('translate_locale')->insert(array('translate' => $values['translate'], 'language_id' => $this->webLanguage));
     }
     $language = $this->languages->get($this->webLanguage);
     $catalogue = new MessageCatalogue($language['translate_locale']);
     foreach ($this->model->getAll() as $translate) {
         $translatesLocale = $translate->related('translate_locale')->where('language_id', $this->webLanguage)->fetch();
         if ($translatesLocale) {
             $catalogue->set($translate['text'], $translatesLocale['translate']);
         } else {
             $catalogue->set($translate['text'], $translate['text']);
         }
     }
     $this->writer->writeTranslations($catalogue, 'neon', ['path' => $this->context->parameters['appDir'] . '/lang/']);
     $this->flashMessage($this->translator->trans('translate.translated'));
     $this->redirect('this');
 }
开发者ID:vsek,项目名称:translate,代码行数:28,代码来源:TranslatePresenter.php

示例10: load

 /**
  * {@inheritdoc}
  */
 function load($resource, $locale, $domain = 'messages')
 {
     $catalogue = new MessageCatalogue($locale);
     $catalogue->addMessages(require $resource, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }
开发者ID:netixpro,项目名称:symfony,代码行数:10,代码来源:PhpFileLoader.php

示例11: format

 /**
  * {@inheritdoc}
  */
 protected function format(MessageCatalogue $messages, $domain)
 {
     $dom = new \DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $xliff = $dom->appendChild($dom->createElement('xliff'));
     $xliff->setAttribute('version', '1.2');
     $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
     $xliffFile = $xliff->appendChild($dom->createElement('file'));
     $xliffFile->setAttribute('source-language', $messages->getLocale());
     $xliffFile->setAttribute('datatype', 'plaintext');
     $xliffFile->setAttribute('original', 'file.ext');
     $xliffBody = $xliffFile->appendChild($dom->createElement('body'));
     foreach ($messages->all($domain) as $source => $target) {
         $translation = $dom->createElement('trans-unit');
         $translation->setAttribute('id', md5($source));
         $translation->setAttribute('resname', $source);
         $s = $translation->appendChild($dom->createElement('source'));
         $s->appendChild($dom->createTextNode($source));
         // Does the target contain characters requiring a CDATA section?
         $text = 1 === preg_match('/[&<>]/', $target) ? $dom->createCDATASection($target) : $dom->createTextNode($target);
         $t = $translation->appendChild($dom->createElement('target'));
         $t->appendChild($text);
         $xliffBody->appendChild($translation);
     }
     return $dom->saveXML();
 }
开发者ID:kchhainarong,项目名称:chantuchP,代码行数:29,代码来源:XliffFileDumper.php

示例12: load

 /**
  * Load translations and metadata of the trans-unit.
  *
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     /* @var MessageCatalogue $catalogue */
     $base_catalogue = parent::load($resource, $locale, $domain);
     $catalogue = new MessageCatalogue($locale);
     $catalogue->addCatalogue($base_catalogue);
     // Process a second pass over the file to collect metadata
     $xml = simplexml_load_file($resource);
     $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
     foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
         // Read the attributes
         $attributes = (array) $translation->attributes();
         $attributes = $attributes['@attributes'];
         if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) {
             continue;
         }
         $key = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
         $metadata = (array) $attributes;
         // read the notes
         if (isset($translation->note)) {
             $metadata['note'] = (string) $translation->note;
         }
         $catalogue->setMetadata((string) $key, $metadata, $domain);
     }
     return $catalogue;
 }
开发者ID:migros,项目名称:LiipTranslationBundle,代码行数:33,代码来源:XliffFileLoader.php

示例13: getDatabaseCatalogue

 private function getDatabaseCatalogue()
 {
     $databaseCatalogue = new MessageCatalogue(self::FAKE_LOCALE);
     $messages = array('baz' => 'Baz is updated !');
     $databaseCatalogue->add($messages, 'messages');
     return $databaseCatalogue;
 }
开发者ID:M03G,项目名称:PrestaShop,代码行数:7,代码来源:ThemeTranslationsFactoryTest.php

示例14: testTargetAttributesMetadataIsSetInFile

    public function testTargetAttributesMetadataIsSetInFile()
    {
        $catalogue = new MessageCatalogue('en_US');
        $catalogue->add(array('foo' => 'bar'));
        $catalogue->setMetadata('foo', array('target-attributes' => array('state' => 'needs-translation')));
        $tempDir = sys_get_temp_dir();
        $dumper = new XliffFileDumper();
        $dumper->dump($catalogue, array('path' => $tempDir, 'default_locale' => 'fr_FR'));
        $content = <<<EOT
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
  <file source-language="fr-FR" target-language="en-US" datatype="plaintext" original="file.ext">
    <body>
      <trans-unit id="acbd18db4cc2f85cedef654fccc4a4d8" resname="foo">
        <source>foo</source>
        <target state="needs-translation">bar</target>
      </trans-unit>
    </body>
  </file>
</xliff>

EOT;
        $this->assertEquals($content, file_get_contents($tempDir . '/messages.en_US.xlf'));
        unlink($tempDir . '/messages.en_US.xlf');
    }
开发者ID:Nakard,项目名称:symfony,代码行数:25,代码来源:XliffFileDumperTest.php

示例15: format

 /**
  * {@inheritdoc}
  */
 protected function format(MessageCatalogue $messages, $domain)
 {
     if (!class_exists('Symfony\\Component\\Yaml\\Yaml')) {
         throw new \LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
     }
     return Yaml::dump($messages->all($domain));
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:10,代码来源:YamlFileDumper.php


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