{"_id":"@cme-pro/mongoose-i18n","_rev":"3-f15296ba957e49b3b83ba39dd6c961ca","name":"@cme-pro/mongoose-i18n","dist-tags":{"latest":"0.1.7"},"versions":{"0.1.5":{"name":"@cme-pro/mongoose-i18n","version":"0.1.5","description":"mongoose plugin to manage i18n fields","homepage":"https://github.com/cme-pro/mongoose-i18n-extra#readme","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","test":"jest --detectOpenHandles --forceExit","prepublish":"npm run build"},"repository":{"type":"git","url":"git+https://github.com/cme-pro/mongoose-i18n-extra.git"},"keywords":["mongoose","intl","i18n","l10n","internationalization","localization"],"author":{"name":"Sven Gaubert","url":"https://github.com/svengau"},"license":"MIT","bugs":{"url":"https://github.com/cme-pro/mongoose-i18n-extra/issues"},"devDependencies":{"@types/jest":"25.2.1","@types/mongoose":"5.7.15","fs-extra":"9.0.0","jest":"26.0.1","jest-environment-node":"26.0.1","mongodb-memory-server":"6.5.2","mongoose":"5.9.12","mongoose-lean-virtuals":"0.6.2","ts-jest":"25.4.0","typescript":"3.8.3","typescript-eslint-parser":"^22.0.0"},"peerDependencies":{"mongoose":">= 4"},"dependencies":{"@types/debug":"^4.1.5","debug":"^4.1.1"},"gitHead":"227cb1cb5fd879b8188ada0639444ed10a8d8fc2","_id":"@cme-pro/mongoose-i18n@0.1.5","_nodeVersion":"12.16.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-8z6pekTHQj2AW2UHieUDO5ij7u5yds7OhCKXx8wCVcWmUNHhzT2vXn/zV9fVc4yeF8lAk9E+SaFtHHG5qYK16A==","shasum":"eb2786f94091dc39690ed9d61472b03007e45d7b","tarball":"https://registry.npmjs.org/@cme-pro/mongoose-i18n/-/mongoose-i18n-0.1.5.tgz","fileCount":24,"unpackedSize":52859,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJesjEdCRA9TVsSAnZWagAAxDgP/R3NTr3PaJLXKUpXaWcN\noYDvEUA3ekfuwG+DOjWzv57iazc8qbnBhzzmrDufKiupsqv6JiyN5AYTNYRO\nlZgDYmBer6cyqN8bWzt4vtp6sDUxO7JJmyCcg80g+qp6KK4/SgJGgEF9QLQb\nKjfgeZeophLhJ3Nzzlp5JphGXuYhdbc3GOAoT/RECBXQRm8Y6vZXwcJcssfw\n4wwzGqg74npQnYJs7K5J7pToBGH1vVkGkPmxX6HDdNH6rOU4u5xrQd/VI6gg\n9bGv06XERNmFrdmDrgRzRjXKNvzSX/6b9hgAHPs5oiOy9wbTcwuCxzAnHiOD\nNpesJSBKbTHUqF011ZRkbecrLa1+S/fI3PJPkVzTipjPSnJ+1bpBXzNwHH+2\nh0ZlunrqEvnbvJTmBS6P3pLMkLchUMGV8o7i96Hx9UPcPPwyFMyVu3DAyyFq\nZCTxkP8Dh9bkGwTBv+mRcPHLZCEHayrU6WJluMBOo9tRlfWyCeIG2qRljekG\nt/EbgtbEctgjZxHZygouki4qkE614r2wG9GHOlFBoqlLrQBa9uP8+96KqKF7\nQLBJKISGpkxDFggqj6UVJl+rdjifX6w5D/DSkviiGYITtt4X3ejl1VgLUfkd\nD/DX6+vpSNDEUs9kM8fhOILtdscNpUL6LapNlrJOG5bP5I9aUP2HHccBTO2r\ns4rj\r\n=H5/C\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDHdp+VOZlfVWiWXQn25D3jjC1VlZm1bc8cRr7t4I5e0gIhAIKSv/xGzGuq0Y8x2pqCHOB49i8kF6a2DOkSOdyL/Gkf"}]},"maintainers":[{"name":"martinratinaud","email":"martinratinaud@gmail.com"},{"name":"svengau","email":"svengau@yahoo.fr"}],"_npmUser":{"name":"svengau","email":"svengau@yahoo.fr"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongoose-i18n_0.1.5_1588736284985_0.5124239745038772"},"_hasShrinkwrap":false},"0.1.6":{"name":"@cme-pro/mongoose-i18n","version":"0.1.6","description":"mongoose plugin to manage i18n fields","homepage":"https://github.com/cme-pro/mongoose-i18n-extra#readme","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","test":"jest --detectOpenHandles --forceExit","prepublish":"npm run build"},"repository":{"type":"git","url":"git+https://github.com/cme-pro/mongoose-i18n-extra.git"},"keywords":["mongoose","intl","i18n","l10n","internationalization","localization"],"author":{"name":"Sven Gaubert","url":"https://github.com/svengau"},"license":"MIT","bugs":{"url":"https://github.com/cme-pro/mongoose-i18n-extra/issues"},"devDependencies":{"@types/jest":"25.2.1","@types/mongoose":"5.7.15","fs-extra":"9.0.0","jest":"26.0.1","jest-environment-node":"26.0.1","mongodb-memory-server":"6.5.2","mongoose":"5.9.12","mongoose-lean-virtuals":"0.6.2","ts-jest":"25.4.0","typescript":"3.8.3","typescript-eslint-parser":"^22.0.0"},"peerDependencies":{"mongoose":">= 4"},"dependencies":{"@types/debug":"^4.1.5","debug":"^4.1.1"},"gitHead":"d90a07d46cd8c6b4595d065268a8cbf659d6880a","_id":"@cme-pro/mongoose-i18n@0.1.6","_nodeVersion":"12.16.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-G8NsUoA3B/UKU2XKyYMBzp0ejo9VKvXCGesrNEXrAWrHP999Tn8DXpi7SsDgVABh4EBT1SGriJGCo+EC1R5VdQ==","shasum":"6f6fcd76486c668e582db1fbae4019cfdde936d1","tarball":"https://registry.npmjs.org/@cme-pro/mongoose-i18n/-/mongoose-i18n-0.1.6.tgz","fileCount":24,"unpackedSize":54927,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeskDJCRA9TVsSAnZWagAA5tEP+wdFBnravKgKP8iLgRRx\nL4J4kX/zXDzx06LccWNziiMe8zw1G1tw+UZPmEpHztF6GvQtlIFXiI5ncPy2\nnD+UgdhikNY0cYRRmNnYHbzqyyVMEFBf6HA4++6NlFePhLPVZF2x233kmKxs\nJInjWqwbd0EPKdpSXTBHZ2MBlxBqN4mhYAHNBFxG2u3IaARv38eNaQs1jK5X\nBRjR6OOPxaQi4oUv/0a9KwTlpRo1T4X9W74gXDua1JnzyYsGYRdJ3b9k8r+Z\nZeSKE/A3mxpnBfqcsxWXXI7bFwl1a7RC3jYI3hK3F77QAwWrTScDnfffItZQ\nKBxGNpyGSqSRu6io6YOf5CBmVTzclqMAgowew3yldJgif3ozRNhYWDWrVog0\noTSx/bW7O3CN5bPxOO7XQ1Vjp18YfJ6UU0HPQ6wQfrQ0l6aoHk+9zgY8OcqB\n346GUO+zU1RU4hwlbXEWpAZ0IqStKqZe2SnHGSUp7om3b93scK4RyJANk3Cz\n65WiZzkiy2sAnfVBHsjA5ymuBIIbYIyCHTyemrGGk1NpNzvfSyyYqBB5Jw0H\nXK2ZAPu9/GTtg/L1NStcPar2/Zp0LVr9BcjpU2Zy5VcL1BSMLSyPy/sMlUjN\nEdorGroeJ5u5R4yp36a+NS5APj4ZO/Kl9FwtQ5evTGqCol1Mlf/QWyvdz9zl\nyQcT\r\n=fKqM\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFKpPcRLqNbT87bQk4fI1NBZThjUePSGi6PrKebudf8JAiEAhStUA/WnPMskXjoe9Y3hCpzHIyR/0IpZX4eXLMXCqKg="}]},"maintainers":[{"name":"martinratinaud","email":"martinratinaud@gmail.com"},{"name":"svengau","email":"svengau@yahoo.fr"}],"_npmUser":{"name":"svengau","email":"svengau@yahoo.fr"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongoose-i18n_0.1.6_1588740297295_0.3346312286983866"},"_hasShrinkwrap":false},"0.1.7":{"name":"@cme-pro/mongoose-i18n","version":"0.1.7","description":"mongoose plugin to manage i18n fields","homepage":"https://github.com/cme-pro/mongoose-i18n-extra#readme","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","test":"jest --detectOpenHandles --forceExit","prepublish":"npm run build"},"repository":{"type":"git","url":"git+https://github.com/cme-pro/mongoose-i18n-extra.git"},"keywords":["mongoose","intl","i18n","l10n","internationalization","localization"],"author":{"name":"Sven Gaubert","url":"https://github.com/svengau"},"license":"MIT","bugs":{"url":"https://github.com/cme-pro/mongoose-i18n-extra/issues"},"devDependencies":{"@types/jest":"25.2.1","@types/mongoose":"5.7.15","fs-extra":"9.0.0","jest":"26.0.1","jest-environment-node":"26.0.1","mongodb-memory-server":"6.5.2","mongoose":"5.9.12","mongoose-lean-virtuals":"0.6.2","ts-jest":"25.4.0","typescript":"3.8.3","typescript-eslint-parser":"^22.0.0"},"peerDependencies":{"mongoose":">= 4"},"dependencies":{"@types/debug":"^4.1.5","debug":"^4.1.1"},"gitHead":"d90a07d46cd8c6b4595d065268a8cbf659d6880a","_id":"@cme-pro/mongoose-i18n@0.1.7","_nodeVersion":"12.16.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-7tHpfaank5X+vbfGTq12vqFs0ETi3FtFxgYvjJEvkV87r89RlK30triHO/fWZ0fvp+v93QnW6Q+yeApSfYA4mA==","shasum":"4967e9dc0b5fcd1c9fe9fa987f483d3b0115aa52","tarball":"https://registry.npmjs.org/@cme-pro/mongoose-i18n/-/mongoose-i18n-0.1.7.tgz","fileCount":24,"unpackedSize":55283,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJesluFCRA9TVsSAnZWagAAq9UP/1N4+nsKCTRGdskDke/L\nT/WPNiTj3e0Hat9DQFwOAi6l0FZL7KX0zbImcIH/aRkNF3LdulZDn6iHNtpw\nilSeuXF43t7p18DS8q6dzjYyl6WnS9aRn6vXWBCovYFxIENT2nS+TOBMWDmL\nfYZiTS9qYdbJAUwwZxGqNEEsQSoxdeIVXiy+D4VFPBehk+MJ9fog3r+9gvcP\nl7sWpy8GRa+bz0wK20bq7uvMXJZja9OHvMC1sKDd8Nuu7im5Qns3q7AggkiZ\npOLjzkxyZQbwvmcGxOHbwfnR0O8vhW/21OeysWoQyKCflm0F/Oqb8fePoVSv\nM+iYItCajTryP6ax/4RpR6FVci21pae3gwz+x8VkBWIhklhD6Zs6HA9EfOuR\nxfYL63FNqEV+dh5q7EsXD+p19jmACG67Rpr+U+gBi/768f+9MFyZtCIWBU7r\nTnDdawGmnW6cYHAmi/u6UCrscG+erIbFGWT4Y3pWQtr1H7bxvQNluLP2AqXC\nA9S2tdVJgZFN4c0YJpTU0CJ+qoCITuxo6mAJu9VX7OeupY6HwJon1Uig5JdR\n2/4Tu02W7s2riMr+wG1pYGEksnbRFpXS3ti9H7+aZLpuvdDivJsY6acqJvth\nfuM0t6RsIi0NF8y1RKLgu+dWMhPSMgZdR9RJkI9BRpSHOHSR2WUAT6Bi3a6N\nJ2yn\r\n=6DTk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCfL5LJqGOhiRXio7DIIs3T3VMm7fibFWUsEOe6nQ2GIAIhAJkBUWAH7gdl+0M1p2CTxso1YxUbK28QFhpZm/ii1F9e"}]},"maintainers":[{"name":"martinratinaud","email":"martinratinaud@gmail.com"},{"name":"svengau","email":"svengau@yahoo.fr"}],"_npmUser":{"name":"svengau","email":"svengau@yahoo.fr"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongoose-i18n_0.1.7_1588747140644_0.7715585377967504"},"_hasShrinkwrap":false}},"time":{"created":"2020-05-06T03:38:04.811Z","0.1.5":"2020-05-06T03:38:05.111Z","modified":"2022-04-04T23:43:16.595Z","0.1.6":"2020-05-06T04:44:57.402Z","0.1.7":"2020-05-06T06:39:00.766Z"},"maintainers":[{"name":"martinratinaud","email":"martinratinaud@gmail.com"},{"name":"svengau","email":"svengau@yahoo.fr"}],"description":"mongoose plugin to manage i18n fields","homepage":"https://github.com/cme-pro/mongoose-i18n-extra#readme","keywords":["mongoose","intl","i18n","l10n","internationalization","localization"],"repository":{"type":"git","url":"git+https://github.com/cme-pro/mongoose-i18n-extra.git"},"author":{"name":"Sven Gaubert","url":"https://github.com/svengau"},"bugs":{"url":"https://github.com/cme-pro/mongoose-i18n-extra/issues"},"license":"MIT","readme":"[![npm][npm]][npm-url]\n[![node][node]][node-url]\n[![tests][tests]][tests-url]\n[![downloads][downloads]][downloads-url]\n\n# mongoose-i18n-extra\n\n[![Build Status](https://travis-ci.org/cme-pro/mongoose-i18n-extra.svg?branch=master)](https://travis-ci.org/cme-pro/mongoose-i18n-extra)\n[![Code Climate](https://codeclimate.com/github/cme-pro/mongoose-i18n-extra/badges/gpa.svg)](https://codeclimate.com/github/cme-pro/mongoose-i18n-extra)\n\n\nMongoose schema plugin for multilingual fields, largely inspired by [mongoose-intl](https://github.com/alexsk/mongoose-intl) plugin.\n\n\nThere are several mongoose plugins dealing already with i18n, the most popular being [mongoose-intl](https://github.com/alexsk/mongoose-intl), but they all changing the translated field into a subdocument containning all translated value.\n\nThis plugin only add a new virtual field `_i18n` with all translations inside, except the default language, which is stored in the main translated field. It's easier to use on an existing database. No need to migrate all documents, you can use this plugin straighforward.\n\n## Installation\n\n```sh\n$ npm install mongoose-i18n-extra --save\n```\n\n## Overview\n\n### Adding plugin to the schema\n\nSchema definition with `i18n` option enabled for some fields:\n\n```js\nconst mongoose          = require('mongoose');\nconst mongooseI18nExtra = require('mongoose-i18n-extra');\nconst { Schema }        = mongoose;\n\nvar BlogPost = new Schema({\n    title  : { type: String, i18n: true },\n    body   : { type: String, i18n: true }\n});\n\n```\n*Note:* `i18n` option can be enabled for String type only.\n\nAdding plugin to the schema:\n\n```js\nBlogPost.plugin(mongooseI18nExtra, { languages: ['en', 'de', 'fr'], defaultLanguage: 'en' });\n```\n\n### Plugin options\n\n* languages - required, array with languages, suggested to use 2- or 3-letters language codes using [ISO 639 standard](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)\n* defaultLanguage - optional, if omitted the first value from `languages` array will be used as a default language\n\n### Database representation\n\n`BlogPost` schema described above will be translated to the following document in the Mongo collection:\n\n```js\n{\n    \"_id\": ObjectId(...),\n    \"title\": \"...\",\n    \"body\": \"...\",\n    \"_i18n\": {\n        \"en\": {\"title\": \"...\", \"body\": \"...\"},\n        \"de\": {\"title\": \"...\", \"body\": \"...\"},\n        \"fr\": {\"title\": \"..., \"body\": \"...\"}\"\n    }\n}\n```\n\n### Usage\n\n`i18n`-enabled field is converted to a virtual path and continue interacting as a string, not an object.\nIt means that you can read it and write to it any string, and it will be stored under default language setting.\n\nOther languages values can be set by using `model.set()` method. Pass an object with multiple languages instead of the string to set all values together. See examples below.\n\nMultilingual fields can be set with 2 ways:\n\n```js\nvar BlogPostModel = mongoose.model('Post', BlogPost);\n\nvar post = new BlogPostModel();\n\npost.title = 'Title on default language'; // default language definition, will be stored to title\n\npost.set('title_de', 'German title'); // any other language value definition will be stored to _i18n.de.title\n\n// you can also set multiple value at once\npost.set(\n\"_i18n\": {\n    \"en\": {\"title\": \"...\", \"body\": \"...\"},\n    \"de\": {\"title\": \"...\", \"body\": \"...\"},\n    \"fr\": {\"title\": \"..., \"body\": \"...\"}\"\n});\n\nawait post.save();\n\n```\n\nValues can be read using the same options:\n\n```js\nvar BlogPostModel = mongoose.model('Post', BlogPost);\n\nconst post = await BlogPostModel.findOne({...});\n\nconsole.log(post.title); // 'Title on default language'\nconsole.log(post.get('title_de')); // 'Another German title'\n```\n\nThis plugin is also compliant with the plugin [mongoose-lean-virtuals](https://github.com/vkarpov15/mongoose-lean-virtuals) which exposes the virtual fields:\n```js\nconst post = await BlogPostModel.findOne({...}).lean({virtuals: ['_i18n']});\n\nconsole.log(post.title); // 'Title on default language'\nconsole.log(post._i18n); // { \"de\": {description: \"...\"}, \"en\": {\"description\": \"...\"}, \"fr\": {description: \"...\"} }\n```\n\n### Language methods\n\nThe current language can be set/changed on 1 level for the moment:\n* Document level: affects only some document (each particular model instance)\n\n#### Document level\n\nEach document will receive the following language methods:\n* `getLanguages()` - returns an array of available languages\n* `getLanguage()` - returns current document's language\n* `setLanguage(lang)` - changes document's language to a new one, the value should be equal to the one of available languages\n* `unsetLanguage()` - removes previously set document-specific language, schema's default language will be used for the translation\n\nUsage examples:\n\n```js\nconst posts = await BlogPostModel.find({});\n\n  console.log(JSON.stringify(posts)); // [{ _id: '...', title: 'Title 1 on default language' },\n                                      //  { _id: '...', title: 'Title 2 on default language' }, ...]\n\n  posts[0].getLanguages(); // [ 'en', 'de', 'fr' ]\n  posts[0].getLanguage(); // 'en'\n\n  posts[0].setLanguage('de');\n  console.log(JSON.stringify(posts)); // [{ _id: '...', title: 'Another German title' },\n                                      //  { _id: '...', title: 'Title 2 on default language' }, ...]\n\n  BlogPostModel.setDefaultLanguage('fr'); // schema-level language change (see documentation below)\n  console.log(JSON.stringify(posts)); // [{ _id: '...', title: 'Another German title' }, // still 'de'\n                                      //  { _id: '...', title: 'French title 2' }, ...]\n\n  posts[0].unsetLanguage();\n  console.log(JSON.stringify(posts)); // [{ _id: '...', title: 'French title 1' },\n                                      //  { _id: '...', title: 'French title 2' }, ...]\n});\n```\n\n### Intl-based String type options\n\n[`default`](http://mongoosejs.com/docs/api.html#schematype_SchemaType-default) and [`required`](http://mongoosejs.com/docs/api.html#schematype_SchemaType-required) options are applied to the default language field only.\n\n2 new options were added for all lang-fields: `defaultAll` and `requiredAll`.\n\nExample:\n\n```js\nvar BlogPost = new Schema({\n    title  : { type: String, i18n: true, default: 'Some default title', requiredAll: true },\n    body   : { type: String, i18n: true }\n});\n```\n\nAll others options and validators (e.g. `lowercase`, `uppercase`, `trim`, `minlength`, `maxlength`, `match`, etc.) will be used for all languages.\nBut please be careful with some of them like `enum` which may not be relevant for multilingual text fields, and indexes which will be added for all fields as well.\n\n\n### TODO\n\n* define as a global plugin which will be applied to all schemas.\n* set language at schema level\n* set language at connection level\n\n## Alternative plugins\n\n* [mongoose-intl](https://github.com/alexsk/mongoose-intl)\n\n\n[npm]: https://img.shields.io/npm/v/mongoose-i18n-extra.svg\n[npm-url]: https://npmjs.com/package/mongoose-i18n-extra\n[node]: https://img.shields.io/node/v/mongoose-i18n-extra.svg\n[node-url]: https://nodejs.org\n[tests]: http://img.shields.io/travis/cme-pro/mongoose-i18n-extra.svg\n[tests-url]: https://travis-ci.org/cme-pro/mongoose-i18n-extra\n[downloads]: https://img.shields.io/npm/dt/mongoose-i18n-extra.svg\n[downloads-url]: https://npmjs.com/package/mongoose-i18n-extra\n","readmeFilename":"README.md"}