diff --git a/packages/cli/src/api/formats/__snapshots__/po-gettext.test.ts.snap b/packages/cli/src/api/formats/__snapshots__/po-gettext.test.ts.snap index dff78d61d..6bf3d0541 100644 --- a/packages/cli/src/api/formats/__snapshots__/po-gettext.test.ts.snap +++ b/packages/cli/src/api/formats/__snapshots__/po-gettext.test.ts.snap @@ -1,5 +1,44 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[` 1`] = ` +Object { + message_with_id: Object { + comments: Array [], + extractedComments: Array [], + flags: Array [], + obsolete: false, + origin: Array [], + translation: {someCount, plural, one {Singular case} other {Case number {someCount}}}, + }, + message_with_id_but_without_translation: Object { + comments: Array [], + extractedComments: Array [ + Comment made by the developers., + ], + flags: Array [], + obsolete: false, + origin: Array [], + translation: , + }, + {anotherCount, plural, one {Singular case} other {Case number {anotherCount}}}: Object { + comments: Array [], + extractedComments: Array [], + flags: Array [], + obsolete: false, + origin: Array [], + translation: {anotherCount, plural, one {Singular case} other {Case number {anotherCount}}}, + }, + {count, plural, one {Singular} other {Plural}}: Object { + comments: Array [], + extractedComments: Array [], + flags: Array [], + obsolete: false, + origin: Array [], + translation: , + }, +} +`; + exports[`po-gettext format should convert ICU plural messages to gettext plurals 1`] = ` msgid "" msgstr "" diff --git a/packages/cli/src/api/formats/fixtures/messages_plural-4-letter.po b/packages/cli/src/api/formats/fixtures/messages_plural-4-letter.po new file mode 100644 index 000000000..c318bb849 --- /dev/null +++ b/packages/cli/src/api/formats/fixtures/messages_plural-4-letter.po @@ -0,0 +1,33 @@ +msgid "" +msgstr "" +"POT-Creation-Date: 2018-08-27 10:00+0000\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: @lingui/cli\n" +"Language: en_CA\n" + +#. js-lingui:pluralize_on=someCount +msgid "message_with_id" +msgid_plural "message_with_id_plural" +msgstr[0] "Singular case" +msgstr[1] "Case number {someCount}" + +#. js-lingui:icu=%7BanotherCount%2C+plural%2C+one+%7BSingular+case%7D+other+%7BCase+number+%7BanotherCount%7D%7D%7D&pluralize_on=anotherCount +msgid "Singular case" +msgid_plural "Case number {anotherCount}" +msgstr[0] "Singular case" +msgstr[1] "Case number {anotherCount}" + +#. Comment made by the developers. +#. js-lingui:pluralize_on=count +msgid "message_with_id_but_without_translation" +msgid_plural "message_with_id_but_without_translation_plural" +msgstr[0] "" +msgstr[1] "" + +#. js-lingui:icu=%7Bcount%2C+plural%2C+one+%7BSingular%7D+other+%7BPlural%7D%7D&pluralize_on=count +msgid "Singular" +msgid_plural "Plural" +msgstr[0] "" +msgstr[1] "" \ No newline at end of file diff --git a/packages/cli/src/api/formats/po-gettext.test.ts b/packages/cli/src/api/formats/po-gettext.test.ts index 1489b9e3f..82e707521 100644 --- a/packages/cli/src/api/formats/po-gettext.test.ts +++ b/packages/cli/src/api/formats/po-gettext.test.ts @@ -366,4 +366,15 @@ msgstr[2] "# dnĂ­" }) }) }) + + describe("convertPluralsToIco handle correctly locales with 4-letter", () => { + const pofile = fs + .readFileSync( + path.join(path.resolve(__dirname), "fixtures", "messages_plural-4-letter.po") + ) + .toString() + + const catalog = format.parse(pofile) + expect(catalog).toMatchSnapshot() + }) }) diff --git a/packages/cli/src/api/formats/po-gettext.ts b/packages/cli/src/api/formats/po-gettext.ts index 7b86aa37e..d041b7779 100644 --- a/packages/cli/src/api/formats/po-gettext.ts +++ b/packages/cli/src/api/formats/po-gettext.ts @@ -204,10 +204,12 @@ const deserialize: (Object) => Object = R.map( * https://github.com/LLK/po2icu/blob/9eb97f81f72b2fee02b77f1424702e019647e9b9/lib/po2icu.js#L148. */ const getPluralCases = (lang: string): string[] | undefined => { - const gettextPluralsInfo = gettextPlurals[lang] + // If users uses locale with underscore or slash, es-ES, es_ES, gettextplural is "es" not es-ES. + const [correctLang] = lang.split(/[-_]/g) + const gettextPluralsInfo = gettextPlurals[correctLang] return gettextPluralsInfo?.examples.map((pluralCase) => - pluralsCldr(lang, pluralCase.sample) + pluralsCldr(correctLang, pluralCase.sample) ) }