本文整理汇总了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'));
}
示例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]);
}
示例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)));
}
示例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;
}
示例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'));
}
示例6: load
/**
* {@inheritdoc}
*
* @api
*/
public function load($resource, $locale, $domain = 'messages')
{
$this->flatten($resource);
$catalogue = new MessageCatalogue($locale);
$catalogue->add($resource, $domain);
return $catalogue;
}
示例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'));
}
示例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;
}
示例9: getDatabaseCatalogue
private function getDatabaseCatalogue()
{
$databaseCatalogue = new MessageCatalogue(self::FAKE_LOCALE);
$messages = array('baz' => 'Baz is updated !');
$databaseCatalogue->add($messages, 'messages');
return $databaseCatalogue;
}
示例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');
}
示例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;
}
示例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));
}
示例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);
}
示例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'));
}
示例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'));
}