tpl: Add EnableMissingTranslationPlaceholders option

Fixes #2451
This commit is contained in:
digitalcraftsman 2016-09-16 17:20:29 +02:00 committed by Bjørn Erik Pedersen
parent 0dd57b907b
commit e80453a991
4 changed files with 20 additions and 0 deletions

View file

@ -119,7 +119,9 @@ From within your templates, use the `i18n` function like this:
```
{{ i18n "home" }}
```
This uses a definition like this one in `i18n/en-US.yaml`:
```
- id: home
translation: "Home"
@ -130,11 +132,14 @@ Often you will want to use to the page variables in the translations strings. To
```
{{ 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 @@ i18n|MISSING_TRANSLATION|en|wordCount
```
### 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:
@ -184,6 +190,13 @@ The rendering of the main navigation works as usual. `.Site.Menus` will just con
```
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
To support Multilingual mode in your themes, some considerations must be taken for the URLs in the templates. If there are more than one language, URLs must either come from the built-in `.Permalink` or `.URL`, be constructed with `relLangURL` or `absLangURL` template funcs -- or prefixed with `{{.LanguagePrefix }}`.

View file

@ -118,6 +118,8 @@ Following is a list of Hugo-defined variables that you can configure and their c
# 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

View file

@ -105,4 +105,5 @@ func loadDefaultSettings() {
viper.SetDefault("CurrentContentLanguage", helpers.NewDefaultLanguage())
viper.SetDefault("DefaultContentLanguage", "en")
viper.SetDefault("DefaultContentLanguageInSubdir", false)
viper.SetDefault("EnableMissingTranslationPlaceholders", false)
}

View file

@ -82,6 +82,10 @@ func SetI18nTfuncs(bndl *bundle.Bundle) {
return translated
}
}
if !viper.GetBool("EnableMissingTranslationPlaceholders") {
return ""
}
return fmt.Sprintf("[i18n] %s", translationID)
}
}