docs: add example for value interpolation (#79)

Added a short example about how to inject custom values into the translation
This commit is contained in:
pal03377 2020-06-27 01:23:10 +02:00 committed by GitHub
parent 47ca8e679f
commit f7f5ed1e59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,7 +55,17 @@ interface MessageObject {
- `format`: the format to be used. See [#formats](#formats);
- `values`: properties that should be interpolated in the message;
You can pass a `string` as the first parameter for a less verbose way of formatting a message.
You can pass a `string` as the first parameter for a less verbose way of formatting a message. It is also possible to inject values into the translation like so:
```jsonc
// en.json
{
"awesome": "{name} is awesome!"
}
```
```svelte
<h1>{$_("awesome", { values: { name: "svelte-i18n" } })}</h1> <!-- "svelte-i18n is awesome" -->
```
If the message id literal value is not in the root of the dicitonary, `.` (dots) are interpreted as a path: