From 8f1ddd787b79510b112b87c21d4a23b875722edc Mon Sep 17 00:00:00 2001 From: Aseer KT <39845171+aseerkt@users.noreply.github.com> Date: Thu, 16 May 2024 20:09:44 +0530 Subject: [PATCH] fix: default message extraction (#1936) --- packages/cli/src/api/catalog/extractFromFiles.ts | 7 ++++--- packages/cli/test/extract-po-format/expected/en.po | 6 ++++++ packages/cli/test/extract-po-format/expected/pl.po | 6 ++++++ packages/cli/test/extract-po-format/fixtures/file-a.ts | 5 ++++- packages/cli/test/index.test.ts | 4 ++-- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/api/catalog/extractFromFiles.ts b/packages/cli/src/api/catalog/extractFromFiles.ts index 43cd13d54..9922798bf 100644 --- a/packages/cli/src/api/catalog/extractFromFiles.ts +++ b/packages/cli/src/api/catalog/extractFromFiles.ts @@ -3,11 +3,11 @@ import type { ExtractorType, LinguiConfigNormalized, } from "@lingui/conf" -import extract from "../extractors" -import path from "path" import chalk from "chalk" +import path from "path" +import extract from "../extractors" +import { ExtractedCatalogType, MessageOrigin } from "../types" import { prettyOrigin } from "../utils" -import { MessageOrigin, ExtractedCatalogType } from "../types" export async function extractFromFiles( paths: string[], @@ -50,6 +50,7 @@ export async function extractFromFiles( messages[next.id] = { ...prev, + message: prev.message ?? next.message, comments: next.comment ? [...prev.comments, next.comment] : prev.comments, diff --git a/packages/cli/test/extract-po-format/expected/en.po b/packages/cli/test/extract-po-format/expected/en.po index e546bce2e..123a182b6 100644 --- a/packages/cli/test/extract-po-format/expected/en.po +++ b/packages/cli/test/extract-po-format/expected/en.po @@ -7,6 +7,12 @@ msgstr "" "X-Generator: @lingui/cli\n" "Language: en\n" +#. js-lingui-explicit-id +#: fixtures/file-a.ts:22 +#: fixtures/file-a.ts:23 +msgid "addToCart" +msgstr "Add To Cart" + #. this is a comment #: fixtures/file-b.tsx:6 msgid "Hello this is JSX Translation" diff --git a/packages/cli/test/extract-po-format/expected/pl.po b/packages/cli/test/extract-po-format/expected/pl.po index fb4927030..85c6a6c97 100644 --- a/packages/cli/test/extract-po-format/expected/pl.po +++ b/packages/cli/test/extract-po-format/expected/pl.po @@ -7,6 +7,12 @@ msgstr "" "X-Generator: @lingui/cli\n" "Language: pl\n" +#. js-lingui-explicit-id +#: fixtures/file-a.ts:22 +#: fixtures/file-a.ts:23 +msgid "addToCart" +msgstr "" + #. this is a comment #: fixtures/file-b.tsx:6 msgid "Hello this is JSX Translation" diff --git a/packages/cli/test/extract-po-format/fixtures/file-a.ts b/packages/cli/test/extract-po-format/fixtures/file-a.ts index 995dc7284..018575624 100644 --- a/packages/cli/test/extract-po-format/fixtures/file-a.ts +++ b/packages/cli/test/extract-po-format/fixtures/file-a.ts @@ -1,5 +1,5 @@ -import { defineMessage, t } from "@lingui/macro" import { i18n } from "@lingui/core" +import { defineMessage, t } from "@lingui/macro" const msg = t`Hello world` @@ -18,3 +18,6 @@ const msgDescriptor = defineMessage({ }) i18n._(msgDescriptor) + +i18n._("addToCart") +i18n._({id: "addToCart", message: "Add To Cart"}) \ No newline at end of file diff --git a/packages/cli/test/index.test.ts b/packages/cli/test/index.test.ts index 1bac33ec5..e53d3b81a 100644 --- a/packages/cli/test/index.test.ts +++ b/packages/cli/test/index.test.ts @@ -69,8 +69,8 @@ describe("E2E Extractor Test", () => { ┌─────────────┬─────────────┬─────────┐ │ Language │ Total count │ Missing │ ├─────────────┼─────────────┼─────────┤ - │ en (source) │ 7 │ - │ - │ pl │ 7 │ 7 │ + │ en (source) │ 8 │ - │ + │ pl │ 8 │ 8 │ └─────────────┴─────────────┴─────────┘ (use "yarn extract" to update catalogs with new messages)