From d10fe2336671905c8529095c896031a56dbe1b29 Mon Sep 17 00:00:00 2001 From: Luca Date: Thu, 24 Oct 2019 09:53:20 +0200 Subject: [PATCH 1/4] Fix X-Poedit-Basepath for de_DE locale Configure Poedit to correctly interpret the keyword _e --- resources/lang/de_DE/default.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 8dba9b4b..b3184f41 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -10,8 +10,8 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Poedit 1.8.11\n" -"X-Poedit-KeywordsList: __;_e;translate;translatePlural\n" -"X-Poedit-Basepath: ../../../..\n" +"X-Poedit-KeywordsList: __;_e:1,2;translate;translatePlural\n" +"X-Poedit-Basepath: ../../..\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Poedit-SourceCharset: UTF-8\n" "X-Poedit-SearchPath-0: resources/views\n" From 6cde313e47cd08216ff15d733c8de894f2657a8b Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 25 Oct 2019 09:33:09 +0200 Subject: [PATCH 2/4] Move translations whose message ids do not appear as literals in the sources into a separate file Test whether additional.{m,p}o files are loaded correctly --- resources/lang/de_DE/additional.po | 36 ++++++++++++++++++ resources/lang/de_DE/default.po | 29 ++------------ resources/lang/en_US/additional.po | 34 +++++++++++++++++ resources/lang/en_US/default.po | 24 ------------ .../TranslationServiceProvider.php | 18 +++++---- .../Translation/Assets/ba_RR/additional.po | 3 ++ .../Translation/Assets/fo_OO/additional.mo | Bin 0 -> 93 bytes .../Translation/Assets/fo_OO/additional.po | 3 ++ .../TranslationServiceProviderTest.php | 7 +++- 9 files changed, 96 insertions(+), 58 deletions(-) create mode 100644 resources/lang/de_DE/additional.po create mode 100644 resources/lang/en_US/additional.po create mode 100644 tests/Unit/Helpers/Translation/Assets/ba_RR/additional.po create mode 100644 tests/Unit/Helpers/Translation/Assets/fo_OO/additional.mo create mode 100644 tests/Unit/Helpers/Translation/Assets/fo_OO/additional.po diff --git a/resources/lang/de_DE/additional.po b/resources/lang/de_DE/additional.po new file mode 100644 index 00000000..00eb90b3 --- /dev/null +++ b/resources/lang/de_DE/additional.po @@ -0,0 +1,36 @@ +msgid "" +msgstr "" +"Project-Id-Version: Engelsystem 2.0\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"Last-Translator: \n" +"Language: de_DE\n" + +msgid "auth.not-found" +msgstr "" +"Es wurde kein User gefunden oder das Passwort ist falsch. Probiere es bitte noch einmal. Wenn das Problem " +"weiterhin besteht, melde dich im Himmel." + +msgid "validation.password.required" +msgstr "Bitte gib ein Passwort an." + +msgid "validation.login.required" +msgstr "Bitte gib einen Loginnamen an." + +msgid "validation.email.required" +msgstr "Bitte gib eine E-Mail-Adresse an." + +msgid "validation.email.email" +msgstr "Die E-Mail-Adresse ist nicht gültig." + +msgid "validation.password.min" +msgstr "Dein angegebenes Passwort ist zu kurz." + +msgid "validation.password.confirmed" +msgstr "Deine Passwörter stimmen nicht überein." + +msgid "validation.password_confirmation.required" +msgstr "Du musst dein Passwort bestätigen." diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index b3184f41..105d7330 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -1536,10 +1536,10 @@ msgstr "Pflichtfeld!" #~ msgstr "Gib bitte ein Passwort ein." #: includes/pages/guest_login.php:418 -msgid "auth.not-found" -msgstr "" -"Es wurde kein User gefunden oder das Passwort ist falsch. Probiere es bitte noch einmal. Wenn das Problem " -"weiterhin besteht, melde dich im Himmel." +#~ msgid "auth.not-found" +#~ msgstr "" +#~ "Es wurde kein User gefunden oder das Passwort ist falsch. Probiere es bitte noch einmal. Wenn das Problem " +#~ "weiterhin besteht, melde dich im Himmel." #~ msgid "auth.no-nickname" #~ msgstr "Gib bitte einen Nick an." @@ -2767,26 +2767,5 @@ msgstr "" "Diese Seite existiert nicht oder Du hast keinen Zugriff. Melde Dich an um " "Zugriff zu erhalten!" -msgid "validation.password.required" -msgstr "Bitte gib ein Passwort an." - -msgid "validation.login.required" -msgstr "Bitte gib einen Loginnamen an." - msgid "form.submit" msgstr "Absenden" - -msgid "validation.email.required" -msgstr "Bitte gib eine E-Mail-Adresse an." - -msgid "validation.email.email" -msgstr "Die E-Mail-Adresse ist nicht gültig." - -msgid "validation.password.min" -msgstr "Dein angegebenes Passwort ist zu kurz." - -msgid "validation.password.confirmed" -msgstr "Deine Passwörter stimmen nicht überein." - -msgid "validation.password_confirmation.required" -msgstr "Du musst dein Passwort bestätigen." diff --git a/resources/lang/en_US/additional.po b/resources/lang/en_US/additional.po new file mode 100644 index 00000000..9943b0ab --- /dev/null +++ b/resources/lang/en_US/additional.po @@ -0,0 +1,34 @@ +msgid "" +msgstr "" +"Project-Id-Version: Engelsystem 2.0\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"Last-Translator: \n" +"Language: en_US\n" + +msgid "auth.not-found" +msgstr "No user was found or password is wrong. Please try again. If you are still having problems, ask Heaven." + +msgid "validation.password.required" +msgstr "The password is required." + +msgid "validation.login.required" +msgstr "The login name is required." + +msgid "validation.email.required" +msgstr "The email address is required." + +msgid "validation.email.email" +msgstr "This email address is not valid." + +msgid "validation.password.min" +msgstr "Your password is too short." + +msgid "validation.password.confirmed" +msgstr "Your passwords are not equal." + +msgid "validation.password_confirmation.required" +msgstr "You have to confirm your password." diff --git a/resources/lang/en_US/default.po b/resources/lang/en_US/default.po index a2d56fd1..f7566f1d 100644 --- a/resources/lang/en_US/default.po +++ b/resources/lang/en_US/default.po @@ -22,29 +22,5 @@ msgstr "" #~ msgid "auth.no-password" #~ msgstr "Please enter a password." -msgid "auth.not-found" -msgstr "No user was found or password is wrong. Please try again. If you are still having problems, ask Heaven." - -msgid "validation.password.required" -msgstr "The password is required." - -msgid "validation.login.required" -msgstr "The login name is required." - msgid "form.submit" msgstr "Submit" - -msgid "validation.email.required" -msgstr "The email address is required." - -msgid "validation.email.email" -msgstr "This email address is not valid." - -msgid "validation.password.min" -msgstr "Your password is too short." - -msgid "validation.password.confirmed" -msgstr "Your passwords are not equal." - -msgid "validation.password_confirmation.required" -msgstr "You have to confirm your password." diff --git a/src/Helpers/Translation/TranslationServiceProvider.php b/src/Helpers/Translation/TranslationServiceProvider.php index 6df9b0fe..5534a1c3 100644 --- a/src/Helpers/Translation/TranslationServiceProvider.php +++ b/src/Helpers/Translation/TranslationServiceProvider.php @@ -70,17 +70,20 @@ class TranslationServiceProvider extends ServiceProvider public function getTranslator(string $locale): GettextTranslator { if (!isset($this->translators[$locale])) { - $file = $this->getFile($locale); + $names = ['default', 'additional']; /** @var GettextTranslator $translator */ $translator = $this->app->make(GettextTranslator::class); /** @var Translations $translations */ $translations = $this->app->make(Translations::class); - if (Str::endsWith($file, '.mo')) { - $translations->addFromMoFile($file); - } else { - $translations->addFromPoFile($file); + foreach ($names as $name) { + $file = $this->getFile($locale, $name); + if (Str::endsWith($file, '.mo')) { + $translations->addFromMoFile($file); + } else { + $translations->addFromPoFile($file); + } } $translator->loadTranslations($translations); @@ -93,11 +96,12 @@ class TranslationServiceProvider extends ServiceProvider /** * @param string $locale + * @param string $name * @return string */ - protected function getFile(string $locale): string + protected function getFile(string $locale, string $name = 'default'): string { - $filepath = $file = $this->app->get('path.lang') . '/' . $locale . '/default'; + $filepath = $file = $this->app->get('path.lang') . '/' . $locale . '/' . $name; $file = $filepath . '.mo'; if (!file_exists($file)) { diff --git a/tests/Unit/Helpers/Translation/Assets/ba_RR/additional.po b/tests/Unit/Helpers/Translation/Assets/ba_RR/additional.po new file mode 100644 index 00000000..72383947 --- /dev/null +++ b/tests/Unit/Helpers/Translation/Assets/ba_RR/additional.po @@ -0,0 +1,3 @@ +# Testing content +msgid "validation.foo.bar" +msgstr "B Arr required!" diff --git a/tests/Unit/Helpers/Translation/Assets/fo_OO/additional.mo b/tests/Unit/Helpers/Translation/Assets/fo_OO/additional.mo new file mode 100644 index 0000000000000000000000000000000000000000..73faf3ba22db901d7f266efc95500a6d137d61d6 GIT binary patch literal 93 zcmca7#4?ou2pEA_28dOFm>Gz5fLI8KEr3`Mh`oUr20&`d5_2+B5=%1k^Yqg4^YxMv Yix}MU^A(&Dixi4d3rjPLQd1Ne0M~*KoB#j- literal 0 HcmV?d00001 diff --git a/tests/Unit/Helpers/Translation/Assets/fo_OO/additional.po b/tests/Unit/Helpers/Translation/Assets/fo_OO/additional.po new file mode 100644 index 00000000..8eea7df9 --- /dev/null +++ b/tests/Unit/Helpers/Translation/Assets/fo_OO/additional.po @@ -0,0 +1,3 @@ +# Testing content +msgid "validation.foo.bar" +msgstr "Foo Bar required!" diff --git a/tests/Unit/Helpers/Translation/TranslationServiceProviderTest.php b/tests/Unit/Helpers/Translation/TranslationServiceProviderTest.php index e55fdf02..8c9e21b8 100644 --- a/tests/Unit/Helpers/Translation/TranslationServiceProviderTest.php +++ b/tests/Unit/Helpers/Translation/TranslationServiceProviderTest.php @@ -7,6 +7,7 @@ use Engelsystem\Helpers\Translation\TranslationServiceProvider; use Engelsystem\Helpers\Translation\Translator; use Engelsystem\Test\Unit\ServiceProviderTest; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Rule\InvokedCount; use Symfony\Component\HttpFoundation\Session\Session; class TranslationServiceProviderTest extends ServiceProviderTest @@ -82,11 +83,12 @@ class TranslationServiceProviderTest extends ServiceProviderTest $app = $this->getApp(['get']); $serviceProvider = new TranslationServiceProvider($app); - $this->setExpects($app, 'get', ['path.lang'], __DIR__ . '/Assets'); + $this->setExpects($app, 'get', ['path.lang'], __DIR__ . '/Assets', new InvokedCount(2)); // Get translator $translator = $serviceProvider->getTranslator('fo_OO'); $this->assertEquals('Foo Bar!', $translator->gettext('foo.bar')); + $this->assertEquals('Foo Bar required!', $translator->gettext('validation.foo.bar')); // Retry from cache $serviceProvider->getTranslator('fo_OO'); @@ -99,12 +101,13 @@ class TranslationServiceProviderTest extends ServiceProviderTest public function testGetTranslatorFromPo(): void { $app = $this->getApp(['get']); - $this->setExpects($app, 'get', ['path.lang'], __DIR__ . '/Assets'); + $this->setExpects($app, 'get', ['path.lang'], __DIR__ . '/Assets', new InvokedCount(2)); $serviceProvider = new TranslationServiceProvider($app); // Get translator using a .po file $translator = $serviceProvider->getTranslator('ba_RR'); $this->assertEquals('B Arr!', $translator->gettext('foo.bar')); + $this->assertEquals('B Arr required!', $translator->gettext('validation.foo.bar')); } } From 23d548585b530445f275367ca0c5a7cf4baa30b5 Mon Sep 17 00:00:00 2001 From: Luca Date: Sun, 27 Oct 2019 15:00:05 +0100 Subject: [PATCH 3/4] Remove unused message from default.po --- resources/lang/de_DE/default.po | 6 ------ 1 file changed, 6 deletions(-) diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 105d7330..9d2a00e3 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -1535,12 +1535,6 @@ msgstr "Pflichtfeld!" #~ msgid "auth.no-password" #~ msgstr "Gib bitte ein Passwort ein." -#: includes/pages/guest_login.php:418 -#~ msgid "auth.not-found" -#~ msgstr "" -#~ "Es wurde kein User gefunden oder das Passwort ist falsch. Probiere es bitte noch einmal. Wenn das Problem " -#~ "weiterhin besteht, melde dich im Himmel." - #~ msgid "auth.no-nickname" #~ msgstr "Gib bitte einen Nick an." From 8a298f0f5eedcf6520af58bdd3d5087b1fc39272 Mon Sep 17 00:00:00 2001 From: Luca Date: Thu, 24 Oct 2019 13:29:43 +0200 Subject: [PATCH 4/4] Replace full-text message ids with keys in credits template --- resources/lang/de_DE/default.po | 16 ++++++++++++++++ resources/lang/en_US/default.po | 16 ++++++++++++++++ resources/views/pages/credits.twig | 9 ++------- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 9d2a00e3..1370fca2 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -2763,3 +2763,19 @@ msgstr "" msgid "form.submit" msgstr "Absenden" + +msgid "credits.credit" +msgstr "" +"Das ursprüngliche Engelsystem wurde entwickelt von " +"[cookie](https://github.com/cookieBerlin/engelsystem)" +". Danach wurde es von " +"[msquare](https://notrademark.de)" +" (Maintainer) und " +"[MyIgel](https://myigel.name)" +" völlig überarbeitet und verbessert." + +msgid "credits.contributors" +msgstr "" +"Eine vollständige Liste der Mitwirkenden findest Du " +"[auf GitHub](https://github.com/engelsystem/engelsystem/graphs/contributors)" +"." diff --git a/resources/lang/en_US/default.po b/resources/lang/en_US/default.po index f7566f1d..0119865b 100644 --- a/resources/lang/en_US/default.po +++ b/resources/lang/en_US/default.po @@ -24,3 +24,19 @@ msgstr "" msgid "form.submit" msgstr "Submit" + +msgid "credits.credit" +msgstr "" +"The original engelsystem was written by " +"[cookie](https://github.com/cookieBerlin/engelsystem)" +". It was then completely rewritten and enhanced by " +"[msquare](https://notrademark.de)" +" (maintainer) and " +"[MyIgel](https://myigel.name)" +"." + +msgid "credits.contributors" +msgstr "" +"Please have a look at the " +"[contributors list on GitHub](https://github.com/engelsystem/engelsystem/graphs/contributors)" +" for a complete list." diff --git a/resources/views/pages/credits.twig b/resources/views/pages/credits.twig index 8bd1f694..7e0d3890 100644 --- a/resources/views/pages/credits.twig +++ b/resources/views/pages/credits.twig @@ -17,15 +17,10 @@

{{ __('Source code') }}

{{ __('Version: _%s_', [version])|markdown }}

- {{ __('The original engelsystem was written by -[cookie](https://github.com/cookieBerlin/engelsystem). -It was then completely rewritten and enhanced by [msquare](https://notrademark.de) (maintainer) and -[MyIgel](https://myigel.name).')|markdown }} + {{ __('credits.credit')|markdown }}

- {{ __('Please have a look at the -[contributors list on GitHub](https://github.com/engelsystem/engelsystem/graphs/contributors) -for a complete list.')|markdown }} + {{ __('credits.contributors')|markdown }}