i18n
少于1分钟
将以下英文翻译为中文:
i18n
https://gohugo.io/functions/i18n/
Translates a piece of content based on your i18n configuration files.
语法
i18n KEY
T KEY
lang.Translate KEY
This translates a piece of content based on your i18n/en-US.toml files. You can use the go-i18n tools to manage your translations. The translations can exist in both the theme and at the root of your repository.
| |
T is an alias to i18n. E.g. {{ T "translation_id" }}.
Query a flexible translation with variables
Often you will want to use the page variables in the translation strings. To do so, pass the . context when calling i18n:
| |
The function will pass the . context to the "wordCount" id:
i18n/en-US.
=== “yaml”
``` yaml
wordCount:
other: This article has {{ .WordCount }} words.
```
=== “toml”
``` toml
[wordCount]
other = 'This article has {{ .WordCount }} words.'
```
=== “json”
``` json
{
"wordCount": {
"other": "This article has {{ .WordCount }} words."
}
}
```
Assume .WordCount in the context has value is 101. The result will be:
This article has 101 words.
For more information about string translations, see Translation of Strings in Multilingual Mode.