Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
docs, examples: Use TOML for i18n config files
Fix #3200
  • Loading branch information
n10v authored and bep committed Apr 2, 2017
1 parent d122260 commit fe8462b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
23 changes: 11 additions & 12 deletions docs/content/content/multilingual.md
Expand Up @@ -118,21 +118,21 @@ The above also uses the `i18n` func, see [Translation of strings](#translation-o

### Translation of strings

Hugo uses [go-i18n](https://github.com/nicksnyder/go-i18n) to support string translations. Follow the link to find tools to manage your translation workflows.
Hugo uses [go-i18n](https://github.com/nicksnyder/go-i18n) to support string translations. Follow the link to find tools to manage your translation workflows.

Translations are collected from the `themes/[name]/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/[name]/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:

```
{{ 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`:
Expand All @@ -141,19 +141,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:

Expand Down
2 changes: 2 additions & 0 deletions examples/multilingual/i18n/en.toml
@@ -0,0 +1,2 @@
[head_title]
other = "Multilingual"
3 changes: 0 additions & 3 deletions examples/multilingual/i18n/en.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions examples/multilingual/i18n/et.toml
@@ -0,0 +1,2 @@
[head_title]
other = "Mitmekeelne"
2 changes: 0 additions & 2 deletions examples/multilingual/i18n/et.yaml

This file was deleted.

0 comments on commit fe8462b

Please sign in to comment.