This commit is contained in:
zhaoyingbo 2022-12-26 10:48:28 +08:00
parent 1f95d64e6a
commit 86f690c1eb

View File

@ -1,21 +1,19 @@
# 🐤 kiwi-intl [![npm version](https://badge.fury.io/js/kiwi-intl.svg)](http://badge.fury.io/js/kiwi-intl)
# 🐤 canary-intl
通用的国际化框架,不绑定任何框架。
## 如何使用
> yarn add kiwi-intl
> 推荐与[🐤 Kiwi-国际化全流程解决方案](https://github.com/alibaba/kiwi)结合使用
> yarn add canary-intl
## 使用 API
初始化国际化框架
```javascript
import KiwiIntl from 'kiwi-intl';
import canaryIntl from 'canary-intl';
const kiwiIntl = KiwiIntl.init('en-UK', {
const canaryIntl = canaryIntl.init('en-UK', {
'en-UK': {
test: 'testvalue',
testTemplate: 'you have {value} unread message',
@ -28,23 +26,23 @@ const kiwiIntl = KiwiIntl.init('en-UK', {
});
```
在组件中直接使用,支持模板, 单复数。同时支持 `kiwiIntl.test`,直接取对应 Key 值。
在组件中直接使用,支持模板, 单复数。同时支持 `canaryIntl.test`,直接取对应 Key 值。
```javascript
kiwiIntl.test; // testvalue;
canaryIntl.test; // testvalue;
kiwiIntl.get('test'); // testvalue;
canaryIntl.get('test'); // testvalue;
kiwiIntl.get('testTemplate', {
canaryIntl.get('testTemplate', {
value: three
}); // 值是 'you have three unread message'
kiwiIntl.template(kiwiIntl.testTemplate, {
canaryIntl.template(canaryIntl.testTemplate, {
value: three
}); // 值是 'you have three unread message'
kiwiIntl.get('photo', {
canaryIntl.get('photo', {
num: 0
}); // 值是 'You have no photos.'
```
@ -52,7 +50,7 @@ kiwiIntl.get('photo', {
切换语言
```javascript
kiwiIntl.setLang('zh-CN'); // 切换到中文语言
canaryIntl.setLang('zh-CN'); // 切换到中文语言
```
## 语言编码
【强制】区别不同语言的 language tag 遵循 [BCP47](https://en.wikipedia.org/wiki/IETF_language_tag) 规范。