Improve language handling in URLs

The current "rendering language" is needed outside of Site. This commit moves the Language type to the helpers package, and then used to get correct correct language configuration in the markdownify template func.
This commit also adds two new template funcs: relLangURL and absLangURL.

See #2309
This commit is contained in:
Bjørn Erik Pedersen 2016-08-07 22:01:55 +02:00
parent e4b43f02e7
commit b210fe9d76
2 changed files with 8 additions and 1 deletions

View File

@ -135,7 +135,7 @@ This uses a definition like this one in `i18n/en-US.yaml`:
### 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 `relURL` or `absURL` -- or prefixed with `{{.LanguagePrefix }}`.
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 }}`.
If there are more than one language defined, the`LanguagePrefix` variable will equal `"/en"` (or whatever your `CurrentLanguage` is). If not enabled, it will be an empty string, so it is harmless for single-language sites.

View File

@ -787,6 +787,13 @@ e.g.: `{{ i18n "translation_id" }}`
* `{{ mul 1000 (time "2016-05-28T10:30:00.00+10:00").Unix }}` → 1464395400000 (Unix time in milliseconds)
## URLs
### absLangURL, relLangURL
These are similar to the `absURL` and `relURL` relatives below, but will add the correct language prefix when the site is configured with more than one language.
So for a site `baseURL` set to `http://mysite.com/hugo/` and the current language is `en`:
* `{{ "blog/" | absLangURL }}` → "http://mysite.com/hugo/en/blog/"
* `{{ "blog/" | relLangURL }}` → "/hugo/en/blog/"
### absURL, relURL