{"id":13800669,"url":"https://github.com/koa-modules/locale","last_synced_at":"2025-04-26T20:31:15.793Z","repository":{"id":15524509,"uuid":"18258976","full_name":"koa-modules/locale","owner":"koa-modules","description":"Get locale variable from query, subdomain, accept-languages or cookie for koa.","archived":false,"fork":false,"pushed_at":"2022-04-28T08:51:41.000Z","size":26,"stargazers_count":18,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T13:13:11.402Z","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":null,"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-03-30T06:31:47.000Z","updated_at":"2021-12-11T15:31:55.000Z","dependencies_parsed_at":"2022-08-04T05:00:22.232Z","dependency_job_id":null,"html_url":"https://github.com/koa-modules/locale","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koa-modules%2Flocale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koa-modules%2Flocale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koa-modules%2Flocale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koa-modules%2Flocale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koa-modules","download_url":"https://codeload.github.com/koa-modules/locale/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251051368,"owners_count":21528787,"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.903Z","updated_at":"2025-04-26T20:31:12.940Z","avatar_url":"https://github.com/koa-modules.png","language":"JavaScript","readme":"# koa-locale\n\n\u003e Get locale variable from query, subdomain, the last domain, accept-languages or cookie for koa.\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\n### Installation\n\n```bash\n$ npm install koa-locale\n```\n\n### Usage\n\n```js\nvar app = require('koa')();\nvar locale = require('koa-locale');\n\n// the locale key name defaults to `locale`\nlocale(app, 'language');\n\napp.use(function *(next) {\n  // query: '?language=en'\n  this.body = this.getLocaleFromQuery();\n});\n```\n\n### API\n\n#### ctx.getLocaleFromQuery(), ctx.request.getLocaleFromQuery()\n\n```\n/?locale=en-US\n```\n\n#### ctx.getLocaleFromSubdomain(), ctx.request.getLocaleFromSubdomain()\n\n```\nzh-CN.koajs.com\n```\n\n#### ctx.getLocaleFromHeader(multi = false), ctx.request.getLocaleFromHeader(multi = false)\n\n```\nAccept-Language: zh-CN,zh;q=0.5\n```\n\n#### ctx.getLocaleFromCookie(), ctx.request.getLocaleFromCookie()\n\n```\nCookie: locale=zh-TW\n```\n\n#### ctx.getLocaleFromUrl(options), ctx.request.getLocaleFromUrl(options)\n\n```\nhttp://koajs.com/en\n```\n\n```\noptions = { offset: 2 }\n\nhttp://koajs.com/foo/bar/en\n```\n\n#### ctx.getLocaleFromTLD(), ctx.request.getLocaleFromTLD()\n\n```\nhttp://koajs.com/\nhttp://koajs.cn/\nhttp://koajs.it/\n```\n\n### License\n\n  MIT\n\n[npm-img]: https://img.shields.io/npm/v/koa-locale.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/koa-locale\n[travis-img]: https://img.shields.io/travis/koa-modules/locale.svg?style=flat-square\n[travis-url]: https://travis-ci.org/koa-modules/locale\n[coveralls-img]: https://img.shields.io/coveralls/koa-modules/locale.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/koa-modules/locale?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/locale.svg?style=flat-square\n[david-url]: https://david-dm.org/koa-modules/locale\n","funding_links":[],"categories":["仓库"],"sub_categories":["中间件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoa-modules%2Flocale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoa-modules%2Flocale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoa-modules%2Flocale/lists"}