From d9bc6908c225c8a640f3e7803a6cef0f5ab943a5 Mon Sep 17 00:00:00 2001 From: Sylvain PRAS Date: Sat, 3 Jul 2021 16:46:32 +0200 Subject: [PATCH] Fix get_message on intl_icu if domain is undefined (#314) --- Resources/js/translator.js | 2 +- Resources/js/translatorTest.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Resources/js/translator.js b/Resources/js/translator.js index 7a78f20c..0bb2a772 100644 --- a/Resources/js/translator.js +++ b/Resources/js/translator.js @@ -291,7 +291,7 @@ if (has_message(_locale, _domains[i], id) || has_message(nationalLocaleFallback, _domains[i], id) || has_message(localeFallback, _domains[i], id)) { - _domain = _domains[i]; + _domain = _domains[i].replace(INTL_DOMAIN_SUFFIX, ''); break; } diff --git a/Resources/js/translatorTest.js b/Resources/js/translatorTest.js index 5a86efef..69274207 100644 --- a/Resources/js/translatorTest.js +++ b/Resources/js/translatorTest.js @@ -21,7 +21,7 @@ test('add()', function() { }); test('trans()', function() { - expect(14); + expect(17); Translator.add('foo', 'bar', 'Foo'); Translator.add('foo.with.arg', 'This is Ba %arg%'); @@ -57,6 +57,11 @@ test('trans()', function() { equal(Translator.trans('messages.with.args', { name: 'John', projectCount: 0 }, 'messages'), 'John has no projects.', 'Returns the ICU-formatted message with correct replaces.'); equal(Translator.trans('messages.with.args', { name: 'John', projectCount: 1 }, 'messages'), 'John has 1 project.', 'Returns the ICU-formatted message with correct replaces.'); equal(Translator.trans('messages.with.args', { name: 'John', projectCount: 4 }, 'messages'), 'John has 4 projects.', 'Returns the ICU-formatted message with correct replaces.'); + + equal(Translator.trans('messages.with.args', { name: 'John', projectCount: 0 }), 'John has no projects.', 'Returns the ICU-formatted message with correct replaces.'); + equal(Translator.trans('messages.with.args', { name: 'John', projectCount: 1 }), 'John has 1 project.', 'Returns the ICU-formatted message with correct replaces.'); + equal(Translator.trans('messages.with.args', { name: 'John', projectCount: 4 }), 'John has 4 projects.', 'Returns the ICU-formatted message with correct replaces.'); + }); test('transChoice()', function() {