From 284dc4266ca8c96e2eda7510cdebc9c0e3e5bc55 Mon Sep 17 00:00:00 2001 From: Dan Gold Date: Fri, 4 Jun 2021 14:07:20 -0700 Subject: [PATCH] Include flexible translation in i18n.md The flexible translation feature of the i18n function is documented within the article for Multilingual Mode, but is not mentioned in the base i18n article. This copies the relevant article section from one to the other verbatim. --- content/en/functions/i18n.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/content/en/functions/i18n.md b/content/en/functions/i18n.md index 5c2e019dc..34a6ff022 100644 --- a/content/en/functions/i18n.md +++ b/content/en/functions/i18n.md @@ -28,6 +28,27 @@ This translates a piece of content based on your `i18n/en-US.toml` files. You ca `T` is an alias to `i18n`. E.g. `{{ T "translation_id" }}`. {{% /note %}} +### Query a flexible translation with variables + +Often you will want to use the page variables in the translation strings. To do so, pass the `.` context when calling `i18n`: + +``` +{{ i18n "wordCount" . }} +``` + +The function will pass the `.` context to the `"wordCount"` id: + +{{< code-toggle file="i18n/en-US" >}} +[wordCount] +other = "This article has {{ .WordCount }} words." +{{< /code-toggle >}} + +Assume `.WordCount` in the context has value is 101. The result will be: + +``` +This article has 101 words. +``` + For more information about string translations, see [Translation of Strings in Multilingual Mode][multistrings]. [multistrings]: /content-management/multilingual/#translation-of-strings