diff --git a/packages/babel-plugin-formatjs/CHANGELOG.md b/packages/babel-plugin-formatjs/CHANGELOG.md index 142a657d6ad..5bf6eb61c6c 100644 --- a/packages/babel-plugin-formatjs/CHANGELOG.md +++ b/packages/babel-plugin-formatjs/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [10.5.33](https://github.com/formatjs/formatjs/compare/babel-plugin-formatjs@10.5.32...babel-plugin-formatjs@10.5.33) (2025-01-20) + +**Note:** Version bump only for package babel-plugin-formatjs + ## [10.5.32](https://github.com/formatjs/formatjs/compare/babel-plugin-formatjs@10.5.31...babel-plugin-formatjs@10.5.32) (2025-01-20) **Note:** Version bump only for package babel-plugin-formatjs diff --git a/packages/babel-plugin-formatjs/package.json b/packages/babel-plugin-formatjs/package.json index 69e240b22f1..8d2baf62f07 100644 --- a/packages/babel-plugin-formatjs/package.json +++ b/packages/babel-plugin-formatjs/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-formatjs", - "version": "10.5.32", + "version": "10.5.33", "description": "Extracts string messages for translation from modules that use formatjs.", "repository": { "type": "git", diff --git a/packages/cli-lib/CHANGELOG.md b/packages/cli-lib/CHANGELOG.md index f305415091b..72e36599b42 100644 --- a/packages/cli-lib/CHANGELOG.md +++ b/packages/cli-lib/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [7.2.0](https://github.com/formatjs/formatjs/compare/@formatjs/cli-lib@7.1.3...@formatjs/cli-lib@7.2.0) (2025-01-20) + +### Features + +* **@formatjs/icu-messageformat-parser:** return error containing structural differences ([24a6145](https://github.com/formatjs/formatjs/commit/24a61456bb4adc0afbbc0b932de5b7826301e892)) - by @longlho + ## [7.1.3](https://github.com/formatjs/formatjs/compare/@formatjs/cli-lib@7.1.2...@formatjs/cli-lib@7.1.3) (2025-01-20) **Note:** Version bump only for package @formatjs/cli-lib diff --git a/packages/cli-lib/package.json b/packages/cli-lib/package.json index 1bb466a61a3..ac05a2b4f84 100644 --- a/packages/cli-lib/package.json +++ b/packages/cli-lib/package.json @@ -1,6 +1,6 @@ { "name": "@formatjs/cli-lib", - "version": "7.1.3", + "version": "7.2.0", "description": "Lib for CLI for formatjs.", "keywords": [ "intl", diff --git a/packages/cli-lib/src/verify/checkStructuralEquality.ts b/packages/cli-lib/src/verify/checkStructuralEquality.ts index c8d9c7de562..e35d51af4da 100644 --- a/packages/cli-lib/src/verify/checkStructuralEquality.ts +++ b/packages/cli-lib/src/verify/checkStructuralEquality.ts @@ -52,19 +52,27 @@ export async function checkStructuralEquality( .reduce((result, [locale, content]) => { const localeMessages = flatten(content) - const problematicKeys = Object.keys(enUSMessages).filter(k => { - if (!localeMessages[k]) { - return false - } - const enUSMessage = enUSMessages[k] - try { - const localeMessage = parse(localeMessages[k]) - return !isStructurallySame(enUSMessage, localeMessage) - } catch (e) { - error('Error comparing message', k, enUSMessage, localeMessages[k], e) - return true - } - }) + const problematicKeys = Object.keys(enUSMessages) + .map(k => { + if (!localeMessages[k]) { + return {key: k, success: true} + } + const enUSMessage = enUSMessages[k] + try { + const localeMessage = parse(localeMessages[k]) + return { + key: k, + ...isStructurallySame(enUSMessage, localeMessage), + } + } catch (e) { + return { + key: k, + success: false, + error: e instanceof Error ? e : new Error(String(e)), + } + } + }) + .filter(s => !s.success) if (!problematicKeys.length) { return result @@ -74,7 +82,9 @@ export async function checkStructuralEquality( writeStderr( `These translation keys for locale ${locale} are structurally different from ${sourceLocale}:\n` ) - problematicKeys.forEach(r => writeStderr(`${r}\n`)) + problematicKeys.forEach(({key, error}) => + writeStderr(`${key}: ${error?.message}\n`) + ) return false }, true) diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index ba75a352fd0..613d315fdb6 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [6.5.0](https://github.com/formatjs/formatjs/compare/@formatjs/cli@6.4.3...@formatjs/cli@6.5.0) (2025-01-20) + +### Features + +* **@formatjs/icu-messageformat-parser:** return error containing structural differences ([24a6145](https://github.com/formatjs/formatjs/commit/24a61456bb4adc0afbbc0b932de5b7826301e892)) - by @longlho + ## [6.4.3](https://github.com/formatjs/formatjs/compare/@formatjs/cli@6.4.2...@formatjs/cli@6.4.3) (2025-01-20) ### Bug Fixes diff --git a/packages/cli/integration-tests/verify/integration.test.ts b/packages/cli/integration-tests/verify/integration.test.ts index 9d6c404b0fb..ceeb621913c 100644 --- a/packages/cli/integration-tests/verify/integration.test.ts +++ b/packages/cli/integration-tests/verify/integration.test.ts @@ -51,6 +51,10 @@ test('structural equality fail', async () => { `${BIN_PATH} verify --source-locale en-US --structural-equality '${join(__dirname, 'structural-equality', 'fixtures2', '*.json')}'` ) ).rejects.toThrow( - /These translation keys for locale fr-FR are structurally different from en-US:\n3\n4\n6/ + `These translation keys for locale fr-FR are structurally different from en-US: +3: Variable var has conflicting types: number vs date +4: Missing variable var4 in message +6: Different number of variables: [var, var2, var3, var4, var5, b] vs [var, var2, var3, var4, var5] +7: EXPECT_ARGUMENT_CLOSING_BRACE` ) }, 20000) diff --git a/packages/cli/integration-tests/verify/structural-equality/fixtures1/en-US.json b/packages/cli/integration-tests/verify/structural-equality/fixtures1/en-US.json index 1e4ddf0dee9..cbf697347ce 100644 --- a/packages/cli/integration-tests/verify/structural-equality/fixtures1/en-US.json +++ b/packages/cli/integration-tests/verify/structural-equality/fixtures1/en-US.json @@ -1,4 +1,8 @@ { "foo": "baz {var}", - "2": "{c, plural, one {#} other {#}}" + "2": "{c, plural, one {#} other {#}}", + "3": "only string", + "4": { + "5": "nested" + } } diff --git a/packages/cli/integration-tests/verify/structural-equality/fixtures1/fr.json b/packages/cli/integration-tests/verify/structural-equality/fixtures1/fr.json index 51fcb1bc4f7..8163f00fceb 100644 --- a/packages/cli/integration-tests/verify/structural-equality/fixtures1/fr.json +++ b/packages/cli/integration-tests/verify/structural-equality/fixtures1/fr.json @@ -1,4 +1,8 @@ { "foo": "baz {var}", - "2": "{c, plural, one {#} few {#} other {#}}" + "2": "{c, plural, one {#} few {#} other {#}}", + "3": "only string", + "4": { + "5": "nested literal" + } } diff --git a/packages/cli/integration-tests/verify/structural-equality/fixtures2/en-US.json b/packages/cli/integration-tests/verify/structural-equality/fixtures2/en-US.json index c890de392ce..0a15ceb6786 100644 --- a/packages/cli/integration-tests/verify/structural-equality/fixtures2/en-US.json +++ b/packages/cli/integration-tests/verify/structural-equality/fixtures2/en-US.json @@ -1,16 +1,16 @@ { "1": "bar", "2": "bar {var}", - "3": "bar {var, number}", - "4": "bar {var} {var2, number} {var3, date} {var4, time}", - "5": "bar {var} {var2, number} {var3, date} {var4, time} {var5, plural, one {# foo} other {# foos}}", - "6": "bar {var} {var2, number} {var3, date} {var4, time} {var5, plural, one {# foo} other {# foos}} foo", - "7": "bb", "8": { "9": "bar", "nested": { "10": "bar" } }, + "3": "bar {var, number}", + "4": "bar {var} {var2, number} {var3, date} {var4, time}", + "5": "bar {var} {var2, number} {var3, date} {var4, time} {var5, plural, one {# foo} other {# foos}}", + "6": "bar {var} {var2, number} {var3, date} {var4, time} {var5, plural, one {# foo} other {# foos}} foo", + "7": "bb", "11": "nah" } diff --git a/packages/cli/integration-tests/verify/structural-equality/fixtures2/fr-FR.json b/packages/cli/integration-tests/verify/structural-equality/fixtures2/fr-FR.json index 4f654566866..3f76929d6b5 100644 --- a/packages/cli/integration-tests/verify/structural-equality/fixtures2/fr-FR.json +++ b/packages/cli/integration-tests/verify/structural-equality/fixtures2/fr-FR.json @@ -1,16 +1,16 @@ { "1": "bar", - "2": "{var} bar", - "3": "bar {var, date}", - "4": "bar {var} {var2, number} {var3, date} {var5, time}", - "5": "bar {var} {var2, number} {var3, date} {var4, time} {var5, plural, one {# foo} other {# foos}}", - "6": "bar {var} {var2, number} {var3, date} {var4, time} {var5, plural, one {# foo} other {# foos}} foo", - "7": "malform {a", "8": { "9": "bar", "nested": { "10": "bar" } }, + "2": "{var} bar", + "3": "bar {var, date}", + "4": "bar {var} {var2, number} {var3, date} {var5, time}", + "5": "bar {var} {var2, number} {var3, date} {var4, time} {var5, plural, one {# foo} other {# foos}}", + "6": "bar {var} {var2, number} {var3, date} {var4, time} {var5, plural, one {# foo} other {# foos}} foo", + "7": "malform {a", "11": "nah" } diff --git a/packages/cli/package.json b/packages/cli/package.json index 6b74fc26162..c21508c64ac 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@formatjs/cli", - "version": "6.4.3", + "version": "6.5.0", "description": "A CLI for formatjs.", "keywords": [ "intl", diff --git a/packages/editor/CHANGELOG.md b/packages/editor/CHANGELOG.md index a00ebffa2a2..a9cbfed8a59 100644 --- a/packages/editor/CHANGELOG.md +++ b/packages/editor/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.0.69](https://github.com/formatjs/formatjs/compare/@formatjs/editor@2.0.68...@formatjs/editor@2.0.69) (2025-01-20) + +**Note:** Version bump only for package @formatjs/editor + ## [2.0.68](https://github.com/formatjs/formatjs/compare/@formatjs/editor@2.0.67...@formatjs/editor@2.0.68) (2025-01-20) **Note:** Version bump only for package @formatjs/editor diff --git a/packages/editor/package.json b/packages/editor/package.json index 65e11826146..d3e57c94443 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -1,6 +1,6 @@ { "name": "@formatjs/editor", - "version": "2.0.68", + "version": "2.0.69", "description": "A ICU MessageFormat Editor UI", "keywords": [ "intl", diff --git a/packages/eslint-plugin-formatjs/CHANGELOG.md b/packages/eslint-plugin-formatjs/CHANGELOG.md index 817d8219e44..8283652c52f 100644 --- a/packages/eslint-plugin-formatjs/CHANGELOG.md +++ b/packages/eslint-plugin-formatjs/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [5.2.12](https://github.com/formatjs/formatjs/compare/eslint-plugin-formatjs@5.2.11...eslint-plugin-formatjs@5.2.12) (2025-01-20) + +**Note:** Version bump only for package eslint-plugin-formatjs + ## [5.2.11](https://github.com/formatjs/formatjs/compare/eslint-plugin-formatjs@5.2.10...eslint-plugin-formatjs@5.2.11) (2025-01-20) **Note:** Version bump only for package eslint-plugin-formatjs diff --git a/packages/eslint-plugin-formatjs/package.json b/packages/eslint-plugin-formatjs/package.json index be6b7d0993c..0fd1dc59f64 100644 --- a/packages/eslint-plugin-formatjs/package.json +++ b/packages/eslint-plugin-formatjs/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-formatjs", - "version": "5.2.11", + "version": "5.2.12", "description": "ESLint plugin for formatjs", "main": "index.js", "repository": { diff --git a/packages/icu-messageformat-parser/CHANGELOG.md b/packages/icu-messageformat-parser/CHANGELOG.md index 9b07a99dcae..e68702957f4 100644 --- a/packages/icu-messageformat-parser/CHANGELOG.md +++ b/packages/icu-messageformat-parser/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [2.11.0](https://github.com/formatjs/formatjs/compare/@formatjs/icu-messageformat-parser@2.10.1...@formatjs/icu-messageformat-parser@2.11.0) (2025-01-20) + +### Features + +* **@formatjs/icu-messageformat-parser:** return error containing structural differences ([24a6145](https://github.com/formatjs/formatjs/commit/24a61456bb4adc0afbbc0b932de5b7826301e892)) - by @longlho + ## [2.10.1](https://github.com/formatjs/formatjs/compare/@formatjs/icu-messageformat-parser@2.10.0...@formatjs/icu-messageformat-parser@2.10.1) (2025-01-20) ### Bug Fixes diff --git a/packages/icu-messageformat-parser/manipulator.ts b/packages/icu-messageformat-parser/manipulator.ts index c983f9ab9ac..bfc0d871957 100644 --- a/packages/icu-messageformat-parser/manipulator.ts +++ b/packages/icu-messageformat-parser/manipulator.ts @@ -136,6 +136,11 @@ function collectVariables( }) } +interface IsStructurallySameResult { + error?: Error + success: boolean +} + /** * Check if 2 ASTs are structurally the same. This primarily means that * they have the same variables with the same type @@ -146,17 +151,43 @@ function collectVariables( export function isStructurallySame( a: MessageFormatElement[], b: MessageFormatElement[] -): boolean { +): IsStructurallySameResult { const aVars = new Map() const bVars = new Map() collectVariables(a, aVars) collectVariables(b, bVars) if (aVars.size !== bVars.size) { - return false + return { + success: false, + error: new Error( + `Different number of variables: [${Array.from(aVars.keys()).join(', ')}] vs [${Array.from(bVars.keys()).join(', ')}]` + ), + } } - return Array.from(aVars.entries()).every(([key, type]) => { - return bVars.has(key) && bVars.get(key) === type - }) + return Array.from(aVars.entries()).reduce( + (result, [key, type]) => { + if (!result.success) { + return result + } + const bType = bVars.get(key) + if (bType == null) { + return { + success: false, + error: new Error(`Missing variable ${key} in message`), + } + } + if (bType !== type) { + return { + success: false, + error: new Error( + `Variable ${key} has conflicting types: ${TYPE[type]} vs ${TYPE[bType]}` + ), + } + } + return result + }, + {success: true} + ) } diff --git a/packages/icu-messageformat-parser/package.json b/packages/icu-messageformat-parser/package.json index c9a11d4205f..c9b9aec2281 100644 --- a/packages/icu-messageformat-parser/package.json +++ b/packages/icu-messageformat-parser/package.json @@ -1,6 +1,6 @@ { "name": "@formatjs/icu-messageformat-parser", - "version": "2.10.1", + "version": "2.11.0", "main": "index.js", "module": "lib/index.js", "types": "index.d.ts", diff --git a/packages/icu-messageformat-parser/tests/manipulator.test.ts b/packages/icu-messageformat-parser/tests/manipulator.test.ts index e884ea2e4c8..e8cb9145300 100644 --- a/packages/icu-messageformat-parser/tests/manipulator.test.ts +++ b/packages/icu-messageformat-parser/tests/manipulator.test.ts @@ -76,10 +76,12 @@ test('structurally same plural', function () { '{count, plural, one {{count, number} cat} other {{count, number} cats}}' ), parse( - '{count, plural, one {{count, number} foo} other {{count, number} bax}}' + '{count, plural, one {{count, number} foo} few{# cats} other {{count, number} bax}}' ) ) - ).toBe(true) + ).toEqual({ + success: true, + }) }) test('structurally same plural mismatch element', function () { @@ -92,5 +94,18 @@ test('structurally same plural mismatch element', function () { '{count2, plural, one {{count, number} foo} other {{count, number} bax}}' ) ) - ).toBe(false) + ).toEqual({ + success: false, + error: new Error( + `Different number of variables: [count] vs [count2, count]` + ), + }) +}) + +test('structurally same literal', function () { + expect(isStructurallySame(parse('some static string'), parse('asd'))).toEqual( + { + success: true, + } + ) }) diff --git a/packages/intl-messageformat/CHANGELOG.md b/packages/intl-messageformat/CHANGELOG.md index 20dcfc5a648..3e247a879dd 100644 --- a/packages/intl-messageformat/CHANGELOG.md +++ b/packages/intl-messageformat/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [10.7.14](https://github.com/formatjs/formatjs/compare/intl-messageformat@10.7.13...intl-messageformat@10.7.14) (2025-01-20) + +**Note:** Version bump only for package intl-messageformat + ## [10.7.13](https://github.com/formatjs/formatjs/compare/intl-messageformat@10.7.12...intl-messageformat@10.7.13) (2025-01-20) **Note:** Version bump only for package intl-messageformat diff --git a/packages/intl-messageformat/package.json b/packages/intl-messageformat/package.json index 72c233572ea..7da516fb2ce 100644 --- a/packages/intl-messageformat/package.json +++ b/packages/intl-messageformat/package.json @@ -1,6 +1,6 @@ { "name": "intl-messageformat", - "version": "10.7.13", + "version": "10.7.14", "description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.", "keywords": [ "i18n", diff --git a/packages/intl/CHANGELOG.md b/packages/intl/CHANGELOG.md index 425a35c8967..c7fb84ee001 100644 --- a/packages/intl/CHANGELOG.md +++ b/packages/intl/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [3.1.3](https://github.com/formatjs/formatjs/compare/@formatjs/intl@3.1.2...@formatjs/intl@3.1.3) (2025-01-20) + +**Note:** Version bump only for package @formatjs/intl + ## [3.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/intl@3.1.1...@formatjs/intl@3.1.2) (2025-01-20) **Note:** Version bump only for package @formatjs/intl diff --git a/packages/intl/package.json b/packages/intl/package.json index 6e53130871c..98a80c9775b 100644 --- a/packages/intl/package.json +++ b/packages/intl/package.json @@ -1,6 +1,6 @@ { "name": "@formatjs/intl", - "version": "3.1.2", + "version": "3.1.3", "description": "Internationalize JS apps. This library provides an API to format dates, numbers, and strings, including pluralization and handling translations.", "keywords": [ "intl", diff --git a/packages/react-intl/CHANGELOG.md b/packages/react-intl/CHANGELOG.md index 5b246556a8b..abd9b936f2e 100644 --- a/packages/react-intl/CHANGELOG.md +++ b/packages/react-intl/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [7.1.3](https://github.com/formatjs/formatjs/compare/react-intl@7.1.2...react-intl@7.1.3) (2025-01-20) + +**Note:** Version bump only for package react-intl + ## [7.1.2](https://github.com/formatjs/formatjs/compare/react-intl@7.1.1...react-intl@7.1.2) (2025-01-20) **Note:** Version bump only for package react-intl diff --git a/packages/react-intl/package.json b/packages/react-intl/package.json index 3545a0c33de..4137ba3b963 100644 --- a/packages/react-intl/package.json +++ b/packages/react-intl/package.json @@ -1,6 +1,6 @@ { "name": "react-intl", - "version": "7.1.2", + "version": "7.1.3", "description": "Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.", "keywords": [ "intl", diff --git a/packages/ts-transformer/CHANGELOG.md b/packages/ts-transformer/CHANGELOG.md index f4fa601a6fc..2bbbe4d02bb 100644 --- a/packages/ts-transformer/CHANGELOG.md +++ b/packages/ts-transformer/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [3.13.30](https://github.com/formatjs/formatjs/compare/@formatjs/ts-transformer@3.13.29...@formatjs/ts-transformer@3.13.30) (2025-01-20) + +**Note:** Version bump only for package @formatjs/ts-transformer + ## [3.13.29](https://github.com/formatjs/formatjs/compare/@formatjs/ts-transformer@3.13.28...@formatjs/ts-transformer@3.13.29) (2025-01-20) **Note:** Version bump only for package @formatjs/ts-transformer diff --git a/packages/ts-transformer/package.json b/packages/ts-transformer/package.json index b81f7452ead..2f52549a647 100644 --- a/packages/ts-transformer/package.json +++ b/packages/ts-transformer/package.json @@ -1,6 +1,6 @@ { "name": "@formatjs/ts-transformer", - "version": "3.13.29", + "version": "3.13.30", "description": "TS Compiler transformer for formatjs", "main": "index.js", "types": "index.d.ts", diff --git a/packages/vue-intl/CHANGELOG.md b/packages/vue-intl/CHANGELOG.md index 58b86f28690..76ef585157f 100644 --- a/packages/vue-intl/CHANGELOG.md +++ b/packages/vue-intl/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [6.5.22](https://github.com/formatjs/formatjs/compare/vue-intl@6.5.21...vue-intl@6.5.22) (2025-01-20) + +**Note:** Version bump only for package vue-intl + ## [6.5.21](https://github.com/formatjs/formatjs/compare/vue-intl@6.5.20...vue-intl@6.5.21) (2025-01-20) **Note:** Version bump only for package vue-intl diff --git a/packages/vue-intl/package.json b/packages/vue-intl/package.json index b8638576eb3..9c83b7706e9 100644 --- a/packages/vue-intl/package.json +++ b/packages/vue-intl/package.json @@ -1,6 +1,6 @@ { "name": "vue-intl", - "version": "6.5.21", + "version": "6.5.22", "description": "formatjs intl binding for vue", "main": "index.js", "repository": {