Browse Source

Merge pull request #11127 from cakephp/3.next-i18n-plural-issue

Fix plural translations falling back when they shouldn't
Mark Story 8 years ago
parent
commit
c72e5ffc19

+ 2 - 2
src/I18n/Parser/PoFileParser.php

@@ -142,9 +142,9 @@ class PoFileParser
 
         $translation = stripcslashes($translation);
 
-        if ($context !== null) {
+        if ($context !== null && !isset($messages[$singular]['_context'][$context])) {
             $messages[$singular]['_context'][$context] = $translation;
-        } else {
+        } elseif (!isset($messages[$singular]['_context'][''])) {
             $messages[$singular]['_context'][''] = $translation;
         }
 

+ 13 - 0
tests/TestCase/I18n/I18nTest.php

@@ -857,4 +857,17 @@ class I18nTest extends TestCase
         $result = __('No translation needed');
         $this->assertEquals('No translation needed', $result);
     }
+
+    /**
+     * Tests that a plurals from a domain get translated correctly
+     *
+     * @return void
+     */
+    public function testPluralTranslationsFromDomain()
+    {
+        I18n::locale('de');
+        $this->assertEquals('Standorte', __dn('wa', 'Location', 'Locations', 0));
+        $this->assertEquals('Standort', __dn('wa', 'Location', 'Locations', 1));
+        $this->assertEquals('Standorte', __dn('wa', 'Location', 'Locations', 2));
+    }
 }

+ 20 - 0
tests/test_app/TestApp/Locale/de/wa.po

@@ -0,0 +1,20 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: VERSION\n"
+"POT-Creation-Date: 2017-06-23 08:49+0000\n"
+"PO-Revision-Date: 2017-06-23 08:49+0000\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE TEAM <EMAIL@ADDRESS>\n"
+"Language: de\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"
+
+msgid "Location"
+msgid_plural "Locations"
+msgstr[0] "Standort"
+msgstr[1] "Standorte"
+
+msgid "Locations"
+msgstr "Standorte"