tpl: Add EnableMissingTranslationPlaceholders option
authordigitalcraftsman <digitalcraftsman@users.noreply.github.com>
Fri, 16 Sep 2016 15:20:29 +0000 (17:20 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 16 Sep 2016 15:20:29 +0000 (17:20 +0200)
Fixes #2451

docs/content/content/multilingual.md
docs/content/overview/configuration.md
hugolib/config.go
tpl/template_i18n.go

index a89b28108e6f0ae503c1ffa6a5dfbcb633db2516..86da754097e7dc76afee15e0f854d77f084c2d1a 100644 (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 }}`.
index 67b0a6b9695cb5f24b315e79c60eb6cfc2d35891..0d07bc947b0f83799da6236b3dd841eabba5c955 100644 (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
index d31a38a5acd065739fbfd9c1fd35c015cca25492..86c35964c3c0e0c2e419708ad392f89bc816c244 100644 (file)
@@ -105,4 +105,5 @@ func loadDefaultSettings() {
        viper.SetDefault("CurrentContentLanguage", helpers.NewDefaultLanguage())
        viper.SetDefault("DefaultContentLanguage", "en")
        viper.SetDefault("DefaultContentLanguageInSubdir", false)
+       viper.SetDefault("EnableMissingTranslationPlaceholders", false)
 }
index b973f4cd03f3701f80c9d1b47cfb54cd5df70433..bac449035b78269ebb5f0de8ac23ddc9e506a473 100644 (file)
@@ -82,6 +82,10 @@ func SetI18nTfuncs(bndl *bundle.Bundle) {
                                        return translated
                                }
                        }
+
+                       if !viper.GetBool("EnableMissingTranslationPlaceholders") {
+                               return ""
+                       }
                        return fmt.Sprintf("[i18n] %s", translationID)
                }
        }