simplest-i18n
Advanced tools
Comparing version 0.0.1 to 0.1.0
{ | ||
"name": "simplest-i18n", | ||
"description": "The simplest universal i18n solution", | ||
"description": "The Simplest Universal i18n Solution", | ||
"author": "Ken Berkeley <kenberkeley@foxmail.com>", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"main": "i18n.min.js", | ||
@@ -12,3 +12,5 @@ "scripts": { | ||
"pretest": "npm run lint", | ||
"test": "ava test.js" | ||
"test": "ava test.js", | ||
"vue": "poi examples/vue/app.js", | ||
"react": "poi --jsx react examples/react/app.js" | ||
}, | ||
@@ -34,2 +36,6 @@ "repository": { | ||
"ava": "^0.24.0", | ||
"js-cookie": "^2.2.0", | ||
"poi": "^9.6.12", | ||
"react": "^16.2.0", | ||
"react-dom": "^16.2.0", | ||
"standard": "^10.0.3", | ||
@@ -36,0 +42,0 @@ "uglify-js": "^3.3.5" |
@@ -1,2 +0,2 @@ | ||
# The simplest universal i18n solution | ||
# The Simplest Universal i18n Solution | ||
@@ -7,2 +7,7 @@ [![npm version][npm-v-img]][npm-url] | ||
## $ Features | ||
* Support browsers and Node.js | ||
* No dependencies (source code < 0.5KB) | ||
* Does not rely on any framework (React / Vue / Angular / ...) or any bundler (Webpack / Parcel / Rollup / ...) | ||
* Extremely simple and flexible | ||
@@ -16,5 +21,39 @@ ## $ Installation | ||
## $ Usage | ||
```js | ||
import i18n from 'simplest-i18n' | ||
const t = i18n({ | ||
locale: navigator.language.toLowerCase(), // e.g. here yields 'en-us' | ||
locales: [ | ||
// it is recommended that set your mother tongue as the first locale (e.g. Simplified Chinese for me) | ||
'zh-cn', | ||
'en-us', | ||
'ja' | ||
] | ||
}) | ||
console.log( | ||
t( | ||
'你好', | ||
'Hello', | ||
'こんにちは' | ||
) | ||
) // outputs 'Hello' | ||
``` | ||
*** | ||
There are code examples for React and Vue in [`examples/`](./examples/) | ||
Check it out and run it with the following directives: | ||
``` | ||
>_ git clone https://github.com/kenberkeley/simplest-i18n | ||
>_ npm i | ||
>_ npm run react (or npm run vue) | ||
``` | ||
[npm-url]: https://www.npmjs.com/package/simplest-i18n | ||
[npm-v-img]: http://img.shields.io/npm/v/simplest-i18n.svg | ||
[npm-dl-img]: http://img.shields.io/npm/dm/simplest-i18n.svg |
import test from 'ava' | ||
import i18n from './i18n' | ||
import i18n from './' | ||
@@ -4,0 +4,0 @@ // name as `$t`, avoid conflicting with `t` of ava |
7597
14
142
58
7