{"_id":"simplest-i18n","_rev":"4170352","name":"simplest-i18n","description":"The Simplest Universal i18n Solution","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"kenberkeley","email":""}],"time":{"modified":"2026-03-01T21:13:45.000Z","created":"2018-01-08T09:14:09.951Z","1.0.0":"2018-01-16T06:46:39.275Z","0.1.0":"2018-01-15T11:23:39.298Z","0.0.1":"2018-01-08T09:14:09.951Z"},"users":{},"author":{"name":"Ken Berkeley","email":"kenberkeley@foxmail.com"},"repository":{"type":"git","url":"git+https://github.com/kenberkeley/simplest-i18n.git"},"versions":{"1.0.0":{"name":"simplest-i18n","description":"The Simplest Universal i18n Solution","author":{"name":"Ken Berkeley","email":"kenberkeley@foxmail.com"},"version":"1.0.0","main":"i18n.min.js","scripts":{"lint":"standard i18n.js","prebuild":"npm run lint","build":"uglifyjs i18n.js -c -m -o i18n.min.js","pretest":"npm run lint","test":"ava test.js","vue":"poi examples/vue/app.js","react":"poi --jsx react examples/react/app.js"},"repository":{"type":"git","url":"git+https://github.com/kenberkeley/simplest-i18n.git"},"keywords":["i18n","internationalization","isomorphic","locale","localization","globalization","simple","simplest","translate","translation","universal"],"devDependencies":{"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","uglify-js":"^3.3.5"},"license":"MIT","gitHead":"b051acbc8183496425b829f231da90eb1bc8cab9","bugs":{"url":"https://github.com/kenberkeley/simplest-i18n/issues"},"homepage":"https://github.com/kenberkeley/simplest-i18n#readme","_id":"simplest-i18n@1.0.0","_shasum":"1cf059aad9f92aadfd25fa19d24a8abaa02c506c","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.6.0","_npmUser":{"name":"kenberkeley","email":"kenberkeley@foxmail.com"},"dist":{"shasum":"1cf059aad9f92aadfd25fa19d24a8abaa02c506c","size":4637,"noattachment":false,"key":"/simplest-i18n/-/simplest-i18n-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/simplest-i18n/download/simplest-i18n-1.0.0.tgz"},"maintainers":[{"name":"kenberkeley","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simplest-i18n-1.0.0.tgz_1516085199216_0.47563319746404886"},"directories":{},"publish_time":1516085199275,"_hasShrinkwrap":false,"_cnpm_publish_time":1516085199275,"_cnpmcore_publish_time":"2021-12-16T15:36:40.371Z"},"0.1.0":{"name":"simplest-i18n","description":"The Simplest Universal i18n Solution","author":{"name":"Ken Berkeley","email":"kenberkeley@foxmail.com"},"version":"0.1.0","main":"i18n.min.js","scripts":{"lint":"standard i18n.js","prebuild":"npm run lint","build":"uglifyjs i18n.js -c -m -o i18n.min.js","pretest":"npm run lint","test":"ava test.js","vue":"poi examples/vue/app.js","react":"poi --jsx react examples/react/app.js"},"repository":{"type":"git","url":"git+https://github.com/kenberkeley/simplest-i18n.git"},"keywords":["i18n","internationalization","isomorphic","locale","localization","globalization","simple","simplest","translate","translation","universal"],"devDependencies":{"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","uglify-js":"^3.3.5"},"license":"MIT","gitHead":"3d4f38685674b76cb18b013af00ecda68c554724","bugs":{"url":"https://github.com/kenberkeley/simplest-i18n/issues"},"homepage":"https://github.com/kenberkeley/simplest-i18n#readme","_id":"simplest-i18n@0.1.0","_shasum":"9473e852fdb07c17a116bb9419bb6512b0a62b04","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.6.0","_npmUser":{"name":"kenberkeley","email":"kenberkeley@foxmail.com"},"dist":{"shasum":"9473e852fdb07c17a116bb9419bb6512b0a62b04","size":3535,"noattachment":false,"key":"/simplest-i18n/-/simplest-i18n-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/simplest-i18n/download/simplest-i18n-0.1.0.tgz"},"maintainers":[{"name":"kenberkeley","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simplest-i18n-0.1.0.tgz_1516015419217_0.9267799435183406"},"directories":{},"publish_time":1516015419298,"_hasShrinkwrap":false,"_cnpm_publish_time":1516015419298,"_cnpmcore_publish_time":"2021-12-16T15:36:40.571Z"},"0.0.1":{"name":"simplest-i18n","description":"The simplest universal i18n solution","author":{"name":"Ken Berkeley","email":"kenberkeley@foxmail.com"},"version":"0.0.1","main":"i18n.min.js","scripts":{"lint":"standard i18n.js","prebuild":"npm run lint","build":"uglifyjs i18n.js -c -m -o i18n.min.js","pretest":"npm run lint","test":"ava test.js"},"repository":{"type":"git","url":"git+https://github.com/kenberkeley/simplest-i18n.git"},"keywords":["i18n","internationalization","isomorphic","locale","localization","globalization","simple","simplest","translate","translation","universal"],"devDependencies":{"ava":"^0.24.0","standard":"^10.0.3","uglify-js":"^3.3.5"},"license":"MIT","gitHead":"1ef807d527a0f775c0df51a635acbb1b2dca818a","bugs":{"url":"https://github.com/kenberkeley/simplest-i18n/issues"},"homepage":"https://github.com/kenberkeley/simplest-i18n#readme","_id":"simplest-i18n@0.0.1","_shasum":"987b2b4a8aa7c9952cfbb4516d03587fb398daf2","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.6.0","_npmUser":{"name":"kenberkeley","email":"kenberkeley@foxmail.com"},"dist":{"shasum":"987b2b4a8aa7c9952cfbb4516d03587fb398daf2","size":1966,"noattachment":false,"key":"/simplest-i18n/-/simplest-i18n-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/simplest-i18n/download/simplest-i18n-0.0.1.tgz"},"maintainers":[{"name":"kenberkeley","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simplest-i18n-0.0.1.tgz_1515402849837_0.28417030605487525"},"directories":{},"publish_time":1515402849951,"_hasShrinkwrap":false,"_cnpm_publish_time":1515402849951,"_cnpmcore_publish_time":"2021-12-16T15:36:40.838Z"}},"readme":"# The Simplest Universal i18n Solution\r\n\r\n[![npm version][npm-v-img]][npm-url]\r\n[![npm download][npm-dl-img]][npm-url]\r\n[![build][build-img]][build-url]\r\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\r\n\r\n## § Preface\r\nIn most cases, **internationalization** is actually translating your website into English  \r\nWhich means that you might not need a cumbersome framework to implement this  \r\nAnd this tiny repo is for you!\r\n\r\n## § Features\r\n* Support browsers and Node.js\r\n* No dependencies (compressed [source code](./i18n.js) < 0.5KB, extremely simple and comprehensible)\r\n* Does not rely on any framework (React / Vue / Angular / ...) or any bundler (Webpack / Parcel / Rollup / ...)\r\n* No tedious and verbose documentation (Just this README)\r\n\r\n## § Installation\r\n### ⊙ NPM\r\n`npm i simplest-i18n -S`\r\n\r\n### ⊙ CDN\r\n`<script src=\"//unpkg.com/simplest-i18n\"></script>`\r\n\r\n## § Usage\r\n\r\n```js\r\nimport i18n from 'simplest-i18n'\r\n\r\nconst t = i18n({\r\n  locale: navigator.language.toLowerCase(), // e.g. here yields 'en-us'\r\n  locales: [\r\n    // it is recommended that set your mother tongue as the first locale (e.g. Simplified Chinese for me)\r\n    'zh-cn',\r\n    'en-us',\r\n    'ja'\r\n  ]\r\n})\r\n\r\nconsole.log(\r\n  t(\r\n    '你好',\r\n    'Hello',\r\n    'こんにちは'\r\n  )\r\n) // outputs 'Hello'\r\n```\r\n\r\n***\r\n\r\nThere are code examples for React and Vue in [`examples/`](./examples/)  \r\nCheck it out and run it with the following directives:\r\n\r\n```\r\n>_ git clone https://github.com/kenberkeley/simplest-i18n.git\r\n>_ npm i\r\n>_ npm run react (or npm run vue)\r\n```\r\n\r\n## § Merits\r\n\r\n### ⊙ Keep in context\r\n\r\n```js\r\n// this demonstrates how most popular i18n frameworks do\r\nconst messages = {\r\n  en: {\r\n    greeting: 'Hello {name}, long time no see'\r\n  },\r\n  cn: {\r\n    greeting: '你好，{name}，好久不见了'\r\n  },\r\n  ja: {\r\n    greeting: 'こんにちは、{name}、長い時間は見ていない'\r\n  }\r\n}\r\n*****************************************************************\r\n// in another file (lose direct sight of the original translations)\r\nrender () {\r\n  return (\r\n    <h1>{\r\n      format('greeting', { name: this.state.name })\r\n    }</h1>\r\n  )\r\n}\r\n```\r\n\r\n```js\r\n// this is how we do with ES6 template literals\r\nrender () {\r\n  const { name } = this.state\r\n  return (\r\n    <h1>{\r\n      t(\r\n        `你好，${name}，好久不见`,\r\n        `Hello ${name}, long time no see`,\r\n        `こんにちは、${name}、長い時間は見ていない`\r\n      )\r\n    }</h1>\r\n  )\r\n}\r\n```\r\n\r\nFrom now on, naming things and duplicate keys would not bother you anymore  \r\n(the *key* is actually the original text written in your mother tongue)  \r\nBefore that, you might have to use a kinda nonsense  `module1.page1.greeting` (namespace) to avoid these problems\r\n\r\n### ⊙ Flexible\r\nHow do we solve the pluralization problem?\r\n\r\n* Method 0: Simple and crude: appending `(s) / (es)` directly\r\n\r\n```js\r\nrender () {\r\n  const { num } = this.state\r\n  return (\r\n    <span>{\r\n      t(\r\n        `我有 ${num} 个苹果`,\r\n        `I have ${num} apple(s)`\r\n      )\r\n    }</span>\r\n  )\r\n}\r\n```\r\n\r\n* Method 1: Write your own helper function\r\n\r\n```js\r\n/**\r\n * @param  {String} nouns\r\n * @param  {String} num\r\n * @return {String}\r\n * e.g.\r\n * pluralize('apple|apples', 3) => '3 apples' \r\n * pluralize('man|men', 1) => '1 man'\r\n */\r\nexport default function pluralize(nouns, num) {\r\n  return `${num} ${nouns.split('|')[+!(num === 1)]}`\r\n}\r\n```\r\n\r\n* Method 2: Search `plural` in [npmjs.com](https://www.npmjs.com) and pick one\r\n\r\n> You can control everything in the project! No blackboxes! All functions are pure, simple and composable!\r\n\r\n## § Tips\r\n\r\n* If you are using Webpack and tired of importing `t` everywhere, try [ProvidePlugin](https://webpack.js.org/plugins/provide-plugin/) instead (`window.t = t` is ok as you like it)\r\n\r\n\r\n[npm-url]: https://www.npmjs.com/package/simplest-i18n\r\n[npm-v-img]: http://img.shields.io/npm/v/simplest-i18n.svg\r\n[npm-dl-img]: http://img.shields.io/npm/dm/simplest-i18n.svg\r\n[build-img]: https://travis-ci.org/kenberkeley/simplest-i18n.svg?branch=master\r\n[build-url]: https://travis-ci.org/kenberkeley/simplest-i18n\r\n","_attachments":{},"homepage":"https://github.com/kenberkeley/simplest-i18n#readme","bugs":{"url":"https://github.com/kenberkeley/simplest-i18n/issues"},"license":"MIT"}