https://github.com/ckpack/i18n
A lightweight internationalization library
https://github.com/ckpack/i18n
i18n
Last synced: 5 months ago
JSON representation
A lightweight internationalization library
- Host: GitHub
- URL: https://github.com/ckpack/i18n
- Owner: ckpack
- License: mit
- Created: 2021-03-24T15:15:36.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-10-28T08:58:13.000Z (over 1 year ago)
- Last Synced: 2025-11-23T02:02:58.616Z (7 months ago)
- Topics: i18n
- Language: TypeScript
- Homepage: https://ckpack.github.io/i18n/
- Size: 610 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# i18n
A lightweight internationalization library
```js
const i18n = new I18n({
locale: defaultLocale,
fallbackLocale: defaultLocale,
messages: {
zh: {
hello: "你好 世界",
nest: {
author: "作者: {name}"
},
amount: (v: string | number) => `${v}元`
},
en: {
hello: "hello world",
nest: {
author: "author: {name}"
},
amount: (v: string | number) => `${v}$`
}
}
});
// defaultLocale = "zh";
i18n.t('hello') // 你好 世界
i18n.t('nest.author', {name: 'xiaohong'}) // 作者: xiaohong
// defaultLocale = "en";
i18n.t('hello') // hello world
i18n.t('nest.author', {name: 'xiaohong'}) // author: xiaohong
```
## [Demo](https://ckpack.github.io/i18n/)