Skip to content

Commit

Permalink
fix: default message extraction (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
aseerkt authored May 16, 2024
1 parent d90f778 commit 8f1ddd7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/cli/src/api/catalog/extractFromFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/test/extract-po-format/expected/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/test/extract-po-format/expected/pl.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/test/extract-po-format/fixtures/file-a.ts
Original file line number Diff line number Diff line change
@@ -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`

Expand All @@ -18,3 +18,6 @@ const msgDescriptor = defineMessage({
})

i18n._(msgDescriptor)

i18n._("addToCart")
i18n._({id: "addToCart", message: "Add To Cart"})
4 changes: 2 additions & 2 deletions packages/cli/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ describe("E2E Extractor Test", () => {
┌─────────────┬─────────────┬─────────┐
│ Language │ Total count │ Missing │
├─────────────┼─────────────┼─────────┤
│ en (source) │ 7 │ - │
│ pl │ 77
│ en (source) │ 8 │ - │
│ pl │ 88
└─────────────┴─────────────┴─────────┘
(use "yarn extract" to update catalogs with new messages)
Expand Down

0 comments on commit 8f1ddd7

Please sign in to comment.