Skip to content

Commit

Permalink
Fix i18n doc
Browse files Browse the repository at this point in the history
  • Loading branch information
limodou committed Sep 20, 2015
1 parent 8ff5f07 commit af49c5d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/zh_CN/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ SUPPORT_LANGUAGES = []

## I18N语言的判定规则

### 判定规则

在Uliweb中,可以有许多种方式来决定使用哪种语言,比如:在session中,在cookie中,
通过浏览器发送的HTTP头来自动判断,还有就是在settings中的 `LANGUAGE_CODE` 来决定。
Uliweb在处理时按照以下的顺序来决定是否使用某种语言:
Expand Down Expand Up @@ -78,6 +80,16 @@ SUPPORT_LANGUAGES = ['en', 'zh_CN']

上面的定义说明当前网站支持两种语言,缺省为 `'en'`

### 调试

为了方便了解判定的结果,uliweb提供了当在URL输入 `__debug__=1` 的参数时,会在后台输出判定
的依据,输出结果类似于:

```
Detect from settings of LANGUAGE_CODE=en
```

可能的结果是 cookie, session, HTTP header, settings等。

## I18N字符串的定义

Expand Down Expand Up @@ -135,9 +147,21 @@ class User(Model):
NAME = _('username')
```

## I18N字符串的特殊处理

### 格式化

有时我们需要对符串进行格式化处理,如 `"%s" % 'hello'``"{}".format('hello')` ,这两种都是目前
Python支持的格式化处理方式,对于 i18n 字符串,可以使用format的形式来处理格式化,如:

```
_('Hello, {}').format('name')
```

## I18N字符串的提取

### 命令行用法

uliweb.contrib.i18n App提供了一个i18n的命令它提供以下参数:


Expand Down Expand Up @@ -197,6 +221,14 @@ uliweb i18n -p -l zh_CN

注意, `-l` 参数如果不提供则自动为 `'en'` 。因此,如果要翻译中文一定要加上 `-l zh_CN`

### plugs 的处理

针对plugs项目,可以使用以下命令来提取翻译串:

```
cd <plugs项目目录下>
uliweb i18n -d plugs -l zh_CN
```

## 编码注意事项

Expand Down

0 comments on commit af49c5d

Please sign in to comment.