From f7f5ed1e599daf2dc2e1fe35110efbbf243e9f2c Mon Sep 17 00:00:00 2001 From: pal03377 Date: Sat, 27 Jun 2020 01:23:10 +0200 Subject: [PATCH] docs: add example for value interpolation (#79) Added a short example about how to inject custom values into the translation --- docs/Formatting.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/Formatting.md b/docs/Formatting.md index fca89c9..9e12b2d 100644 --- a/docs/Formatting.md +++ b/docs/Formatting.md @@ -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 +

{$_("awesome", { values: { name: "svelte-i18n" } })}

+``` If the message id literal value is not in the root of the dicitonary, `.` (dots) are interpreted as a path: