{"id":13423769,"url":"https://github.com/UnlyEd/universal-language-detector","last_synced_at":"2025-03-15T17:32:15.248Z","repository":{"id":115854515,"uuid":"230812548","full_name":"UnlyEd/universal-language-detector","owner":"UnlyEd","description":"Language detector that works universally (browser + server) - Meant to be used with a universal framework, such as Next.js","archived":false,"fork":false,"pushed_at":"2020-04-23T13:09:29.000Z","size":258,"stargazers_count":95,"open_issues_count":1,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-26T23:51:23.433Z","etag":null,"topics":["i18n","i18next","javascript-library","language","language-detection","language-detection-lib","language-detector","locale","locale-awareness","locale-detect","nextjs","nodejs-library","typescript-library"],"latest_commit_sha":null,"homepage":"https://universal-language-detector.now.sh/","language":"TypeScript","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/UnlyEd.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"liberapay":"unlyEd","github":["UnlyEd","Vadorequest"]}},"created_at":"2019-12-29T22:52:29.000Z","updated_at":"2025-02-25T13:56:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"e1485351-4623-49f5-af5b-5d3435ec07ae","html_url":"https://github.com/UnlyEd/universal-language-detector","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UnlyEd%2Funiversal-language-detector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UnlyEd%2Funiversal-language-detector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UnlyEd%2Funiversal-language-detector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UnlyEd%2Funiversal-language-detector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UnlyEd","download_url":"https://codeload.github.com/UnlyEd/universal-language-detector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243767242,"owners_count":20344895,"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":["i18n","i18next","javascript-library","language","language-detection","language-detection-lib","language-detector","locale","locale-awareness","locale-detect","nextjs","nodejs-library","typescript-library"],"created_at":"2024-07-31T00:00:42.014Z","updated_at":"2025-03-15T17:32:14.802Z","avatar_url":"https://github.com/UnlyEd.png","language":"TypeScript","readme":"\u003ca href=\"https://unly.org\"\u003e\u003cimg src=\"https://storage.googleapis.com/unly/images/ICON_UNLY.png\" align=\"right\" height=\"20\" alt=\"Unly logo\" title=\"Unly logo\" /\u003e\u003c/a\u003e\n[![Maintainability](https://api.codeclimate.com/v1/badges/424ff73928475fd2331f/maintainability)](https://codeclimate.com/github/UnlyEd/universal-language-detector/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/424ff73928475fd2331f/test_coverage)](https://codeclimate.com/github/UnlyEd/universal-language-detector/test_coverage)\n[![Known Vulnerabilities](https://snyk.io/test/github/UnlyEd/universal-language-detector/badge.svg?targetFile=package.json)](https://snyk.io/test/github/UnlyEd/universal-language-detector?targetFile=package.json)\n# Universal Language Detector\n\n\u003e Language detector that works universally (browser + server)\n\u003e\n\u003e - On the server, will rely on \"cookies \u003e accept-language header\"\n\u003e - On the browser, will rely on \"cookies \u003e navigator settings\"\n\u003e\n\u003e Meant to be used with a universal framework, such as Next.js\n\n\nNote that this lib helps resolving the **`language`** (`fr`, `en`, `es`, etc.), **not the locale** (`fr-FR`, `en-US`, etc.)\n\n_It is not out of scope though, PR are welcome to support universal locale detection._ \n\n---\n\n\u003c!-- toc --\u003e\n\n  * [Demo](#demo)\n  * [Getting started](#getting-started)\n  * [Examples](#examples)\n  * [API](#api)\n    + [`universalLanguageDetect`](#universallanguagedetect)\n  * [Contributing](#contributing)\n    + [Working locally](#working-locally)\n    + [Test](#test)\n    + [Versions](#versions)\n      - [SemVer](#semver)\n    + [Releasing and publishing](#releasing-and-publishing)\n  * [Changelog](#changelog)\n  * [License](#license)\n- [Vulnerability disclosure](#vulnerability-disclosure)\n- [Contributors and maintainers](#contributors-and-maintainers)\n- [**[ABOUT UNLY]**](#about-unly-)\n\n\u003c!-- tocstop --\u003e\n\n---\n\n## Demo\n\n[Live demo with the Next.js example](https://universal-language-detector.now.sh/)\n\n## Getting started\n\n```\nyarn install @unly/universal-language-detector\n```\n\nUse:\n\n```\nimport universalLanguageDetect from '@unly/universal-language-detector';\n\nOR\n\nimport { universalLanguageDetect } from '@unly/universal-language-detector';\n```\n\n## Examples\n\nSee [our example](./examples/with-next) featuring the Next.js framework\n\n---\n\n## API\n\n\u003e Extensive API documentation can be found in the [source code documentation](./src/index.ts)\n\u003e\n\u003e Only the most useful API methods are documented here, the other aren't meant to be used, even though they may be\n\n### `universalLanguageDetect`\n\n\u003e Detects the language used, universally. \n\n**Parameters:**\n- `supportedLanguages`: string[];\n- `fallbackLanguage`: string;\n- `acceptLanguageHeader?`: string | undefined;\n- `serverCookies?`: object | undefined;\n- `errorHandler?`: [ErrorHandler](./src/utils/error.ts) | undefined;\n\n**Example:**\n```js\nconst lang = universalLanguageDetect({\n  supportedLanguages: SUPPORTED_LANGUAGES, // Whitelist of supported languages, will be used to filter out languages that aren't supported\n  fallbackLanguage: FALLBACK_LANG, // Fallback language in case the user's language cannot be resolved\n  acceptLanguageHeader: get(req, 'headers.accept-language'), // Optional - Accept-language header will be used when resolving the language on the server side\n  serverCookies: cookies, // Optional - Cookie \"i18next\" takes precedence over navigator configuration (ex: \"i18next: fr\"), will only be used on the server side\n  errorHandler: (error) =\u003e { // Optional - Use you own logger here, Sentry, etc.\n    console.log('Custom error handler:');\n    console.error(error);\n  },\n});\n```\n\n---\n\n## Contributing\n\nWe gladly accept PRs, but please open an issue first so we can discuss it beforehand.\n\n### Working locally\n\n```\nyarn start # Shortcut - Runs linter + build + tests in concurrent mode (watch mode)\n\nOR run each process separately for finer control\n\nyarn lint\nyarn build\nyarn test\n```\n\n### Test\n\n```\nyarn test # Run all tests, interactive and watch mode\nyarn test:once\nyarn test:coverage\n```\n\n### Versions\n\n#### SemVer\n\nWe use Semantic Versioning for this project: https://semver.org/. (`vMAJOR.MINOR.PATCH`: `v1.0.1`)\n\n- Major version: Must be changed when Breaking Changes are made (public API isn't backward compatible).\n  - A function has been renamed/removed from the public API\n  - Something has changed that will cause the app to behave differently with the same configuration\n- Minor version: Must be changed when a new feature is added or updated (without breaking change nor behavioral change)\n- Patch version: Must be changed when any change is made that isn't either Major nor Minor. (Misc, doc, etc.)\n\n### Releasing and publishing\n\n```\nyarn releaseAndPublish # Shortcut - Will prompt for bump version, commit, create git tag, push commit/tag and publish to NPM\n\nyarn release # Will prompt for bump version, commit, create git tag, push commit/tag\nnpm publish # Will publish to NPM\n```\n\n\u003e Don't forget we are using SemVer, please follow our SemVer rules.\n\n**Pro hint**: use `beta` tag if you're in a work-in-progress (or unsure) to avoid releasing WIP versions that looks legit\n\n---\n\n## Changelog\n\n\u003e Our API change (including breaking changes and \"how to migrate\") are documented in the Changelog.\n\nSee [changelog](./CHANGELOG.md)\n\n---\n\n## License\n\nMIT\n\n---\n\n\u003e This project was generated using https://github.com/UnlyEd/boilerplate-generator/tree/master/templates/typescript-OSS\n\n# Vulnerability disclosure\n\n[See our policy](https://github.com/UnlyEd/Unly).\n\n---\n\n# Contributors and maintainers\n\nThis project is being maintained by:\n- [Unly] Ambroise Dhenain ([Vadorequest](https://github.com/vadorequest)) **(active)**\n\n---\n\n# **[ABOUT UNLY]** \u003ca href=\"https://unly.org\"\u003e\u003cimg src=\"https://storage.googleapis.com/unly/images/ICON_UNLY.png\" height=\"40\" align=\"right\" alt=\"Unly logo\" title=\"Unly logo\" /\u003e\u003c/a\u003e\n\n\u003e [Unly](https://unly.org) is a socially responsible company, fighting inequality and facilitating access to higher education. \n\u003e Unly is committed to making education more inclusive, through responsible funding for students. \n\nWe provide technological solutions to help students find the necessary funding for their studies. \n\nWe proudly participate in many TechForGood initiatives. To support and learn more about our actions to make education accessible, visit : \n- https://twitter.com/UnlyEd\n- https://www.facebook.com/UnlyEd/\n- https://www.linkedin.com/company/unly\n- [Interested to work with us?](https://jobs.zenploy.io/unly/about)\n\nTech tips and tricks from our CTO on our [Medium page](https://medium.com/unly-org/tech/home)!\n\n#TECHFORGOOD #EDUCATIONFORALL","funding_links":["https://liberapay.com/unlyEd","https://github.com/sponsors/UnlyEd","https://github.com/sponsors/Vadorequest"],"categories":["Extensions","TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUnlyEd%2Funiversal-language-detector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FUnlyEd%2Funiversal-language-detector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUnlyEd%2Funiversal-language-detector/lists"}