hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit e80453a991b84280181555b8186730918ae8ee0a
parent 0dd57b907bb092d7b637a63cd378dd33b66fa1b5
Author: digitalcraftsman <digitalcraftsman@users.noreply.github.com>
Date:   Fri, 16 Sep 2016 17:20:29 +0200

tpl: Add EnableMissingTranslationPlaceholders option

Fixes #2451
Diffstat:
Mdocs/content/content/multilingual.md | 13+++++++++++++
Mdocs/content/overview/configuration.md | 2++
Mhugolib/config.go | 1+
Mtpl/template_i18n.go | 4++++
4 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/docs/content/content/multilingual.md b/docs/content/content/multilingual.md
@@ -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 }}`.
diff --git a/docs/content/overview/configuration.md b/docs/content/overview/configuration.md
@@ -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
diff --git a/hugolib/config.go b/hugolib/config.go
@@ -105,4 +105,5 @@ func loadDefaultSettings() {
 	viper.SetDefault("CurrentContentLanguage", helpers.NewDefaultLanguage())
 	viper.SetDefault("DefaultContentLanguage", "en")
 	viper.SetDefault("DefaultContentLanguageInSubdir", false)
+	viper.SetDefault("EnableMissingTranslationPlaceholders", false)
 }
diff --git a/tpl/template_i18n.go b/tpl/template_i18n.go
@@ -82,6 +82,10 @@ func SetI18nTfuncs(bndl *bundle.Bundle) {
 					return translated
 				}
 			}
+
+			if !viper.GetBool("EnableMissingTranslationPlaceholders") {
+				return ""
+			}
 			return fmt.Sprintf("[i18n] %s", translationID)
 		}
 	}