Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support values property in MessageDescriptor. #16

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,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:
Expand Down
1 change: 1 addition & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>} [values] - An optional dictionary of values to be used in the message.
*/

import { writable, derived } from 'svelte/store';
Expand Down