From b3b1df75d68e43c95c84e77fe027ddcff8aa26ab Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Fri, 15 Dec 2023 08:54:20 -0800 Subject: [PATCH] Describe lang.Translate fallback behavior --- .cspell.json | 5 ++++- content/en/functions/lang/Translate.md | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.cspell.json b/.cspell.json index ae469d646..1c386ee29 100644 --- a/.cspell.json +++ b/.cspell.json @@ -7,8 +7,10 @@ "flagWords": [ "alot", "hte", + "langauge", "reccommend", - "seperate" + "seperate", + "teh" ], "ignorePaths": [ "**/emojis.md", @@ -69,6 +71,7 @@ "transpile", "transpiles", "unmarshal", + "unmarshals", "unmarshaling", "# ----------------------------------------------------------------------", "# cspell: ignore foreign language words", diff --git a/content/en/functions/lang/Translate.md b/content/en/functions/lang/Translate.md index 630098a96..108873384 100644 --- a/content/en/functions/lang/Translate.md +++ b/content/en/functions/lang/Translate.md @@ -8,9 +8,27 @@ action: related: [] returnType: string signatures: ['lang.Translate KEY [CONTEXT]'] +toc: true aliases: [/functions/i18n] --- +The `lang.Translate` function returns the value associated with given key as defined in the translation table for the current language. + +If the key is not found in the translation table for the current language, the `lang.Translate` function falls back to the translation table for the [`defaultContentLanguage`]. + +If the key is not found in the translation table for the `defaultContentLanguage`, the `lang.Translate` function returns an empty string. + +[`defaultContentLanguage`]: /getting-started/configuration/#defaultcontentlanguage + +{{% note %}} +To list missing and fallback translations, use the `--printI18nWarnings` flag when building your site. + +To render placeholders for missing and fallback translations, set +[`enableMissingTranslationPlaceholders`] to `true` in your site configuration. + +[`enableMissingTranslationPlaceholders`]: /getting-started/configuration/#enablemissingtranslationplaceholders +{{% /note %}} + Let's say your multilingual site supports two languages, English and Polish. Create a translation table for each language in the `i18n` directory. ```text