當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。