From 419f9f952f5b724631f516861ecaab1513154507 Mon Sep 17 00:00:00 2001 From: Tao Zhou Date: Tue, 14 Mar 2023 13:57:40 -0700 Subject: [PATCH] feat: change default orderBy to `message` (#1519) --- .../cli/test/extract-po-format/expected/en.po | 34 +++++++++---------- .../cli/test/extract-po-format/expected/pl.po | 32 ++++++++--------- .../expected/messages.pot | 32 ++++++++--------- .../conf/src/__snapshots__/index.test.ts.snap | 2 +- packages/conf/src/makeConfig.ts | 2 +- website/docs/ref/conf.md | 10 +++--- website/docs/releases/migration-4.md | 2 ++ 7 files changed, 58 insertions(+), 56 deletions(-) diff --git a/packages/cli/test/extract-po-format/expected/en.po b/packages/cli/test/extract-po-format/expected/en.po index b2d3407ae..6d17fb9bc 100644 --- a/packages/cli/test/extract-po-format/expected/en.po +++ b/packages/cli/test/extract-po-format/expected/en.po @@ -7,6 +7,18 @@ msgstr "" "X-Generator: @lingui/cli\n" "Language: en\n" +#. this is a comment +#. js-lingui-id: f9Atdk +#: fixtures/file-b.tsx:6 +msgid "Hello this is JSX Translation" +msgstr "Hello this is JSX Translation" + +#. js-lingui-id: 6qYmGe +#: fixtures/file-b.tsx:11 +msgctxt "my context" +msgid "Hello this is JSX Translation" +msgstr "Hello this is JSX Translation" + #. js-lingui-id: 1nGWAC #: fixtures/file-a.ts:4 msgid "Hello world" @@ -18,29 +30,17 @@ msgctxt "custom context" msgid "Hello world" msgstr "Hello world" -#. js-lingui-id: 6qYmGe -#: fixtures/file-b.tsx:11 -msgctxt "my context" -msgid "Hello this is JSX Translation" -msgstr "Hello this is JSX Translation" - #. js-lingui-id: BcXPt3 #: fixtures/file-a.ts:16 msgid "Message in descriptor" msgstr "Message in descriptor" -#: fixtures/file-a.ts:11 -#, explicit-id -msgid "custom.id" -msgstr "This message has custom id" - -#. this is a comment -#. js-lingui-id: f9Atdk -#: fixtures/file-b.tsx:6 -msgid "Hello this is JSX Translation" -msgstr "Hello this is JSX Translation" - #: fixtures/file-b.tsx:15 #, explicit-id msgid "jsx.custom.id" msgstr "This JSX element has custom id" + +#: fixtures/file-a.ts:11 +#, explicit-id +msgid "custom.id" +msgstr "This message has custom id" diff --git a/packages/cli/test/extract-po-format/expected/pl.po b/packages/cli/test/extract-po-format/expected/pl.po index f518b7500..7b28ab46f 100644 --- a/packages/cli/test/extract-po-format/expected/pl.po +++ b/packages/cli/test/extract-po-format/expected/pl.po @@ -7,6 +7,18 @@ msgstr "" "X-Generator: @lingui/cli\n" "Language: pl\n" +#. this is a comment +#. js-lingui-id: f9Atdk +#: fixtures/file-b.tsx:6 +msgid "Hello this is JSX Translation" +msgstr "" + +#. js-lingui-id: 6qYmGe +#: fixtures/file-b.tsx:11 +msgctxt "my context" +msgid "Hello this is JSX Translation" +msgstr "" + #. js-lingui-id: 1nGWAC #: fixtures/file-a.ts:4 msgid "Hello world" @@ -18,29 +30,17 @@ msgctxt "custom context" msgid "Hello world" msgstr "" -#. js-lingui-id: 6qYmGe -#: fixtures/file-b.tsx:11 -msgctxt "my context" -msgid "Hello this is JSX Translation" -msgstr "" - #. js-lingui-id: BcXPt3 #: fixtures/file-a.ts:16 msgid "Message in descriptor" msgstr "" -#: fixtures/file-a.ts:11 +#: fixtures/file-b.tsx:15 #, explicit-id -msgid "custom.id" -msgstr "" - -#. this is a comment -#. js-lingui-id: f9Atdk -#: fixtures/file-b.tsx:6 -msgid "Hello this is JSX Translation" +msgid "jsx.custom.id" msgstr "" -#: fixtures/file-b.tsx:15 +#: fixtures/file-a.ts:11 #, explicit-id -msgid "jsx.custom.id" +msgid "custom.id" msgstr "" diff --git a/packages/cli/test/extract-template-po-format/expected/messages.pot b/packages/cli/test/extract-template-po-format/expected/messages.pot index 55f214c5a..e54d986a2 100644 --- a/packages/cli/test/extract-template-po-format/expected/messages.pot +++ b/packages/cli/test/extract-template-po-format/expected/messages.pot @@ -6,6 +6,18 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "X-Generator: @lingui/cli\n" +#. this is a comment +#. js-lingui-id: f9Atdk +#: fixtures/file-b.tsx:6 +msgid "Hello this is JSX Translation" +msgstr "" + +#. js-lingui-id: 6qYmGe +#: fixtures/file-b.tsx:11 +msgctxt "my context" +msgid "Hello this is JSX Translation" +msgstr "" + #. js-lingui-id: 1nGWAC #: fixtures/file-a.ts:4 msgid "Hello world" @@ -17,29 +29,17 @@ msgctxt "custom context" msgid "Hello world" msgstr "" -#. js-lingui-id: 6qYmGe -#: fixtures/file-b.tsx:11 -msgctxt "my context" -msgid "Hello this is JSX Translation" -msgstr "" - #. js-lingui-id: BcXPt3 #: fixtures/file-a.ts:16 msgid "Message in descriptor" msgstr "" -#: fixtures/file-a.ts:11 +#: fixtures/file-b.tsx:15 #, explicit-id -msgid "custom.id" -msgstr "" - -#. this is a comment -#. js-lingui-id: f9Atdk -#: fixtures/file-b.tsx:6 -msgid "Hello this is JSX Translation" +msgid "jsx.custom.id" msgstr "" -#: fixtures/file-b.tsx:15 +#: fixtures/file-a.ts:11 #, explicit-id -msgid "jsx.custom.id" +msgid "custom.id" msgstr "" diff --git a/packages/conf/src/__snapshots__/index.test.ts.snap b/packages/conf/src/__snapshots__/index.test.ts.snap index 1eebd8872..767af9f67 100644 --- a/packages/conf/src/__snapshots__/index.test.ts.snap +++ b/packages/conf/src/__snapshots__/index.test.ts.snap @@ -49,7 +49,7 @@ exports[`@lingui/conf should return default config 1`] = ` locales: [ en-gb, ], - orderBy: messageId, + orderBy: message, pseudoLocale: , rootDir: ., runtimeConfigModule: { diff --git a/packages/conf/src/makeConfig.ts b/packages/conf/src/makeConfig.ts index f2fe00fc0..6aeb0752d 100644 --- a/packages/conf/src/makeConfig.ts +++ b/packages/conf/src/makeConfig.ts @@ -59,7 +59,7 @@ export const defaultConfig: LinguiConfig = { format: "po", formatOptions: { origins: true, lineNumbers: true }, locales: [], - orderBy: "messageId", + orderBy: "message", pseudoLocale: "", rootDir: ".", runtimeConfigModule: ["@lingui/core", "i18n"], diff --git a/website/docs/ref/conf.md b/website/docs/ref/conf.md index 781057214..697241498 100644 --- a/website/docs/ref/conf.md +++ b/website/docs/ref/conf.md @@ -363,18 +363,18 @@ Locale tags which are used in the project. [`extract`](/docs/ref/cli.md#extract) ## orderBy -Default: `messageId` +Default: `message` Order of messages in catalog: -#### messageId - -Sort by the message ID, `js-lingui-id` will be used if no custom id provided. - #### message Sort by source message. +#### messageId + +Sort by the message ID, `js-lingui-id` will be used if no custom id provided. + #### origin Sort by message origin (e.g. `App.js:3`) diff --git a/website/docs/releases/migration-4.md b/website/docs/releases/migration-4.md index 960d5f7cf..777098150 100644 --- a/website/docs/releases/migration-4.md +++ b/website/docs/releases/migration-4.md @@ -60,6 +60,8 @@ Also, we've added a possibility to provide a context for the message. For more d The context feature affects the message ID generation and adds the `msgctxt` parameter in case of the PO catalog format extraction. +This also affects the `orderBy` with `messageId` as now the generated id is used when custom id is absent. To avoid confusion, we switched the default `orderBy` to use the source message (`message`) instead. + ### Change in generated ICU messages for nested JSX Macros We have made a small change in how Lingui generates ICU messages for nested JSX Macros. We have removed leading spaces from the texts in all cases.