Skip to content

Commit

Permalink
Fix translation of messages with dot at the end (Kdyby#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
2 people authored and Jirka Hrazdil committed Apr 27, 2022
1 parent d0785b8 commit 7478f5c
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 7478f5c

Please sign in to comment.