{"_id":"@elementium/koa-locales","_rev":"1-65984166a0422e42c1d6b9e70a4ae363","name":"@elementium/koa-locales","dist-tags":{"latest":"1.13.0"},"versions":{"1.13.0":{"name":"@elementium/koa-locales","version":"1.13.0","description":"koa locales, i18n solution for koa","main":"index.js","scripts":{"test":"eslint . && mocha -R spec -t 5000 test/*.test.js","cov":"istanbul cover _mocha -- -t 5000 test/*.test.js","lint":"eslint .","ci":"npm run lint && npm run cov","autod":"autod -w --prefix '^'","contributors":"contributors -f plain -o AUTHORS"},"dependencies":{"debug":"^2.6.0","humanize-ms":"^1.2.0","ini":"^1.3.4","js-yaml":"^3.13.1","npminstall":"^3.23.0","object-assign":"^4.1.0"},"devDependencies":{"autod":"2","beautify-benchmark":"^0.2.4","benchmark":"^2.1.3","contributors":"*","egg-ci":"^1.1.0","eslint":"1","istanbul":"*","koa":"^1.2.4","mm":"^2.0.0","mocha":"4","pedding":"^1.1.0","supertest":"^2.0.1"},"homepage":"https://github.com/zhouleyan/locales","repository":{"type":"git","url":"git://github.com/zhouleyan/locales.git","web":"https://github.com/zhouleyan/locales"},"bugs":{"url":"https://github.com/zhouleyan/locales/issues"},"keywords":["koa-locales","i18n","locales","koa-i18n","koa"],"engines":{"node":">=4.0.0"},"ci":{"version":"4, 6, 8, 10, 12"},"author":{"name":"zhouleyan"},"license":"MIT","contributors":[{"name":"fengmk2","email":"m@fengmk2.com","url":"https://fengmk2.com"},{"name":"Haoliang Gao","email":"sakura9515@gmail.com","url":"https://github.com/popomore"},{"name":"闲耘™","email":"hotoo.cn@gmail.com","url":"https://github.com/hotoo"},{"name":"ermin.zem","email":"harbin1053020115@gmail.com"}],"gitHead":"36aaf477b9ca8655d740333a2d2d12c073018de2","_id":"@elementium/koa-locales@1.13.0","_nodeVersion":"10.21.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-3ZKvhHtSoBF+nvOImau0rEwbjwQ9NF99ow8R9vP5r7pEyyJT5qv935bO8tNC63SnNon5lalEQkMPxXUpCi+0kA==","shasum":"206d00f17a2d8fcb44a87e48e26cc01b12b21a4d","tarball":"https://registry.npmjs.org/@elementium/koa-locales/-/koa-locales-1.13.0.tgz","fileCount":5,"unpackedSize":18476,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe/EAMCRA9TVsSAnZWagAAAggP/RnSWBswpqOSDnC8bkEo\nyMvNvSsAVfv3R/8VZoQsfiiSsEi3xV65STDTuBK7D0eZyKYONCro5Y9RODBP\nNqEr9Su1oZhl7HESRqzvPNd9bUpYOB6Mc7tKREwh9pM5umIncOKnItiB1mbs\nmUarU8YkmbLfL1tv/JCVDNLBST7VwmNTNCRcjZUQVSYk4BtBCgQzyBl7IKGx\n8sh0JxvavzrT63ANipEn0be/z6PbWc/l1Cyg6AzFLF0Km9jH0vFTAkuhWdv1\n1BPvCzs/Z3AsJfZ3NhmSJQMYDPIAuBkGqP5ivGfTKxqT3tkOqivB3TRl0pDa\nhPMadKCC3Gu5yxY2VwZ3yj3WY39qtrgfhfG1/MF00j7fUUJln1yEfKnae+nQ\niKoO7vnwH/3yxpUlv6PoLgoWYokJC+QX56XgAaPMGJNCC39ba0nYAwuf7xrI\nEEKDGTmMIsK5I5mC6WUfU2xehZ3CYGzn/694RqcDs9LqQjzIBmUNveO0NSlo\nUKggFeoSMuqnfDy1inWandVnljDDN0hcQ/FbHyAVFjerzn9MG4sDYSe2nKsE\n38EOqHFCqYu1t8WvVQbUM9RfZQSIsr0ludMdQXWYeWkuvrKEPwLpYXqFA5XI\nZi2wpItI0ES1GaHnTcGPztuKIqCo713IogFwUH4mIU99dJ/rfvrKKnJSi49r\nu99m\r\n=tyhH\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE8lYE7FgMRUzzQJfAdv4JKfSqwhHcZWvbdKYvkKeKkwAiEAhTrnsV+KG8SKiqUte05X/DrDAjrNwCqn/IVC22PZfOg="}]},"maintainers":[{"name":"zhouleyan1117","email":"zly_invincible@icloud.com"}],"_npmUser":{"name":"zhouleyan1117","email":"zly_invincible@icloud.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/koa-locales_1.13.0_1593589772026_0.617630889841942"},"_hasShrinkwrap":false}},"time":{"created":"2020-07-01T07:49:31.765Z","1.13.0":"2020-07-01T07:49:32.123Z","modified":"2022-04-05T07:09:08.785Z"},"maintainers":[{"name":"zhouleyan1117","email":"zly_invincible@icloud.com"}],"description":"koa locales, i18n solution for koa","homepage":"https://github.com/zhouleyan/locales","keywords":["koa-locales","i18n","locales","koa-i18n","koa"],"repository":{"type":"git","url":"git://github.com/zhouleyan/locales.git","web":"https://github.com/zhouleyan/locales"},"contributors":[{"name":"fengmk2","email":"m@fengmk2.com","url":"https://fengmk2.com"},{"name":"Haoliang Gao","email":"sakura9515@gmail.com","url":"https://github.com/popomore"},{"name":"闲耘™","email":"hotoo.cn@gmail.com","url":"https://github.com/hotoo"},{"name":"ermin.zem","email":"harbin1053020115@gmail.com"}],"author":{"name":"zhouleyan"},"bugs":{"url":"https://github.com/zhouleyan/locales/issues"},"license":"MIT","readme":"koa-locales\n=======\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][cov-image]][cov-url]\n[![David deps][david-image]][david-url]\n[![npm download][download-image]][download-url]\n\nkoa locales, i18n solution for koa:\n\n1. All locales resources location on `options.dirs`.\n2. resources file supports: `*.js`, `*.json`, `*.yml`, `*.yaml` and `*.properties`, see [examples](test/locales/).\n3. One api: `__(key[, value, ...])`.\n4. Auto detect request locale from `query`, `cookie` and `header: Accept-Language`.\n\n## Installation\n\n```bash\n$ npm install koa-locales --save\n```\n\n## Quick start\n\n```js\nconst koa = require('koa');\nconst locales = require('koa-locales');\n\nconst app = koa();\nconst options = {\n  dirs: [__dirname + '/locales', __dirname + '/foo/locales'],\n};\nlocales(app, options);\n```\n\n## API Reference\n\n### `locales(app, options)`\n\nPatch locales functions to koa app.\n\n- {Application} app: koa app instance.\n- {Object} options: optional params.\n  - {String} functionName: locale function name patch on koa context. Optional, default is `__`.\n  - {String} dirs: locales resources store directories. Optional, default is `['$PWD/locales']`.\n  - {String} defaultLocale: default locale. Optional, default is `en-US`.\n  - {String} queryField: locale field name on query. Optional, default is `locale`.\n  - {String} cookieField: locale field name on cookie. Optional, default is `locale`.\n  - {String} cookieDomain: domain on cookie. Optional, default is `''`.\n  - {Object} localeAlias: locale value map. Optional, default is `{}`.\n  - {String|Number} cookieMaxAge: set locale cookie value max age. Optional, default is `1y`, expired after one year.\n\n```js\nlocales({\n  app: app,\n  dirs: [__dirname + '/app/locales'],\n  defaultLocale: 'zh-CN',\n});\n```\n\n#### Aliases\n\nThe key `options.localeAlias` allows to not repeat dictionary files, as you can configure to use the same file for *es_ES* for *es*, or *en_UK* for *en*.\n\n```js\nlocales({\n  localeAlias: {\n    es: es_ES,\n    en: en_UK,\n  },\n});\n```\n\n### `context.__(key[, value1[, value2, ...]])`\n\nGet current request locale text.\n\n```js\nasync function home(ctx) {\n  ctx.body = {\n    message: ctx.__('Hello, %s', 'fengmk2'),\n  };\n}\n```\n\nExamples:\n\n```js\n__('Hello, %s. %s', 'fengmk2', 'koa rock!')\n=>\n'Hello fengmk2. koa rock!'\n\n__('{0} {0} {1} {1} {1}', ['foo', 'bar'])\n=>\n'foo foo bar bar bar'\n\n__('{a} {a} {b} {b} {b}', {a: 'foo', b: 'bar'})\n=>\n'foo foo bar bar bar'\n```\n\n### `context.__getLocale()`\n\nGet locale from query / cookie and header.\n\n### `context.__setLocale()`\n\nSet locale and cookie.\n\n### `context.__getLocaleOrigin()`\n\nWhere does locale come from, could be `query`, `cookie`, `header` and `default`.\n\n### `app.__(locale, key[, value1[, value2, ...]])`\n\nGet the given locale text on application level.\n\n```js\nconsole.log(app.__('zh', 'Hello'));\n// stdout '你好' for Chinese\n```\n\n## Usage on template\n\n```js\nthis.state.__ = this.__.bind(this);\n```\n\n[Nunjucks] example:\n\n```html\n{{ __('Hello, %s', user.name) }}\n```\n\n[Pug] example:\n\n```pug\np= __('Hello, %s', user.name)\n```\n\n[Koa-pug] integration:\n\nYou can set the property *locals* on the KoaPug instance, where the default locals are stored.\n\n```js\napp.use(async (ctx, next) => {\n  koaPug.locals.__ = ctx.__.bind(ctx);\n  await next();\n});\n```\n\n## Debugging\n\nIf you are interested on knowing what locale was chosen and why you can enable the debug messages from [debug].\n\nThere is two level of verbosity:\n\n```sh\n$ DEBUG=koa-locales node .\n```\nWith this line it only will show one line per request, with the chosen language and the origin where the locale come from (queryString, header or cookie).\n\n```sh\n$ DEBUG=koa-locales:silly node .\n```\nUse this level if something doesn't work as you expect. This is going to debug everything, including each translated line of text.\n\n## License\n\n[MIT](LICENSE)\n\n\n[nunjucks]: https://www.npmjs.com/package/nunjucks\n[debug]: https://www.npmjs.com/package/debug\n[pug]: https://www.npmjs.com/package/pug\n[koa-pug]: https://www.npmjs.com/package/koa-pug\n\n[npm-image]: https://img.shields.io/npm/v/koa-locales.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/koa-locales\n[travis-image]: https://img.shields.io/travis/koajs/locales.svg?style=flat-square\n[travis-url]: https://travis-ci.org/koajs/locales\n[cov-image]: https://codecov.io/github/koajs/locales/coverage.svg?branch=master\n[cov-url]: https://codecov.io/github/koajs/locales?branch=master\n[david-image]: https://img.shields.io/david/koajs/locales.svg?style=flat-square\n[david-url]: https://david-dm.org/koajs/locales\n[download-image]: https://img.shields.io/npm/dm/koa-locales.svg?style=flat-square\n[download-url]: https://npmjs.org/package/koa-locales\n","readmeFilename":"README.md"}