{"id":23291006,"url":"https://github.com/jplusplus/langparser","last_synced_at":"2025-04-06T17:44:28.403Z","repository":{"id":48333129,"uuid":"138590138","full_name":"jplusplus/langparser","owner":"jplusplus","description":"Restify middleware for parsing language/locale url parameters","archived":false,"fork":false,"pushed_at":"2023-07-18T20:09:36.000Z","size":385,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T09:46:24.492Z","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/jplusplus.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-25T12:10:30.000Z","updated_at":"2022-08-15T09:01:13.000Z","dependencies_parsed_at":"2024-12-23T17:16:08.749Z","dependency_job_id":null,"html_url":"https://github.com/jplusplus/langparser","commit_stats":{"total_commits":77,"total_committers":4,"mean_commits":19.25,"dds":0.5194805194805194,"last_synced_commit":"080a84f713e409284f1b97f588de32518ce82850"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jplusplus%2Flangparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jplusplus%2Flangparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jplusplus%2Flangparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jplusplus%2Flangparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jplusplus","download_url":"https://codeload.github.com/jplusplus/langparser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247526675,"owners_count":20953141,"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-12-20T05:13:51.155Z","updated_at":"2025-04-06T17:44:28.381Z","avatar_url":"https://github.com/jplusplus.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Langparser\n[![npm package](https://nodei.co/npm/langparser.png)](https://nodei.co/npm/langparser/)\n\nA middleware for parsing language/locale url parameters in Express, Fastify or Restify (or derivatives).\n\nThis middleware looks for a language tag in the query string (by default in `lang=XX` or `language=XX`), and tries to parse out locale and language, according to BCP 47.\nParsed values will be available for any following routes in `res.locals.lang` and `res.locals.locale`\nrespectively.\n\n# Installation\n\n``` sh\nnpm install langparser\n```\n\n# Usage\n\n```js\nconst langParser = require(\"langparser\")\n\nserver.use(langParser())\n\nserver.get(\"/my/route\", (req, res, next) =\u003e {\n  console.log(req.locals.lang)\n  // Visiting /my/route?lang=sv-AX will print 'sv'\n  // Visiting /my/route?lang=i-klingon will print 'tlh'\n  console.log(req.locals.locale)\n  // Visiting /my/route?lang=sv-AX will print 'sv-AX'\n  // Visiting /my/route?lang=i-klingon will print 'tlh'\n})\n```\n\nThe following options are available:\n\n```js\nserver.use(langParser({\n  defaultLang: \"en-GB\",  // Fallback language/locale if none found\n  params: [\"sprache\", \"lingua\"]  // URL param(s) to look for\n}))\n```\n\nBy default we will look for the url parameters `lang` and `language`.\n\n## Restify\n\nIf you want this middleware to work with post requests in Restify, you need to call the bodyParser middleware before this one.\n\nFor Restify 5.0 and newer:\n\n```js\nserver.use(restify.plugins.bodyParser())\nserver.use(langParser())\n```\n\n## Fastify\n\nIf you use Fastify, you need the `@fastify/Express` plugin:\n\n```js\nimport express from \"@fastify/express\"\nawait fastify.register(express)\nfastify.use(langParser())\n```\nIn the Fastify routes, parsed paramerters will be available under `req.raw.locals`\n\n# Changelog\n\n+ 3.1.0\n  - Look in both `req.query` and `req.params`, as `query` is used by e.g. Fastify.\n\n+ 3.0.0\n\n  - Parse locale data moved from `res` to `req`\n  - Document Express and Fastify usage\n\n+ 2.0.1\n\n  - Specify engine requirement to NodeJS \u003e= 12.20.0, as we are now ESM only\n  - rename .eslintrc.js \u003e .eslintrc.cjs\n\n+ 2.0.0\n\n  - Convert to ESM\n\n+ 1.1.1\n\n  - Dependency upgrades\n\n+ 1.1.0\n\n  - Add Restify 8 to peerDependencies, and require NodeJS \u003e= 8\n\n+ 1.0.1\n\n  - Documentation fixes\n\n+ 1.0.0\n\n  - First version\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjplusplus%2Flangparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjplusplus%2Flangparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjplusplus%2Flangparser/lists"}