diff --git a/framework/core/js/tests/unit/common/utils/Translator.test.ts b/framework/core/js/tests/unit/common/utils/Translator.test.ts index 4983d60993..0d94610e34 100644 --- a/framework/core/js/tests/unit/common/utils/Translator.test.ts +++ b/framework/core/js/tests/unit/common/utils/Translator.test.ts @@ -14,8 +14,8 @@ test('placeholders encoding', () => { 'test2': 'test2 {placeholder} test2', }); - expect(extractText(translator.trans('test1', {'{placeholder}': "'"}))).toBe("test1 ' test1"); - expect(extractText(translator.trans('test1', {'{placeholder}': translator.trans('test2', {'{placeholder}': "'"})}))).toBe("test1 test2 ' test2 test1"); + expect(extractText(translator.trans('test1', {'placeholder': "'"}))).toBe("test1 ' test1"); + expect(extractText(translator.trans('test1', {'placeholder': translator.trans('test2', {'placeholder': "'"})}))).toBe("test1 test2 ' test2 test1"); }); test('missing placeholders', () => { @@ -48,3 +48,16 @@ test('plural rules', () => { expect(extractText(translator.trans('test4', {forumName: 'A & B', pageNumber: 1}))).toBe('A & B'); expect(extractText(translator.trans('test4', {forumName: 'A & B', pageNumber: 2}))).toBe('Page 2 - A & B'); }); + +test('plural rules 2', () => { + const translator = new Translator(); + translator.setLocale('pl'); + translator.addTranslations({ + 'test5': '{count, plural, one {# post} few {# posty} many {# postów} other {# posta}}', + }); + + expect(extractText(translator.trans('test5', {count: 1}))).toBe('1 post'); + expect(extractText(translator.trans('test5', {count: 2}))).toBe('2 posty'); + expect(extractText(translator.trans('test5', {count: 5}))).toBe('5 postów'); + expect(extractText(translator.trans('test5', {count: 1.5}))).toBe('1,5 posta'); +}); diff --git a/framework/core/tests/unit/Locale/TranslatorTest.php b/framework/core/tests/unit/Locale/TranslatorTest.php index 86057f6297..8fb63bb7b6 100644 --- a/framework/core/tests/unit/Locale/TranslatorTest.php +++ b/framework/core/tests/unit/Locale/TranslatorTest.php @@ -73,4 +73,19 @@ public function plural_rules() $this->assertSame('A & B', $translator->trans('test4', ['forumName' => 'A & B', 'pageNumber' => 1])); $this->assertSame('Page 2 - A & B', $translator->trans('test4', ['forumName' => 'A & B', 'pageNumber' => 2])); } + + /** @test */ + public function plural_rules_2() + { + $translator = new Translator('pl'); + $translator->addLoader('array', new ArrayLoader()); + $translator->addResource('array', [ + 'test4' => '{count, plural, one {# post} few {# posty} many {# postów} other {# posta}}', + ], 'pl', self::DOMAIN); + + $this->assertSame('1 post', $translator->trans('test4', ['count' => 1])); + $this->assertSame('2 posty', $translator->trans('test4', ['count' => 2])); + $this->assertSame('5 postów', $translator->trans('test4', ['count' => 5])); + $this->assertSame('1,5 posta', $translator->trans('test4', ['count' => 1.5])); + } }