From 7478f5c622cb7cd6f3161c44ea36cf92c972ce8c Mon Sep 17 00:00:00 2001 From: Michal Lulco Date: Fri, 19 Feb 2021 20:45:04 +0100 Subject: [PATCH] Fix translation of messages with dot at the end (#181) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix translation of messages with dot at the end * Fixed mixed indentations * Fixed syntax error in test * Rerun travis * Fix Closure::fromCallable + coding standards * Dot cannot be at last position * Update src/Translator.php Co-authored-by: Jáchym Toušek Co-authored-by: Jáchym Toušek --- src/Translator.php | 2 +- tests/KdybyTests/Translation/TranslatorTest.phpt | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Translator.php b/src/Translator.php index c47a5e6c..d10ef4eb 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -435,7 +435,7 @@ protected function assertValidLocale($locale) */ private function extractMessageDomain($message) { - if (strpos($message, '.') !== FALSE && strpos($message, ' ') === FALSE) { + if (strpos(substr($message, 0, -1), '.') !== FALSE && strpos($message, ' ') === FALSE) { list($domain, $message) = explode('.', $message, 2); } else { diff --git a/tests/KdybyTests/Translation/TranslatorTest.phpt b/tests/KdybyTests/Translation/TranslatorTest.phpt index 97f54c49..d6e0cb00 100644 --- a/tests/KdybyTests/Translation/TranslatorTest.phpt +++ b/tests/KdybyTests/Translation/TranslatorTest.phpt @@ -157,6 +157,13 @@ class TranslatorTest extends \KdybyTests\Translation\TestCase Assert::same('Hello world', $translator->translate('Hello %value%', ['value' => 'world'])); } + public function testBugMessageWithDotAtTheEnd() + { + $translator = $this->createTranslator(); + Assert::same('Hello.', $translator->translate('Hello.')); + Assert::same('Hello world.', $translator->translate('Hello world.')); + } + } (new TranslatorTest())->run();