mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-18 19:14:43 -04:00
Update content-management/multilingual to reflect new TOML support
@bogem Thanks a lot for your help, sir! And for the great work on implementing this feature. I appreciate it! 😄 Fixes rdwatters/hugo-docs-concept#64 See PR rdwatters/hugo-docs-concept#65 and PR gohugoio/hugo#3257
This commit is contained in:
parent
bf2d2bbede
commit
35fffad1e9
@ -135,7 +135,7 @@ The above also uses the [`i18n` function][i18func] described in the next section
|
||||
|
||||
Hugo uses [go-i18n][] to support string translations. [See the project's source repository][go-i18n-source] to find tools that will help you manage your translation workflows.
|
||||
|
||||
Translations are collected from the `themes/<THEME>/i18n/` folder (built into the theme), as well as translations present in `i18n/` at the root of your project. In the `i18n`, the translations will be merged and take precedence over what is in the theme folder. Language files should be named according to [RFC 5646][] with names such as `en-US.yaml`, `fr.yaml`, etc.
|
||||
Translations are collected from the `themes/<THEME>/i18n/` folder (built into the theme), as well as translations present in `i18n/` at the root of your project. In the `i18n`, the translations will be merged and take precedence over what is in the theme folder. Language files should be named according to [RFC 5646][] with names such as `en-US.toml`, `fr.toml`, etc.
|
||||
|
||||
From within your templates, use the `i18n` function like this:
|
||||
|
||||
@ -143,11 +143,11 @@ From within your templates, use the `i18n` function like this:
|
||||
{{ i18n "home" }}
|
||||
```
|
||||
|
||||
This uses a definition like this one in `i18n/en-US.yaml`:
|
||||
This uses a definition like this one in `i18n/en-US.toml`:
|
||||
|
||||
```
|
||||
- id: home
|
||||
translation: "Home"
|
||||
[home]
|
||||
other = "Home"
|
||||
```
|
||||
|
||||
Often you will want to use to the page variables in the translations strings. To do that, pass on the "." context when calling `i18n`:
|
||||
@ -156,19 +156,18 @@ 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`:
|
||||
This uses a definition like this one in `i18n/en-US.toml`:
|
||||
|
||||
```
|
||||
- id: wordCount
|
||||
translation: "This article has {{ .WordCount }} words."
|
||||
[wordCount]
|
||||
other = "This article has {{ .WordCount }} words."
|
||||
```
|
||||
An example of singular and plural form:
|
||||
|
||||
```
|
||||
- id: readingTime
|
||||
translation:
|
||||
one: "One minute read"
|
||||
other: "{{.Count}} minutes read"
|
||||
[readingTime]
|
||||
one = "One minute read"
|
||||
other = "{{.Count}} minutes read"
|
||||
```
|
||||
And then in the template:
|
||||
|
||||
@ -186,7 +185,7 @@ i18n|MISSING_TRANSLATION|en|wordCount
|
||||
|
||||
At the time of this writing, Golang does not yet have support for internationalized locales, but if you do some work, you can simulate it. For example, if you want to use French month names, you can add a data file like ``data/mois.yaml`` with this content:
|
||||
|
||||
~~~toml
|
||||
~~~yaml
|
||||
1: "janvier"
|
||||
2: "février"
|
||||
3: "mars"
|
||||
@ -283,4 +282,4 @@ If there is more than one language defined, the `LanguagePrefix` variable will e
|
||||
[menus]: /content-management/menus/
|
||||
[rellangurl]: /functions/rellangurl
|
||||
[RFC 5646]: https://tools.ietf.org/html/rfc5646
|
||||
[singles]: /templates/single-page-templates/
|
||||
[singles]: /templates/single-page-templates/
|
||||
|
Loading…
x
Reference in New Issue
Block a user