From 74b8f338a6bbe4edf93bd54620b87fdd0a06e167 Mon Sep 17 00:00:00 2001 From: Unai Date: Wed, 7 Dec 2022 17:27:56 +0100 Subject: [PATCH] Skip fully filled translations for translation cmd --- src/commands/translate.ts | 4 +++- tests/commands/__snapshots__/test_translate.ts.snap | 13 +++++++++++++ tests/commands/test_translate.ts | 1 + tests/fixtures/translateTest/translate.po | 13 +++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/commands/translate.ts b/src/commands/translate.ts index 1377cf9..2b0ff38 100644 --- a/src/commands/translate.ts +++ b/src/commands/translate.ts @@ -16,7 +16,9 @@ export function* untranslatedStream(translations: Translations): any { const context = translations[contextKey]; for (const msgid of Object.keys(context)) { const msg = context[msgid]; - msg.msgstr = yield [contextKey, msg]; + if (msg.msgstr.includes("") || !msgid) { + msg.msgstr = yield [contextKey, msg]; + } } } } diff --git a/tests/commands/__snapshots__/test_translate.ts.snap b/tests/commands/__snapshots__/test_translate.ts.snap index 1f52742..642efea 100644 --- a/tests/commands/__snapshots__/test_translate.ts.snap +++ b/tests/commands/__snapshots__/test_translate.ts.snap @@ -15,5 +15,18 @@ msgid \\"test_plural\\" msgid_plural \\"test_plural\\" msgstr[0] \\"test1\\" msgstr[1] \\"test2\\" + +msgid \\"filled_test\\" +msgstr \\"filled value\\" + +msgid \\"partially_filled_test_plural\\" +msgid_plural \\"test_plural\\" +msgstr[0] \\"overwritten test1\\" +msgstr[1] \\"overwritten test2\\" + +msgid \\"fully_filled_test_plural\\" +msgid_plural \\"test_plural\\" +msgstr[0] \\"filled value\\" +msgstr[1] \\"filled values\\" " `; diff --git a/tests/commands/test_translate.ts b/tests/commands/test_translate.ts index 3c467bc..404280b 100644 --- a/tests/commands/test_translate.ts +++ b/tests/commands/test_translate.ts @@ -15,6 +15,7 @@ test("translate poFile", () => { stream.next(""); stream.next(["test"]); stream.next(["test1", "test2"]); + stream.next(["overwritten test1", "overwritten test2"]); const data = serialize(poData).toString(); expect(data).toMatchSnapshot(); }); diff --git a/tests/fixtures/translateTest/translate.po b/tests/fixtures/translateTest/translate.po index 283444b..405d93e 100644 --- a/tests/fixtures/translateTest/translate.po +++ b/tests/fixtures/translateTest/translate.po @@ -12,3 +12,16 @@ msgid "test_plural" msgid_plural "test_plural" msgstr[0] "" msgstr[1] "" + +msgid "filled_test" +msgstr "filled value" + +msgid "partially_filled_test_plural" +msgid_plural "test_plural" +msgstr[0] "filled value" +msgstr[1] "" + +msgid "fully_filled_test_plural" +msgid_plural "test_plural" +msgstr[0] "filled value" +msgstr[1] "filled values"