From 8d1c3ba9fe9d03126d488583adf73957be4a7a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valeriu=20Palo=C8=99?= Date: Mon, 30 Dec 2024 04:21:07 +0200 Subject: [PATCH 1/6] Add .values property to MessageDescriptor definition. --- src/lib/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/index.js b/src/lib/index.js index 8c874eb..4b49211 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -4,6 +4,7 @@ * @property {string} message - The message to be translated. * @property {string} [context] - The context of the message, will be included in the po file. The same message with different context will be extracted as separate entries, and can be translated differently. * @property {string} [comment] - A comment purely for giving information to the translator, won't affect translated string. + * @property {Record} [values] - An optional dictionary of values to be used in the message. */ import { writable, derived } from 'svelte/store'; From df2e51c9be86800d0a3a0c4298f24cf3f0dcac49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valeriu=20Palo=C8=99?= Date: Mon, 30 Dec 2024 04:27:19 +0200 Subject: [PATCH 2/6] Update the documentation to reflect the usage of MessageDescriptor values. --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 18ffc4b..5e9e94a 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,15 @@ To include components or elements in the middle of the message, use the provided ### MessageDescriptor Format +When you need to interpolate dynamic values into the message, you can use the `values` property in the MessageDescriptor object: + +```svelte +{$t({ + message: 'Hello {name}', + values: { name: 'John' } +})} +``` + Sometimes we'll need to add a context info for messages that are exactly the same in the base language, but has different meanings in different places (e.g. in English `right` can either refer to direction or correctness). We can add a context by passing a message descriptor instead of plain string or literal string: ```svelte @@ -237,7 +246,7 @@ Since Svelte's stores are meant to be used in Svelte components, using them insi ## Known issues - When extracting to Lingui's PO format and enabling the `origins` option, the line numbers are always empty for `` components usage. The line numbers work on any other syntax. - - When working in a larger project in a team, I suggest disabling origins on the PO file anyway, since they cause a lot of line changes in diff view every time a string is added/reused. This might cause merge conflicts when two people are modifying or reusing the same string, for example. + - When working in a larger project in a team, I suggest disabling origins on the PO file anyway, since they cause a lot of line changes in diff view every time a string is added/reused. This might cause merge conflicts when two people are modifying or reusing the same string, for example. ## Contributing From cd11b52dca8f28f6741ed97c9cdac079709d8999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valeriu=20Palo=C8=99?= Date: Mon, 30 Dec 2024 04:29:49 +0200 Subject: [PATCH 3/6] Removed unpexpected prettier change. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e9e94a..60501db 100644 --- a/README.md +++ b/README.md @@ -246,7 +246,7 @@ Since Svelte's stores are meant to be used in Svelte components, using them insi ## Known issues - When extracting to Lingui's PO format and enabling the `origins` option, the line numbers are always empty for `` components usage. The line numbers work on any other syntax. - - When working in a larger project in a team, I suggest disabling origins on the PO file anyway, since they cause a lot of line changes in diff view every time a string is added/reused. This might cause merge conflicts when two people are modifying or reusing the same string, for example. + - When working in a larger project in a team, I suggest disabling origins on the PO file anyway, since they cause a lot of line changes in diff view every time a string is added/reused. This might cause merge conflicts when two people are modifying or reusing the same string, for example. ## Contributing From bc46927eade02fc0d4e8b98b77bb616aa4a536b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valeriu=20Palo=C8=99?= Date: Mon, 30 Dec 2024 04:41:50 +0200 Subject: [PATCH 4/6] Any, value types (just as in Lingui). Minor doc correction. --- README.md | 18 +++++++++--------- src/lib/index.js | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 60501db..7d6f54e 100644 --- a/README.md +++ b/README.md @@ -181,15 +181,6 @@ To include components or elements in the middle of the message, use the provided ### MessageDescriptor Format -When you need to interpolate dynamic values into the message, you can use the `values` property in the MessageDescriptor object: - -```svelte -{$t({ - message: 'Hello {name}', - values: { name: 'John' } -})} -``` - Sometimes we'll need to add a context info for messages that are exactly the same in the base language, but has different meanings in different places (e.g. in English `right` can either refer to direction or correctness). We can add a context by passing a message descriptor instead of plain string or literal string: ```svelte @@ -210,6 +201,15 @@ We can also add a comment for the translators reading the message catalog e.g. t })} ``` +Also, if you need to interpolate dynamic values into the message, you can use the `values` property in the MessageDescriptor object: + +```svelte +{$t({ + message: 'Hello {name}!', + values: { name: 'World' } +})} +``` + ### Plurals To provide different messages for text with numbers, use the provided `$plural` store: diff --git a/src/lib/index.js b/src/lib/index.js index 4b49211..f164daf 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -4,7 +4,7 @@ * @property {string} message - The message to be translated. * @property {string} [context] - The context of the message, will be included in the po file. The same message with different context will be extracted as separate entries, and can be translated differently. * @property {string} [comment] - A comment purely for giving information to the translator, won't affect translated string. - * @property {Record} [values] - An optional dictionary of values to be used in the message. + * @property {Record} [values] - An optional dictionary of values to be used in the message. */ import { writable, derived } from 'svelte/store'; From ff414fd84262661ed6754f798fcb9889472de0b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valeriu=20Palo=C8=99?= Date: Mon, 30 Dec 2024 05:36:22 +0200 Subject: [PATCH 5/6] Minor version increment. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 46153d9..b5e6fa8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte-i18n-lingui", - "version": "0.2.0", + "version": "0.2.1", "author": "Henry Roes Lie", "license": "MIT", "description": "Add i18n to Svelte/Sveltekit projects using Lingui, using message as the catalog id", From 4418406cd9a6435826e9e443419c88c0aecf8c3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valeriu=20Palo=C5=9F?= Date: Mon, 20 Jan 2025 19:36:15 +0200 Subject: [PATCH 6/6] Defer version update for later tagging. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5e6fa8..46153d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte-i18n-lingui", - "version": "0.2.1", + "version": "0.2.0", "author": "Henry Roes Lie", "license": "MIT", "description": "Add i18n to Svelte/Sveltekit projects using Lingui, using message as the catalog id",