{"id":15659003,"url":"https://github.com/rusty1s/mongoose-i18n-localize","last_synced_at":"2025-06-16T08:06:09.900Z","repository":{"id":57302089,"uuid":"47764258","full_name":"rusty1s/mongoose-i18n-localize","owner":"rusty1s","description":"Mongoose plugin to support i18n and localization","archived":false,"fork":false,"pushed_at":"2019-11-02T09:23:47.000Z","size":18,"stargazers_count":25,"open_issues_count":6,"forks_count":13,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-01T12:43:45.815Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/rusty1s.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":"2015-12-10T13:40:21.000Z","updated_at":"2024-12-07T14:50:39.000Z","dependencies_parsed_at":"2022-09-20T14:53:40.391Z","dependency_job_id":null,"html_url":"https://github.com/rusty1s/mongoose-i18n-localize","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/rusty1s/mongoose-i18n-localize","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusty1s%2Fmongoose-i18n-localize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusty1s%2Fmongoose-i18n-localize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusty1s%2Fmongoose-i18n-localize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusty1s%2Fmongoose-i18n-localize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rusty1s","download_url":"https://codeload.github.com/rusty1s/mongoose-i18n-localize/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusty1s%2Fmongoose-i18n-localize/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260124034,"owners_count":22962200,"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-10-03T13:14:38.032Z","updated_at":"2025-06-16T08:06:09.877Z","avatar_url":"https://github.com/rusty1s.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-i18n-localize\n\nmongoose-i18n-localize is a mongoose plugin to support i18n and localization in your mongoose schemas.\n\nIt seems like [mongoose-i18n](https://github.com/elrolito/mongoose-i18n) is not longer supported and I didn't get it to work on my machine, so I decided to write my own version.\n\n## Usage\n\n```\nnpm install mongoose-i18n-localize\n```\n\nCreate your schema:\n\n```js\nvar mongoose = require('mongoose');\nvar mongooseI18n = require('mongoose-i18n-localize');\n\nvar schema = new mongoose.Schema({\n\tname: {\n\t\ttype: String,\n\t\ti18n: true\n\t}\n});\n\nschema.plugin(mongooseI18n, {\n\tlocales: ['en', 'de']\n});\n\nvar Model = mongoose.model('Name', schema);\n```\n\nThis will create a structure like:\n\n```js\n{\n\tname: {\n\t\ten: String,\n\t\tde: String\n\t}\n}\n```\n\nAll validators of `name` get also assigned to `name.en` and `name.de`.\n\nmongoose-i18n-localize adds the methods `toObjectLocalized(resource, locale)` and `toJSONLocalized(resource, locale)` to the i18n schema methods. To set the locale of a resource to `en`, just do:\n\n\n```js\nModel.find(function(err, resources) {\n\tvar localizedResources = resources.toJSONLocalized('en');\n});\n\n//or\n\nModel.find(function(err, resources) {\n\tvar localizedResources = Model.schema.methods.toJSONLocalized(resources, 'en');\n});\n```\n\n`localizedResources` has now the following structure:\n\n```js\n[\n\t{\n\t\tname: {\n\t\t\ten: 'hello',\n\t\t\tde: 'hallo',\n\t\t\tlocalized: 'hello'\n\t\t}\n\t}\n]\n```\n\nUse `toObjectLocalized` or `toJSONLocalized` according to `toObject` or `toJSON`.\n\nIf you only want to show only one locale message use the methods\n`toObjectLocalizedOnly(resource, locale, localeDefault)` or\n`toJSONLocalizedOnly(resource, locale, localeDefault)`.\n\n# Tests\n\nTo run the tests you need a local MongoDB instance available. Run with:\n\n```\nnpm test\n```\n# Issues\n\nPlease use the GitHub issue tracker to raise any problems or feature requests.\n\nIf you would like to submit a pull request with any changes you make, please feel free!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusty1s%2Fmongoose-i18n-localize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frusty1s%2Fmongoose-i18n-localize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusty1s%2Fmongoose-i18n-localize/lists"}