Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Translation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
5.2.0
-----

* added support for calling `trans` with ICU formatted messages
* added `PseudoLocalizationTranslator`

5.1.0
Expand Down
19 changes: 19 additions & 0 deletions src/Symfony/Component/Translation/Tests/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ public function testTrans($expected, $id, $translation, $parameters, $locale, $d
$this->assertEquals($expected, $translator->trans($id, $parameters, $domain, $locale));
}

/**
* @dataProvider getTransICUTests
*/
public function testTransICU(...$args)
{
$this->testTrans(...$args);
}

/**
* @dataProvider getInvalidLocalesTests
*/
Expand Down Expand Up @@ -444,6 +452,17 @@ public function getTransTests()
];
}

public function getTransICUTests()
{
$id = '{apples, plural, =0 {There are no apples} one {There is one apple} other {There are # apples}}';

return [
['There are no apples', $id, $id, ['{apples}' => 0], 'en', 'test'.MessageCatalogue::INTL_DOMAIN_SUFFIX],
['There is one apple', $id, $id, ['{apples}' => 1], 'en', 'test'.MessageCatalogue::INTL_DOMAIN_SUFFIX],
['There are 3 apples', $id, $id, ['{apples}' => 3], 'en', 'test'.MessageCatalogue::INTL_DOMAIN_SUFFIX],
];
}

public function getFlattenedTransTests()
{
$messages = [
Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ public function trans(?string $id, array $parameters = [], string $domain = null
}
}

if ($this->hasIntlFormatter && $catalogue->defines($id, $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX)) {
$len = \strlen(MessageCatalogue::INTL_DOMAIN_SUFFIX);
if ($this->hasIntlFormatter
&& ($catalogue->defines($id, $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX)
|| 0 == substr_compare($domain, MessageCatalogue::INTL_DOMAIN_SUFFIX, -$len, $len))) {
return $this->formatter->formatIntl($catalogue->get($id, $domain), $locale, $parameters);
}

Expand Down