From 8fa28c6d6245504bdf1cd12f85d39898e2894797 Mon Sep 17 00:00:00 2001 From: Nicolas C Date: Fri, 21 Jun 2024 13:03:28 +0200 Subject: [PATCH 1/3] fix: leave obsolete pristine for files not in extraction file set --- packages/cli/src/api/catalog/mergeCatalog.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/api/catalog/mergeCatalog.ts b/packages/cli/src/api/catalog/mergeCatalog.ts index d761635b7..73b1a1f81 100644 --- a/packages/cli/src/api/catalog/mergeCatalog.ts +++ b/packages/cli/src/api/catalog/mergeCatalog.ts @@ -49,7 +49,7 @@ export function mergeCatalog( const obsoleteMessages = obsoleteKeys.map((key) => ({ [key]: { ...prevCatalog[key], - obsolete: !options.files, + ...(!options.files && { obsolete: true }), }, })) From 068de89095259bcc0656cb799d748478f9ab5f22 Mon Sep 17 00:00:00 2001 From: Nicolas Cherel Date: Mon, 24 Jun 2024 12:14:13 +0200 Subject: [PATCH 2/3] test(cli): check for consistent results with partial extracts --- .../existing/en.po | 53 +++++++++++++++++++ .../expected/en.po | 53 +++++++++++++++++++ .../fixtures/file-a.ts | 23 ++++++++ .../fixtures/file-b.tsx | 16 ++++++ packages/cli/test/index.test.ts | 35 +++++++++++- 5 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 packages/cli/test/extract-partial-consistency/existing/en.po create mode 100644 packages/cli/test/extract-partial-consistency/expected/en.po create mode 100644 packages/cli/test/extract-partial-consistency/fixtures/file-a.ts create mode 100644 packages/cli/test/extract-partial-consistency/fixtures/file-b.tsx diff --git a/packages/cli/test/extract-partial-consistency/existing/en.po b/packages/cli/test/extract-partial-consistency/existing/en.po new file mode 100644 index 000000000..7564ea414 --- /dev/null +++ b/packages/cli/test/extract-partial-consistency/existing/en.po @@ -0,0 +1,53 @@ +msgid "" +msgstr "" +"POT-Creation-Date: 2023-03-15 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\n" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"Plural-Forms: \n" + +#. js-lingui-explicit-id +#: fixtures/file-a.ts:11 +#~ msgid "custom.id" +#~ msgstr "This message has custom id" + +#. js-lingui-explicit-id +#: fixtures/file-a.ts:22 +#: fixtures/file-a.ts:23 +msgid "addToCart" +msgstr "Add To Cart with change ignored" + +#. this is a comment +#: fixtures/file-b.tsx:6 +msgid "Hello this is JSX Translation" +msgstr "Hello this is JSX Translation" + +#: fixtures/file-b.tsx:11 +msgctxt "my context" +msgid "Hello this is JSX Translation" +msgstr "Hello this is JSX Translation" + +#: fixtures/file-a.ts:4 +msgid "Hello world" +msgstr "Hello world" + +#: fixtures/file-a.ts:6 +msgctxt "custom context" +msgid "Hello world" +msgstr "Hello world" + +#: fixtures/file-a.ts:16 +msgid "Message in descriptor" +msgstr "Message in descriptor" + +#. js-lingui-explicit-id +#: fixtures/file-b.tsx:15 +msgid "jsx.custom.id" +msgstr "This JSX element has custom id" diff --git a/packages/cli/test/extract-partial-consistency/expected/en.po b/packages/cli/test/extract-partial-consistency/expected/en.po new file mode 100644 index 000000000..7564ea414 --- /dev/null +++ b/packages/cli/test/extract-partial-consistency/expected/en.po @@ -0,0 +1,53 @@ +msgid "" +msgstr "" +"POT-Creation-Date: 2023-03-15 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\n" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"Plural-Forms: \n" + +#. js-lingui-explicit-id +#: fixtures/file-a.ts:11 +#~ msgid "custom.id" +#~ msgstr "This message has custom id" + +#. js-lingui-explicit-id +#: fixtures/file-a.ts:22 +#: fixtures/file-a.ts:23 +msgid "addToCart" +msgstr "Add To Cart with change ignored" + +#. this is a comment +#: fixtures/file-b.tsx:6 +msgid "Hello this is JSX Translation" +msgstr "Hello this is JSX Translation" + +#: fixtures/file-b.tsx:11 +msgctxt "my context" +msgid "Hello this is JSX Translation" +msgstr "Hello this is JSX Translation" + +#: fixtures/file-a.ts:4 +msgid "Hello world" +msgstr "Hello world" + +#: fixtures/file-a.ts:6 +msgctxt "custom context" +msgid "Hello world" +msgstr "Hello world" + +#: fixtures/file-a.ts:16 +msgid "Message in descriptor" +msgstr "Message in descriptor" + +#. js-lingui-explicit-id +#: fixtures/file-b.tsx:15 +msgid "jsx.custom.id" +msgstr "This JSX element has custom id" diff --git a/packages/cli/test/extract-partial-consistency/fixtures/file-a.ts b/packages/cli/test/extract-partial-consistency/fixtures/file-a.ts new file mode 100644 index 000000000..87f894eb9 --- /dev/null +++ b/packages/cli/test/extract-partial-consistency/fixtures/file-a.ts @@ -0,0 +1,23 @@ +import { i18n } from "@lingui/core" +import { defineMessage, t } from "@lingui/macro" + +const msg = t`Hello world` + +const msg2 = t({ + message: "Hello world", + context: "custom context", +}) + +const msg3 = null /* original translation commented to mark message obsolete *//*t({ + message: "This message has custom id", + id: "custom.id", +})*/ + +const msgDescriptor = defineMessage({ + message: "Message in descriptor", +}) + +i18n._(msgDescriptor) + +i18n._("addToCart") +i18n._({id: "addToCart", message: "Add To Cart with change ignored"}) \ No newline at end of file diff --git a/packages/cli/test/extract-partial-consistency/fixtures/file-b.tsx b/packages/cli/test/extract-partial-consistency/fixtures/file-b.tsx new file mode 100644 index 000000000..5c771448f --- /dev/null +++ b/packages/cli/test/extract-partial-consistency/fixtures/file-b.tsx @@ -0,0 +1,16 @@ +import { Trans } from "@lingui/macro" +import React from "react" + +export function MyComponent() { + return ( + Hello this is JSX Translation + ) +} + +export function MyComponent2() { + return Hello this is JSX Translation +} + +export function MyComponent3() { + return This JSX element has custom id +} diff --git a/packages/cli/test/index.test.ts b/packages/cli/test/index.test.ts index 991aed8ac..b83e7668b 100644 --- a/packages/cli/test/index.test.ts +++ b/packages/cli/test/index.test.ts @@ -5,6 +5,7 @@ import { command as compileCommand } from "../src/lingui-compile" import fs from "fs/promises" import os from "os" import nodepath from "path" +import glob from "glob" import { makeConfig } from "@lingui/conf" import { listingToHumanReadable, readFsToJson } from "../src/tests" import { getConsoleMockCalls, mockConsole } from "@lingui/jest-mocks" @@ -22,13 +23,18 @@ async function prepare(caseFolderName: string) { const actualPath = nodepath.join(rootDir, "actual") const expectedPath = nodepath.join(rootDir, "expected") + const existingPath = nodepath.join(rootDir, "existing") await fs.rm(actualPath, { recursive: true, force: true, }) - return { rootDir, actualPath, expectedPath } + if (glob.sync(existingPath).length === 1) { + await fs.cp(existingPath, actualPath, { recursive: true }) + } + + return { rootDir, actualPath, existingPath, expectedPath } } describe("E2E Extractor Test", () => { @@ -288,4 +294,31 @@ describe("E2E Extractor Test", () => { compareFolders(actualPath, expectedPath) }) }) + + it("should extract consistently with files argument", async () => { + const { rootDir, actualPath, expectedPath } = await prepare( + "extract-partial-consistency" + ) + + await extractCommand( + makeConfig({ + rootDir: rootDir, + locales: ["en"], + sourceLocale: "en", + format: "po", + catalogs: [ + { + path: "/actual/{locale}", + include: ["/fixtures"], + }, + ], + }), + { + files: [nodepath.join(rootDir, "fixtures", "file-b.tsx")] + } + ) + + compareFolders(actualPath, expectedPath) + }) + }) From 2ecc64dedc3e614c4502724a7229f2995892d888 Mon Sep 17 00:00:00 2001 From: Nicolas C Date: Wed, 16 Oct 2024 09:45:33 +0200 Subject: [PATCH 3/3] fix(extraction test): remove manual copies of 'existing' --- packages/cli/test/index.test.ts | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/packages/cli/test/index.test.ts b/packages/cli/test/index.test.ts index b83e7668b..b3a6c284d 100644 --- a/packages/cli/test/index.test.ts +++ b/packages/cli/test/index.test.ts @@ -4,8 +4,8 @@ import extractExperimentalCommand from "../src/lingui-extract-experimental" import { command as compileCommand } from "../src/lingui-compile" import fs from "fs/promises" import os from "os" -import nodepath from "path" import glob from "glob" +import nodepath from "path" import { makeConfig } from "@lingui/conf" import { listingToHumanReadable, readFsToJson } from "../src/tests" import { getConsoleMockCalls, mockConsole } from "@lingui/jest-mocks" @@ -180,12 +180,6 @@ describe("E2E Extractor Test", () => { "extractor-experimental" ) - await fs.cp( - nodepath.join(rootDir, "existing"), - nodepath.join(rootDir, "actual"), - { recursive: true } - ) - await mockConsole(async (console) => { const config = makeConfig({ rootDir: rootDir, @@ -240,12 +234,6 @@ describe("E2E Extractor Test", () => { "extractor-experimental-clean" ) - await fs.cp( - nodepath.join(rootDir, "existing"), - nodepath.join(rootDir, "actual"), - { recursive: true } - ) - await mockConsole(async (console) => { const result = await extractExperimentalCommand( makeConfig({ @@ -314,11 +302,10 @@ describe("E2E Extractor Test", () => { ], }), { - files: [nodepath.join(rootDir, "fixtures", "file-b.tsx")] + files: [nodepath.join(rootDir, "fixtures", "file-b.tsx")], } ) compareFolders(actualPath, expectedPath) }) - })