{"_id":"@cephalomax/koa-i18next","name":"@cephalomax/koa-i18next","dist-tags":{"latest":"1.1.2"},"versions":{"1.1.2":{"name":"@cephalomax/koa-i18next","version":"1.1.2","description":"koa middleware for i18next","main":"./lib/index.js","scripts":{"test":"ava | tap-spec","watch:test":"ava --watch | tap-spec","build":"NODE_ENV=production rollup -c","prepublish":"npm run build"},"publishConfig":{"registry":"https://registry.npmjs.org"},"keywords":["i18n","i18next","koa","middleware"],"author":{"name":"sunfuze","email":"sunfuze.1989@gmail.com"},"ava":{"files":["test/**/*.test.js"],"require":["babel-register"],"tap":"tap-spec","timeout":"5s"},"repository":{"type":"git","url":"git@github.com:sunfuze/koa-i18next.git"},"engines":{"node":">= 8.0.0"},"devDependencies":{"ava":"^0.15.2","babel-preset-env":"^1.6.1","babel-register":"^6.26.0","babelrc-rollup":"^1.1.0","i18next":"^10.6.0","i18next-sync-fs-backend":"^1.0.0","koa":"^2.5.0","koa-router":"^7.4.0","koa-session":"^5.8.1","rollup":"^0.59.1","rollup-plugin-babel":"^2.7.1","supertest":"^1.2.0","tap-spec":"^4.1.1"},"license":"MIT","dependencies":{"debug":"^2.2.0","koa-convert":"^1.2.0"},"_id":"@cephalomax/koa-i18next@1.1.2","dist":{"shasum":"7acc331c794f4cfe69bbc2069895ae98843ebd81","integrity":"sha512-XniMUePB+Jc8QwwQ/F5mQF9U9rpGcgnK+v2wRzuakGYn/WhDaP00aOLsfhIPFkfbWUmXXO781QzD/Y4JT2iGNg==","tarball":"https://registry.npmjs.org/@cephalomax/koa-i18next/-/koa-i18next-1.1.2.tgz","fileCount":6,"unpackedSize":13154,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDlV3nwxNmzTFIWypyWJlkxFIdbKRLMZ3PwZAfT5haVRAIgHnPF2TmdobUxv6jmwdu42vWadyXoP7a4AjxIyzjI4YM="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJicNRLACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrsTBAAgvY1+bPUOeHI5TgzZL+patUEYa/q8EKrNWV0SpDi2ljfjE6N\r\nX/5sHkrVQAzOjQGfY5A386tjosmZx93XHGpa6mqjcJoSdLvdmn2Fiek6UsKy\r\nQ6LqoZ6wKVD/+Tl6e1FhT4uRNbpffRXQ4FbqkZl8lQsAJ6qJUtc6GUqD44/4\r\nuC7HyOPkX+h+WAJBZUpAM/7I0vf9dnLyw2mOo14FtC9aXE3BkZhyfVdJMBlG\r\nEGs1tBrrZDttwp+S5bDZJcIxgy8lkfwjKlR8XQS8mV6g8vd1ISHwvsDfLLqz\r\nl+B+vjoCfP1YJ1GFEiC3v/DbKIN+WqD6YCkGxW0Bl+qlkSMAxvNAW6V7knXh\r\nuw+unaQ9/7Hi4YTeutqi8sFLCahYqyJ00/9aURe/fRrX2D9Bo9J/aEEbuC9J\r\n4juRHrfptwLPdeMXNkL9WT80jS28sC+yWlBBklVORa0EU/QFkM3jQTbwOWFG\r\nWTOHZh3KuLw/9/LLN4SFcUrITs1v3sncfEu9VtckvjKo4stBYWKSqvd9LBHj\r\nSCLwgLaanH5BmyAnHkNBtYU6SLwuFZ4RxYFR2BRV8omF+Ts4kp4UsyX+sA/Y\r\nA0uFkbMQS/AjxBWlJYse0QX76VepS8T+ui4Cd5oeTwAXlvhko/Ik/fm2XtnR\r\nxY8547CAtCMexHuxS7q9INnvGnq20KQfJIA=\r\n=xpPW\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"cephalomax","email":"cephalomax@gmail.com"},"directories":{},"maintainers":[{"name":"cephalomax","email":"cephalomax@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/koa-i18next_1.1.2_1651561547022_0.13701278730039523"},"_hasShrinkwrap":false}},"time":{"created":"2022-05-03T07:05:46.956Z","1.1.2":"2022-05-03T07:05:47.203Z","modified":"2022-05-03T07:05:47.341Z"},"maintainers":[{"name":"cephalomax","email":"cephalomax@gmail.com"}],"description":"koa middleware for i18next","keywords":["i18n","i18next","koa","middleware"],"repository":{"type":"git","url":"git@github.com:sunfuze/koa-i18next.git"},"author":{"name":"sunfuze","email":"sunfuze.1989@gmail.com"},"license":"MIT","readme":"# This repo is *deprecated*, please use [koa-i18next-middleware](https://github.com/lxzxl/koa-i18next-middleware).\n\n\n# Introduction\nA middleware to use i18next in koajs.\n\n# Getting started\ninstall dependencies\n```bash\nnpm install koa-i18next\n```\n## working with backend\n\n```javascript\nconst koa = require('koa')\nconst i18next = require('i18next')\nconst Backend = require('i18next-sync-fs-backend') // or i18next-node-fs-backend\nconst koaI18next = require('koa-i18next')\n\ni18next\n  .use(Backend)\n  .init({\n    backend: {\n      // translation resources\n      loadPath: path.resolve('./locales/{{lng}}/{{ns}}.json'),\n      addPath: path.resolve('./locales/{{lng}}/{{ns}}.missing.json')\n    },\n    preload: ['zh', 'en'], // must know what languages to use\n    fallbackLng: 'en'\n  })\n\nconst app = koa()\napp.use(koaI18next(i18next, {\n  lookupCookie: 'i18next', // detecting language in cookie\n  /**\n  * Detecting language in path params, need third part route middleware.\n  * Example\n  * path: `/api/:lng/hello\n  */\n  lookupPath: 'lng',\n  lookupFromPathIndex: 0, // detecting language in path, like `/api/zh/hello` which `zh` is the language and the index is 1\n  lookupQuerystring: 'lng', // detect language in query,\n  lookupSession: 'lng', // detect language in session\n  /**\n  * support querystring, cookie, header, session, path\n  * default order: ['querystring', 'cookie', 'header']\n  */\n  order: ['querystring'],\n  next: true // if koa is version 2\n}))\n// koa@1.X\napp.use(function* (next) {\n  this.body = {message: this.t('lalala')}\n})\n```\n\n## language detection\n\nSupport for:\n- querystring\n- cookie\n- header\n- session\n- path\n\nIf you don't config this, it will use ['querystring', 'cookie', 'header'] as default  detecting order.\n\n## options\n\n```javascript\n{\n  // order and from where user language should be detected\n  order: ['querystring', 'cookie', 'header'/*, 'path', 'session'*/],\n  // keys or params to lookup language from\n  lookupQuerystring: 'lng',\n  lookupCookie: 'i18next',\n  lookupSession: 'lng',\n  lookupPath: 'lng',\n  lookupFromPathIndex: 0,\n  // if koa is v2\n  next: true\n}\n```\n\n## api\nyou can use i18next in koa middleware, as:\n\n```javascript\nthis.t('balabala', options)\n```\n\n`i18next.t` arguments are all supported. [i18next.t](http://i18next.com/docs/api/#t)\n\n\n## Resources middleware\n> inspired by i18next-express-middleware\n\nIf needed, you can serve the translations with the resources middleware.  \nAs Koa doesn't come with built-in routing system, you'll have to handle the request path matching by a routing library or by specifying a path in the options.\n\n```javascript\nconst koaI18next = require('koa-i18next')\n...\n// Exemple without router\napp.use(koaI18next.getResourcesHandler(i18next, {path: '/locales/resources.json'}));\n\n// Exemple with koa-router\napp.get('/locales/resources.json', koaI18next.getResourcesHandler(i18next));\n```\n\nRequesting `/locales/resources.json?lng=en&ns=fr` will return the translations of the `common` namespace of the `en` language.  \nNote:  Multiple languages and namespaces are supported.  \n\nAvailable options (with default) are :  \n```javascript\n{\n  // Serve resources only if ctx.path match given path (handle every request by default)\n  path: false, \n  // Where to look for lng & ns parameters on the context (query, params, ...)\n  propertyParam: 'query',   \n  // Name of the lng param\n  lngParam: 'lng',\n  // Name of the ns param\n  nsParam: 'ns'\n}\n```\n\n## Missing Keys middleware\n> inspired by i18next-express-middleware\n\nYou can handle missing keys with the Missing Keys middleware. It'll need the `bodyparser` in order to get the submitted missing translations.\n\n```javascript\nconst koaI18next = require('koa-i18next')\n...\n// Exemple without router\napp.use(koaI18next.getMissingKeysHandler(i18next, {path: '/locales/add'}));\n\n// Exemple with koa-router\napp.post('/locales/add', koaI18next.getMissingKeysHandler(i18next));\n```\n\nPosting on `/locales/add?lng=en&ns=common` with an array of missing message as body will perform a save missing for the `common` namespace and the `en` language.\n\nAvailable options (with default) are :  \n```javascript\n{\n  // Handle request only if ctx.path match given path \n  path: false, \n  // Where to look for lng & ns parameters on the context (query, params, ...)\n  propertyParam: 'query',   \n  // Name of the lng params\n  lngParam: 'lng',\n  // Name of the ns param\n  nsParam: 'ns'\n\n}\n```\n\n# License\n[MIT](http://opensource.org/licenses/MIT)\n","readmeFilename":"README.md"}