{"id":13800657,"url":"https://github.com/koa-modules/i18n","last_synced_at":"2025-10-27T03:15:20.829Z","repository":{"id":16183523,"uuid":"18930057","full_name":"koa-modules/i18n","owner":"koa-modules","description":"Lightweight simple translation middleware for koa, based on i18n-2","archived":false,"fork":false,"pushed_at":"2018-09-03T14:03:44.000Z","size":54,"stargazers_count":65,"open_issues_count":8,"forks_count":19,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-26T20:47:02.160Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koa-modules.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-19T00:50:26.000Z","updated_at":"2022-05-17T16:29:55.000Z","dependencies_parsed_at":"2022-09-04T06:21:14.427Z","dependency_job_id":null,"html_url":"https://github.com/koa-modules/i18n","commit_stats":null,"previous_names":["koa-modules/koa-i18n"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koa-modules%2Fi18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koa-modules%2Fi18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koa-modules%2Fi18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koa-modules%2Fi18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koa-modules","download_url":"https://codeload.github.com/koa-modules/i18n/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254567328,"owners_count":22092750,"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":[],"created_at":"2024-08-04T00:01:14.770Z","updated_at":"2025-10-27T03:15:15.779Z","avatar_url":"https://github.com/koa-modules.png","language":"JavaScript","readme":"# koa-i18n\n\n\u003e I18n fro koa, based on [i18n-2].\n\u003e **NOTE**: If want to use koa-i18n, [koa-locale] must be required!\n\n[![NPM version][npm-img]][npm-url]\n[![Build status][travis-img]][travis-url]\n[![Test coverage][coveralls-img]][coveralls-url]\n[![License][license-img]][license-url]\n[![Dependency status][david-img]][david-url]\n\nkoa-i18n version | branch | koa version\n---------------- | ------ | -----------\n1.x **latest**   | v1.x   | 1.x **latest**\n2.x **next**     | master | 2.x **next**\n\n### Installation\n\n```bash\n$ npm install koa-i18n\n```\n\n### Usage\n\n```js\nconst Koa = require('koa')\nconst convert = require('koa-convert')\nconst locale = require('koa-locale') //  detect the locale\nconst render = require('koa-swig')   //  swig render\nconst i18n = require('koa-i18n')\n\nconst app = new Koa()\n\n// Required!\nlocale(app)\n\napp.context.render = render({\n  root: __dirname + '/views/',\n  ext: 'html'\n})\n\napp.use(i18n(app, {\n  directory: './config/locales',\n  locales: ['zh-CN', 'en'], //  `zh-CN` defualtLocale, must match the locales to the filenames\n  modes: [\n    'query',                //  optional detect querystring - `/?locale=en-US`\n    'subdomain',            //  optional detect subdomain   - `zh-CN.koajs.com`\n    'cookie',               //  optional detect cookie      - `Cookie: locale=zh-TW`\n    'header',               //  optional detect header      - `Accept-Language: zh-CN,zh;q=0.5`\n    'url',                  //  optional detect url         - `/en`\n    'tld',                  //  optional detect tld(the last domain) - `koajs.cn`\n    function() {}           //  optional custom function (will be bound to the koa context)\n  ]\n}))\n\napp.use(function (ctx) {\n  ctx.body = ctx.i18n.__('any key');\n})\n\napp.use(convert(function *() {\n  yield this.render('index')\n}))\n```\n\n\u003e **Tip**: We can change position of the elements in the `modes` array.\n\u003e If one mode is detected, no continue to detect.\n\n\n### Dependencies\n\n* [i18n-2][]\n* [koa-locale][] - Get locale variable from query, subdomain, accept-languages or cookie\n\n\n### License\n\n  MIT\n\n[i18n-2]: https://github.com/jeresig/i18n-node-2\n[koa-locale]: https://github.com/koa-modules/koa-locale\n\n[npm-img]: https://img.shields.io/npm/v/koa-i18n.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/koa-i18n\n[travis-img]: https://img.shields.io/travis/koa-modules/i18n.svg?style=flat-square\n[travis-url]: https://travis-ci.org/koa-modules/i18n\n[coveralls-img]: https://img.shields.io/coveralls/koa-modules/i18n.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/koa-modules/i18n?branch=master\n[license-img]: https://img.shields.io/badge/license-MIT-green.svg?style=flat-square\n[license-url]: LICENSE\n[david-img]: https://img.shields.io/david/koa-modules/i18n.svg?style=flat-square\n[david-url]: https://david-dm.org/koa-modules/i18n\n","funding_links":[],"categories":["仓库"],"sub_categories":["中间件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoa-modules%2Fi18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoa-modules%2Fi18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoa-modules%2Fi18n/lists"}