{"id":18880523,"url":"https://github.com/onewaytech/simplest-i18n","last_synced_at":"2026-02-27T23:07:48.524Z","repository":{"id":143803916,"uuid":"116654049","full_name":"OneWayTech/simplest-i18n","owner":"OneWayTech","description":"The Simplest Universal i18n Solution","archived":false,"fork":false,"pushed_at":"2018-01-16T07:23:22.000Z","size":11,"stargazers_count":13,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T02:05:58.420Z","etag":null,"topics":["globalization","i18n","isomorphic","locale","localization","simple","translate","translation","universal"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OneWayTech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-08T09:06:03.000Z","updated_at":"2025-03-08T20:24:16.000Z","dependencies_parsed_at":"2023-05-28T05:45:12.949Z","dependency_job_id":null,"html_url":"https://github.com/OneWayTech/simplest-i18n","commit_stats":null,"previous_names":["kenberkeley/simplest-i18n"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneWayTech%2Fsimplest-i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneWayTech%2Fsimplest-i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneWayTech%2Fsimplest-i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneWayTech%2Fsimplest-i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OneWayTech","download_url":"https://codeload.github.com/OneWayTech/simplest-i18n/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248946079,"owners_count":21187446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["globalization","i18n","isomorphic","locale","localization","simple","translate","translation","universal"],"created_at":"2024-11-08T06:44:19.587Z","updated_at":"2026-02-27T23:07:48.494Z","avatar_url":"https://github.com/OneWayTech.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"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) \u003c 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`\u003cscript src=\"//unpkg.com/simplest-i18n\"\u003e\u003c/script\u003e`\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\u003e_ git clone https://github.com/OneWayTech/simplest-i18n.git\r\n\u003e_ npm i\r\n\u003e_ npm run react (or npm run vue)\r\n```\r\n\r\nIf you doubt the practicality of this repo, please visit https://developer.oneway.mobi to see if it is serious enough :)\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    \u003ch1\u003e{\r\n      format('greeting', { name: this.state.name })\r\n    }\u003c/h1\u003e\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    \u003ch1\u003e{\r\n      t(\r\n        `你好，${name}，好久不见`,\r\n        `Hello ${name}, long time no see`,\r\n        `こんにちは、${name}、長い時間は見ていない`\r\n      )\r\n    }\u003c/h1\u003e\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    \u003cspan\u003e{\r\n      t(\r\n        `我有 ${num} 个苹果`,\r\n        `I have ${num} apple(s)`\r\n      )\r\n    }\u003c/span\u003e\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) =\u003e '3 apples' \r\n * pluralize('man|men', 1) =\u003e '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\u003e 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/OneWayTech/simplest-i18n.svg?branch=master\r\n[build-url]: https://travis-ci.org/OneWayTech/simplest-i18n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonewaytech%2Fsimplest-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonewaytech%2Fsimplest-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonewaytech%2Fsimplest-i18n/lists"}