|
|
@@ -65,11 +65,12 @@ class I18nTest extends TestCase
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testDefaultTranslator()
|
|
|
+ public function testGetDefaultTranslator()
|
|
|
{
|
|
|
- $translator = I18n::translator();
|
|
|
+ $translator = I18n::getTranslator();
|
|
|
$this->assertInstanceOf('Aura\Intl\TranslatorInterface', $translator);
|
|
|
$this->assertEquals('%d is 1 (po translated)', $translator->translate('%d = 1'));
|
|
|
+ $this->assertSame($translator, I18n::translator(), 'backwards compat works');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -77,9 +78,9 @@ class I18nTest extends TestCase
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testTranslatorLoadMoFile()
|
|
|
+ public function testGetTranslatorLoadMoFile()
|
|
|
{
|
|
|
- $translator = I18n::translator('default', 'es_ES');
|
|
|
+ $translator = I18n::getTranslator('default', 'es_ES');
|
|
|
$this->assertEquals('Plural Rule 6 (translated)', $translator->translate('Plural Rule 1'));
|
|
|
}
|
|
|
|
|
|
@@ -92,7 +93,7 @@ class I18nTest extends TestCase
|
|
|
public function testPluralSelection()
|
|
|
{
|
|
|
I18n::defaultFormatter('sprintf');
|
|
|
- $translator = I18n::translator(); // en_US
|
|
|
+ $translator = I18n::getTranslator(); // en_US
|
|
|
$result = $translator->translate('%d = 0 or > 1', ['_count' => 1]);
|
|
|
$this->assertEquals('1 is 1 (po translated)', $result);
|
|
|
|
|
|
@@ -108,7 +109,7 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testPluralSelectionBasicFormatter()
|
|
|
{
|
|
|
- $translator = I18n::translator('special');
|
|
|
+ $translator = I18n::getTranslator('special');
|
|
|
$result = $translator->translate('There are {0} things', ['_count' => 2, 'plenty']);
|
|
|
$this->assertEquals('There are plenty things', $result);
|
|
|
|
|
|
@@ -123,7 +124,7 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testPluralSelectionRussian()
|
|
|
{
|
|
|
- $translator = I18n::translator('default', 'ru');
|
|
|
+ $translator = I18n::getTranslator('default', 'ru');
|
|
|
$result = $translator->translate('{0} months', ['_count' => 1, 1]);
|
|
|
$this->assertEquals('1 months ends in 1, not 11', $result);
|
|
|
|
|
|
@@ -141,16 +142,16 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testCreateCustomTranslationPackage()
|
|
|
{
|
|
|
- I18n::translator('custom', 'fr_FR', function () {
|
|
|
+ I18n::setTranslator('custom', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages([
|
|
|
'Cow' => 'Le moo'
|
|
|
]);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'fr_FR');
|
|
|
|
|
|
- $translator = I18n::translator('custom', 'fr_FR');
|
|
|
+ $translator = I18n::getTranslator('custom', 'fr_FR');
|
|
|
$this->assertEquals('Le moo', $translator->translate('Cow'));
|
|
|
}
|
|
|
|
|
|
@@ -167,13 +168,13 @@ class I18nTest extends TestCase
|
|
|
'Company/TestPluginThree'
|
|
|
]);
|
|
|
|
|
|
- $translator = I18n::translator('test_plugin');
|
|
|
+ $translator = I18n::getTranslator('test_plugin');
|
|
|
$this->assertEquals(
|
|
|
'Plural Rule 1 (from plugin)',
|
|
|
$translator->translate('Plural Rule 1')
|
|
|
);
|
|
|
|
|
|
- $translator = I18n::translator('company/test_plugin_three');
|
|
|
+ $translator = I18n::getTranslator('company/test_plugin_three');
|
|
|
$this->assertEquals(
|
|
|
'String 1 (from plugin three)',
|
|
|
$translator->translate('String 1')
|
|
|
@@ -189,7 +190,7 @@ class I18nTest extends TestCase
|
|
|
public function testPluginOverride()
|
|
|
{
|
|
|
Plugin::load('TestTheme');
|
|
|
- $translator = I18n::translator('test_theme');
|
|
|
+ $translator = I18n::getTranslator('test_theme');
|
|
|
$this->assertEquals(
|
|
|
'translated',
|
|
|
$translator->translate('A Message')
|
|
|
@@ -218,17 +219,17 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testGetTranslatorByDefaultLocale()
|
|
|
{
|
|
|
- I18n::translator('custom', 'fr_FR', function () {
|
|
|
+ I18n::setTranslator('custom', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages([
|
|
|
'Cow' => 'Le moo'
|
|
|
]);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'fr_FR');
|
|
|
|
|
|
I18n::locale('fr_FR');
|
|
|
- $translator = I18n::translator('custom');
|
|
|
+ $translator = I18n::getTranslator('custom');
|
|
|
$this->assertEquals('Le moo', $translator->translate('Cow'));
|
|
|
}
|
|
|
|
|
|
@@ -318,7 +319,7 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testBasicDomainFunction()
|
|
|
{
|
|
|
- I18n::translator('custom', 'en_US', function () {
|
|
|
+ I18n::setTranslator('custom', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages([
|
|
|
'Cow' => 'Le moo',
|
|
|
@@ -327,7 +328,7 @@ class I18nTest extends TestCase
|
|
|
]);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'en_US');
|
|
|
$this->assertEquals('Le moo', __d('custom', 'Cow'));
|
|
|
|
|
|
$result = __d('custom', 'The {0} is tasty', ['fruit']);
|
|
|
@@ -347,7 +348,7 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testBasicDomainPluralFunction()
|
|
|
{
|
|
|
- I18n::translator('custom', 'en_US', function () {
|
|
|
+ I18n::setTranslator('custom', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages([
|
|
|
'Cow' => 'Le Moo',
|
|
|
@@ -358,7 +359,7 @@ class I18nTest extends TestCase
|
|
|
]);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'en_US');
|
|
|
$this->assertEquals('Le Moo', __dn('custom', 'Cow', 'Cows', 1));
|
|
|
$this->assertEquals('Les Moos', __dn('custom', 'Cow', 'Cows', 2));
|
|
|
}
|
|
|
@@ -370,7 +371,7 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testBasicContextFunction()
|
|
|
{
|
|
|
- I18n::translator('default', 'en_US', function () {
|
|
|
+ I18n::setTranslator('default', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages([
|
|
|
'letter' => [
|
|
|
@@ -394,7 +395,7 @@ class I18nTest extends TestCase
|
|
|
]);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'en_US');
|
|
|
|
|
|
$this->assertEquals('The letters A and B', __x('character', 'letters', ['A', 'B']));
|
|
|
$this->assertEquals('The letter A', __x('character', 'letter', ['A']));
|
|
|
@@ -428,7 +429,7 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testBasicContextFunctionNoString()
|
|
|
{
|
|
|
- I18n::translator('default', 'en_US', function () {
|
|
|
+ I18n::setTranslator('default', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages([
|
|
|
'letter' => [
|
|
|
@@ -439,7 +440,7 @@ class I18nTest extends TestCase
|
|
|
]);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'en_US');
|
|
|
|
|
|
$this->assertEquals('', __x('character', 'letter'));
|
|
|
}
|
|
|
@@ -451,7 +452,7 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testBasicContextFunctionInvalidContext()
|
|
|
{
|
|
|
- I18n::translator('default', 'en_US', function () {
|
|
|
+ I18n::setTranslator('default', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages([
|
|
|
'letter' => [
|
|
|
@@ -462,7 +463,7 @@ class I18nTest extends TestCase
|
|
|
]);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'en_US');
|
|
|
|
|
|
$this->assertEquals('letter', __x('garbage', 'letter'));
|
|
|
$this->assertEquals('a paper letter', __('letter'));
|
|
|
@@ -475,7 +476,7 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testPluralContextFunction()
|
|
|
{
|
|
|
- I18n::translator('default', 'en_US', function () {
|
|
|
+ I18n::setTranslator('default', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages([
|
|
|
'letter' => [
|
|
|
@@ -499,7 +500,7 @@ class I18nTest extends TestCase
|
|
|
]);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'en_US');
|
|
|
$this->assertEquals('The letters A and B', __xn('character', 'letter', 'letters', 2, ['A', 'B']));
|
|
|
$this->assertEquals('The letter A', __xn('character', 'letter', 'letters', 1, ['A']));
|
|
|
|
|
|
@@ -529,7 +530,7 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testDomainContextFunction()
|
|
|
{
|
|
|
- I18n::translator('custom', 'en_US', function () {
|
|
|
+ I18n::setTranslator('custom', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages([
|
|
|
'letter' => [
|
|
|
@@ -553,7 +554,7 @@ class I18nTest extends TestCase
|
|
|
]);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'en_US');
|
|
|
|
|
|
$this->assertEquals('The letters A and B', __dx('custom', 'character', 'letters', ['A', 'B']));
|
|
|
$this->assertEquals('The letter A', __dx('custom', 'character', 'letter', ['A']));
|
|
|
@@ -584,7 +585,7 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testDomainPluralContextFunction()
|
|
|
{
|
|
|
- I18n::translator('custom', 'en_US', function () {
|
|
|
+ I18n::setTranslator('custom', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages([
|
|
|
'letter' => [
|
|
|
@@ -608,7 +609,7 @@ class I18nTest extends TestCase
|
|
|
]);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'en_US');
|
|
|
$this->assertEquals(
|
|
|
'The letters A and B',
|
|
|
__dxn('custom', 'character', 'letter', 'letters', 2, ['A', 'B'])
|
|
|
@@ -644,8 +645,8 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testTranslatorCache()
|
|
|
{
|
|
|
- $english = I18n::translator();
|
|
|
- $spanish = I18n::translator('default', 'es_ES');
|
|
|
+ $english = I18n::getTranslator();
|
|
|
+ $spanish = I18n::getTranslator('default', 'es_ES');
|
|
|
|
|
|
$cached = Cache::read('translations.default.en_US', '_cake_core_');
|
|
|
$this->assertEquals($english, $cached);
|
|
|
@@ -653,9 +654,9 @@ class I18nTest extends TestCase
|
|
|
$cached = Cache::read('translations.default.es_ES', '_cake_core_');
|
|
|
$this->assertEquals($spanish, $cached);
|
|
|
|
|
|
- $this->assertSame($english, I18n::translator());
|
|
|
- $this->assertSame($spanish, I18n::translator('default', 'es_ES'));
|
|
|
- $this->assertSame($english, I18n::translator());
|
|
|
+ $this->assertSame($english, I18n::getTranslator());
|
|
|
+ $this->assertSame($spanish, I18n::getTranslator('default', 'es_ES'));
|
|
|
+ $this->assertSame($english, I18n::getTranslator());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -693,15 +694,15 @@ class I18nTest extends TestCase
|
|
|
return $package;
|
|
|
});
|
|
|
|
|
|
- $translator = I18n::translator('custom', 'fr_FR');
|
|
|
+ $translator = I18n::getTranslator('custom', 'fr_FR');
|
|
|
$this->assertEquals('Le Moo', $translator->translate('Cow'));
|
|
|
$this->assertEquals('Les Moos', $translator->translate('Cows', ['_count' => 2]));
|
|
|
|
|
|
- $translator = I18n::translator('custom', 'es_ES');
|
|
|
+ $translator = I18n::getTranslator('custom', 'es_ES');
|
|
|
$this->assertEquals('El Moo', $translator->translate('Cow'));
|
|
|
$this->assertEquals('Los Moos', $translator->translate('Cows', ['_count' => 2]));
|
|
|
|
|
|
- $translator = I18n::translator();
|
|
|
+ $translator = I18n::getTranslator();
|
|
|
$this->assertEquals('%d is 1 (po translated)', $translator->translate('%d = 1'));
|
|
|
}
|
|
|
|
|
|
@@ -728,10 +729,10 @@ class I18nTest extends TestCase
|
|
|
return $package;
|
|
|
});
|
|
|
|
|
|
- $translator = I18n::translator('custom');
|
|
|
+ $translator = I18n::getTranslator('custom');
|
|
|
$this->assertEquals('Le Moo custom', $translator->translate('Cow'));
|
|
|
|
|
|
- $translator = I18n::translator();
|
|
|
+ $translator = I18n::getTranslator();
|
|
|
$this->assertEquals('Le Moo default', $translator->translate('Cow'));
|
|
|
}
|
|
|
|
|
|
@@ -742,25 +743,25 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testFallbackTranslator()
|
|
|
{
|
|
|
- I18n::translator('default', 'fr_FR', function () {
|
|
|
+ I18n::setTranslator('default', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages([
|
|
|
'Dog' => 'Le bark'
|
|
|
]);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'fr_FR');
|
|
|
|
|
|
- I18n::translator('custom', 'fr_FR', function () {
|
|
|
+ I18n::setTranslator('custom', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages([
|
|
|
'Cow' => 'Le moo'
|
|
|
]);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'fr_FR');
|
|
|
|
|
|
- $translator = I18n::translator('custom', 'fr_FR');
|
|
|
+ $translator = I18n::getTranslator('custom', 'fr_FR');
|
|
|
$this->assertEquals('Le moo', $translator->translate('Cow'));
|
|
|
$this->assertEquals('Le bark', $translator->translate('Dog'));
|
|
|
}
|
|
|
@@ -774,21 +775,21 @@ class I18nTest extends TestCase
|
|
|
{
|
|
|
I18n::useFallback(false);
|
|
|
|
|
|
- I18n::translator('default', 'fr_FR', function () {
|
|
|
+ I18n::setTranslator('default', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages(['Dog' => 'Le bark']);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'fr_FR');
|
|
|
|
|
|
- I18n::translator('custom', 'fr_FR', function () {
|
|
|
+ I18n::setTranslator('custom', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages(['Cow' => 'Le moo']);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'fr_FR');
|
|
|
|
|
|
- $translator = I18n::translator('custom', 'fr_FR');
|
|
|
+ $translator = I18n::getTranslator('custom', 'fr_FR');
|
|
|
$this->assertEquals('Le moo', $translator->translate('Cow'));
|
|
|
$this->assertEquals('Dog', $translator->translate('Dog'));
|
|
|
}
|
|
|
@@ -801,14 +802,14 @@ class I18nTest extends TestCase
|
|
|
*/
|
|
|
public function testFallbackTranslatorWithFactory()
|
|
|
{
|
|
|
- I18n::translator('default', 'fr_FR', function () {
|
|
|
+ I18n::setTranslator('default', function () {
|
|
|
$package = new Package('default');
|
|
|
$package->setMessages([
|
|
|
'Dog' => 'Le bark'
|
|
|
]);
|
|
|
|
|
|
return $package;
|
|
|
- });
|
|
|
+ }, 'fr_FR');
|
|
|
I18n::config('custom', function ($name, $locale) {
|
|
|
$this->assertEquals('custom', $name);
|
|
|
$package = new Package('default');
|
|
|
@@ -819,7 +820,7 @@ class I18nTest extends TestCase
|
|
|
return $package;
|
|
|
});
|
|
|
|
|
|
- $translator = I18n::translator('custom', 'fr_FR');
|
|
|
+ $translator = I18n::getTranslator('custom', 'fr_FR');
|
|
|
$this->assertEquals('Le moo', $translator->translate('Cow'));
|
|
|
$this->assertEquals('Le bark', $translator->translate('Dog'));
|
|
|
}
|