Skip to content

Commit

Permalink
Fix translation of messages with dot at the end (#181)
Browse files Browse the repository at this point in the history
* 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 <enumag@gmail.com>

Co-authored-by: Jáchym Toušek <enumag@gmail.com>
  • Loading branch information
lulco and enumag committed Feb 19, 2021
1 parent 3adb0d8 commit 57124c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Translator.php
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions tests/KdybyTests/Translation/TranslatorTest.phpt
Expand Up @@ -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();

0 comments on commit 57124c2

Please sign in to comment.