[Translation] Add support for calling 'trans' with ICU formatted messages
This commit is contained in:
parent
27bb2828e3
commit
d2ec41f4ef
@ -4,6 +4,7 @@ CHANGELOG
|
|||||||
5.2.0
|
5.2.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
* added support for calling `trans` with ICU formatted messages
|
||||||
* added `PseudoLocalizationTranslator`
|
* added `PseudoLocalizationTranslator`
|
||||||
|
|
||||||
5.1.0
|
5.1.0
|
||||||
|
@ -368,6 +368,14 @@ class TranslatorTest extends TestCase
|
|||||||
$this->assertEquals($expected, $translator->trans($id, $parameters, $domain, $locale));
|
$this->assertEquals($expected, $translator->trans($id, $parameters, $domain, $locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getTransICUTests
|
||||||
|
*/
|
||||||
|
public function testTransICU(...$args)
|
||||||
|
{
|
||||||
|
$this->testTrans(...$args);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getInvalidLocalesTests
|
* @dataProvider getInvalidLocalesTests
|
||||||
*/
|
*/
|
||||||
@ -444,6 +452,17 @@ class TranslatorTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
public function getFlattenedTransTests()
|
||||||
{
|
{
|
||||||
$messages = [
|
$messages = [
|
||||||
|
@ -214,7 +214,10 @@ class Translator implements TranslatorInterface, TranslatorBagInterface, LocaleA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
return $this->formatter->formatIntl($catalogue->get($id, $domain), $locale, $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user