你可以使用国际化以不同的语言渲染你的网站。默认语言通过修改 _config.yml
中的 language
设置来设置。你还可以设置多种语言并修改默认语言的顺序。
¥You can use internationalization to present your site in different languages. The default language is set by modifying the language
setting in _config.yml
. You can also set multiple languages and modify the order of default languages.
language: zh-tw |
语言文件
¥Language Files
语言文件可以是 YAML 或 JSON 文件。你应该将它们放入主题中的 languages
文件夹中。语言文件中支持 printf 格式。
¥Language files can be YAML or JSON files. You should put them into the languages
folder in the theme. There is support for the printf format in language files.
模板
¥Templates
在模板中使用 __
或 _p
助手来获取翻译的字符串。前者用于正常使用,后者用于复数字符串。例如:
¥Use __
or _p
helpers in templates to get the translated strings. The former is for normal usage and the latter is for plural strings. For example:
index: |
<%= __('index.title') %> |
路径
¥Path
你可以在 front-matter 中设置页面的语言,或者修改 _config.yml
中的 i18n_dir
设置以启用 Hexo 的自动检测。
¥You can set the language of pages in front-matter, or modify the i18n_dir
setting in _config.yml
to enable automatic detection by Hexo.
i18n_dir: :lang |
i18n_dir
设置的默认值为 :lang
,这意味着 Hexo 会在第一段 URL 中检测语言。例如:
¥The default value of i18n_dir
setting is :lang
, which means that Hexo will detect the language within the first segment of URL. For example:
/index.html => en |
仅当语言文件存在时,字符串才会作为语言提供。因此 /archives/index.html
中的 archives
(示例 2)将不会作为一种语言提供。
¥The string will only be served as a language when the language file exists. So archives
in /archives/index.html
(example 2) will not get served as a language.