Skip to content

Commit

Permalink
📝 Docs: update docs, add objectAdapter.setLocales
Browse files Browse the repository at this point in the history
  • Loading branch information
Spades-S committed May 1, 2020
1 parent 513d363 commit 36b1684
Showing 1 changed file with 53 additions and 25 deletions.
78 changes: 53 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## i18n

![CI Test](https://github.com/PicGo/i18n/workflows/CI%20Test/badge.svg)

i18n工具
i18n 工具

### 用法

Expand All @@ -25,7 +26,7 @@ const objectAdapter = new ObjectAdapter({
zh: {
user: {
name: 'PicGo',
country: 'China',
country: '中国',
},
report: {
singular: ' ${cnt}个报告',
Expand Down Expand Up @@ -60,6 +61,8 @@ class CustomAdapter extends BaseAdapter {

### API

#### I18n

- 构造函数 I18n

- 参数: options
Expand All @@ -71,6 +74,37 @@ class CustomAdapter extends BaseAdapter {
```
- 返回值: I18n 实例

* i18n.setLanguage

- 参数: language, 语言类型
- 无返回值

* i18n.getLauguage

- 无参数
- 返回当前语言类型

* i18n.translate

- 参数 phrase, args
- 返回翻译后文本

```json
// en.json
{
"report": {
"singular": "only ${cnt} report",
"plural": "${cnt} reports"
}
}
```

```js
i18n.translate('report.singular', { cnt: 1 }); // only 1 report
```

#### FileSyncAdapter

- 构造函数 FileSyncAdapter

- 参数: options
Expand All @@ -82,7 +116,13 @@ class CustomAdapter extends BaseAdapter {
```
- 返回 FileSyncAdapter 实例

- ObjectAdapter
- fileSyncAdapter.getLocale
- 参数 languag, 语言类型
- 返回 language 对应的 locale 数据

#### ObjectAdapter

- 构造函数 ObjectAdapter

- 参数 locales, 保存 locales 信息的对象

Expand Down Expand Up @@ -113,32 +153,20 @@ class CustomAdapter extends BaseAdapter {

- 返回 ObjectAdapter 实例

- i18n.setLanguage
- objectAdapter.getLocale
- 参数 languag, 语言类型
- 返回 language 对应的 locale 数据

- 参数: language
* objectAdapter.setLocales 用于动态修改 objectAdapter 上的 locales 数据
- 参数 locales, locales 数据
- 无返回值

- i18n.getLauguage

- 返回当前语言类型

- i18n.translate

- 参数 phrase, args
- 返回翻译后文本

```json
// en.json
{
"report": {
"singular": "only ${cnt} report",
"plural": "${cnt} reports"
}
}
```

```js
i18n.translate('report.singular', { cnt: 1 }); // only 1 report
objectAdapter.setLocales({
zh: {
newData: 'this is new Data',
},
});
```

### License
Expand Down

0 comments on commit 36b1684

Please sign in to comment.