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


PHP MessageCatalogue::add方法代码示例

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


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

示例1: testAdd

 public function testAdd()
 {
     $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
     $catalogue->add(array('foo1' => 'foo1'), 'domain1');
     $this->assertEquals('foo', $catalogue->get('foo', 'domain1'));
     $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
     $catalogue->add(array('foo' => 'bar'), 'domain1');
     $this->assertEquals('bar', $catalogue->get('foo', 'domain1'));
     $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
     $catalogue->add(array('foo' => 'bar'), 'domain88');
     $this->assertEquals('bar', $catalogue->get('foo', 'domain88'));
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:12,代码来源:MessageCatalogueTest.php

示例2: writeTranslationsByModule

 public function writeTranslationsByModule($module, $messages)
 {
     $currentMessages = $this->getMessagesByModule($module);
     $language = 'en';
     $resource = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . '/config/translations/';
     $messageCatalogue = new MessageCatalogue($language);
     if ($currentMessages && $currentMessages['messages']) {
         $messageCatalogue->add($currentMessages['messages'], 'console');
     }
     $messageCatalogue->add($messages, 'console');
     $translatorWriter = new TranslationWriter();
     $translatorWriter->addDumper('yaml', new YamlFileDumper());
     $translatorWriter->writeTranslations($messageCatalogue, 'yaml', ['path' => $resource, 'nest-level' => 10, 'indent' => 2]);
 }
开发者ID:xsw3ws,项目名称:DrupalConsole,代码行数:14,代码来源:TranslatorHelper.php

示例3: 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

示例4: load

 /**
  * Loads a locale.
  *
  * @param mixed $resource A resource
  * @param string $locale   A locale
  * @param string $domain   The domain
  *
  * @return MessageCatalogue A MessageCatalogue instance
  *
  * @throws NotFoundResourceException when the resource cannot be found
  * @throws InvalidResourceException  when the resource cannot be loaded
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $translations = $this->translationRepo->kvByLocaleAndDomain($locale, $domain);
     $catalogue = new MessageCatalogue($locale);
     $catalogue->add($translations, $domain);
     return $catalogue;
 }
开发者ID:scottstuff,项目名称:GCProtractorJS,代码行数:19,代码来源:TranslationORMLoader.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: load

 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $this->flatten($resource);
     $catalogue = new MessageCatalogue($locale);
     $catalogue->add($resource, $domain);
     return $catalogue;
 }
开发者ID:roberto-sanchez,项目名称:gardencentral,代码行数:12,代码来源:ArrayLoader.php

示例7: testFormatCatalogue

 public function testFormatCatalogue()
 {
     $catalogue = new MessageCatalogue('en');
     $catalogue->add(array('foo' => 'bar'), 'resources');
     $dumper = new QtFileDumper();
     $this->assertStringEqualsFile(__DIR__ . '/../fixtures/resources.ts', $dumper->formatCatalogue($catalogue, 'resources'));
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:7,代码来源:QtFileDumperTest.php

示例8: load

 /**
  *
  * {@inheritdoc}
  *
  */
 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 (!is_dir($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     try {
         $rb = new \ResourceBundle($locale, $resource);
     } catch (\Exception $e) {
         // HHVM compatibility: constructor throws on invalid resource
         $rb = null;
     }
     if (!$rb) {
         throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
     } elseif (intl_is_failure($rb->getErrorCode())) {
         throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode());
     }
     $messages = $this->flatten($rb);
     $catalogue = new MessageCatalogue($locale);
     $catalogue->add($messages, $domain);
     if (class_exists('Symfony\\Component\\Config\\Resource\\DirectoryResource')) {
         $catalogue->addResource(new DirectoryResource($resource));
     }
     return $catalogue;
 }
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:32,代码来源:IcuResFileLoader.php

示例9: 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

示例10: 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

示例11: load

 /**
  * {@inheritDoc}
  * @see \Symfony\Component\Translation\Loader\LoaderInterface::load()
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $repo = $this->service->getResourceRepository();
     if (!$repo->contains($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     // find file in puli repo
     $file = $repo->get($resource);
     $json = $file->getBody();
     $data = Json::decode($json);
     $messages = [];
     // flatten plural strings
     foreach ($data as $key => $value) {
         if (is_array($value)) {
             $vals = [];
             foreach ($value as $k => $v) {
                 $vals[] = sprintf('%s: %s', $k, $v);
             }
             $val = implode('|', $vals);
         } else {
             $val = $value;
         }
         $messages[$key] = str_replace(['{{', '}}'], '%', $val);
     }
     // put them into message catalog
     $catalogue = new MessageCatalogue($locale);
     $catalogue->add($messages, $domain);
     return $catalogue;
 }
开发者ID:keeko,项目名称:framework,代码行数:33,代码来源:KeekoJsonTranslationLoader.php

示例12: testLoadWithMetadata

 public function testLoadWithMetadata()
 {
     $expected = new MessageCatalogue('en');
     $expected->add(array('foo' => 'bar'));
     $file = $this->getInputFile('with_metadata');
     $expected->addResource(new FileResource($file));
     $this->assertEquals($expected, $this->load($file));
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:8,代码来源:BaseLoaderTest.php

示例13: testDump

 public function testDump()
 {
     $catalogue = new MessageCatalogue('en');
     $catalogue->add(array('foo' => 'bar'), 'resources');
     $dumper = new QtTranslationsDumper();
     $dumperString = $dumper->dump($catalogue, 'resources');
     $this->assertEquals(file_get_contents(__DIR__ . '/../fixtures/resources.ts'), $dumperString);
 }
开发者ID:nizam-uddin,项目名称:symfony,代码行数:8,代码来源:QtDumperTest.php

示例14: testFormatCatalogue

    public function testFormatCatalogue()
    {
        $catalogue = new MessageCatalogue('en');
        $catalogue->add(array('foo' => 'bar', 'bar' => 'foo
foo', 'foo;foo' => 'bar'));
        $dumper = new CsvFileDumper();
        $this->assertStringEqualsFile(__DIR__ . '/../fixtures/valid.csv', $dumper->formatCatalogue($catalogue, 'messages'));
    }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:8,代码来源:CsvFileDumperTest.php

示例15: testLoadOldFormat

 public function testLoadOldFormat()
 {
     $expected = new MessageCatalogue('en');
     $expected->add(array('foo1' => 'bar', 'foo2' => 'bar', 'foo3' => 'bar', 'foo4' => 'bar'));
     $file = __DIR__ . '/xliff/old_format.xml';
     $expected->addResource(new FileResource($file));
     $this->assertEquals($expected, $this->getLoader()->load($file, 'en'));
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:8,代码来源:XliffLoaderTest.php


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