Internationalization (i18n)

  • 2018-12-03

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.

1
2
3
4
5
language: zh-tw

language:
- zh-tw
- en

Language Files

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

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:

en.yml
1
2
3
4
5
6
7
index:
title: Home
add: Add
video:
zero: No videos
one: One video
other: %d videos
1
2
3
4
5
<%= __('index.title') %>
// Home

<%= _p('index.video', 3) %>
// 3 videos

Path

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.

1
i18n_dir: :lang

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:

1
2
3
/index.html => en
/archives/index.html => en
/zh-tw/index.html => zh-tw

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.

扫码领红包

2018双11超级红包
PC访问链接: 2018双11超级红包 预售开启 汇聚全球潮流新品

淘口令:¥20Y0b6q4eHR¥ (复制此行再打开手机淘宝客访问)

最后更新: 2018年12月03日 09:29

原始链接: https://cyc.oy99.com/docs/internationalization.html

× 多少都行~
打赏二维码
×
  • {title}