ref: e80453a991b84280181555b8186730918ae8ee0a
parent: 0dd57b907bb092d7b637a63cd378dd33b66fa1b5
author: digitalcraftsman <[email protected]>
date: Fri Sep 16 13:20:29 EDT 2016
tpl: Add EnableMissingTranslationPlaceholders option Fixes #2451
--- a/docs/content/content/multilingual.md
+++ b/docs/content/content/multilingual.md
@@ -119,7 +119,9 @@
```
{{ i18n "home" }}
```
+
This uses a definition like this one in `i18n/en-US.yaml`:
+
```
- id: home
translation: "Home"
@@ -130,11 +132,14 @@
```
{{ i18n "wordCount" . }}
```
+
This uses a definition like this one in `i18n/en-US.yaml`:
+
```
- id: wordCount
translation: "This article has {{ .WordCount }} words."
```
+
To track down missing translation strings, run Hugo with the `--i18n-warnings` flag:
```bash
@@ -143,6 +148,7 @@
```
+
### Menus
You can define your menus for each language independently. The [creation of a menu]({{< relref "extras/menus.md" >}}) works analogous to earlier versions of Hugo, except that they have to be defined in their language-specific block in the configuration file:
@@ -183,6 +189,13 @@
</ul>
```
+
+An empty string will be shown if the translation for the current language is missing and no default value is set.
+
+While translating a Hugo website it can be handy to have a visual indicator as well. The `EnableMissingTranslationPlaceholders` config option allows you to replace the empty string with a placeholder like `[i18n] identifier`, where `identifier` is the id of the missing translation.
+
+**Remember: Hugo will generate your website with these placeholders. It might not be suited for production environments.**
+
### Multilingual Themes support
--- a/docs/content/overview/configuration.md
+++ b/docs/content/overview/configuration.md
@@ -118,6 +118,8 @@
# Enable Emoji emoticons support for page content.
# See www.emoji-cheat-sheet.com
enableEmoji: false
+ # Show a placeholder like "[i18n] foo" instead of an empty string if a translation is missing
+ enableMissingTranslationPlaceholders: false
footnoteAnchorPrefix: ""
footnoteReturnLinkContents: ""
# google analytics tracking id
--- a/hugolib/config.go
+++ b/hugolib/config.go
@@ -105,4 +105,5 @@
viper.SetDefault("CurrentContentLanguage", helpers.NewDefaultLanguage())
viper.SetDefault("DefaultContentLanguage", "en")
viper.SetDefault("DefaultContentLanguageInSubdir", false)
+ viper.SetDefault("EnableMissingTranslationPlaceholders", false)
}
--- a/tpl/template_i18n.go
+++ b/tpl/template_i18n.go
@@ -82,6 +82,10 @@
return translated
}
}
+
+ if !viper.GetBool("EnableMissingTranslationPlaceholders") {
+ return ""
+ }
return fmt.Sprintf("[i18n] %s", translationID)
}
}