{"id":16827029,"url":"https://github.com/wojtekmaj/get-user-locale","last_synced_at":"2025-05-16T01:05:32.133Z","repository":{"id":47125673,"uuid":"144832407","full_name":"wojtekmaj/get-user-locale","owner":"wojtekmaj","description":"A function that returns user's locale as an IETF language tag, based on all available sources.","archived":false,"fork":false,"pushed_at":"2025-04-30T19:09:34.000Z","size":3651,"stargazers_count":61,"open_issues_count":1,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-08T20:53:40.928Z","etag":null,"topics":["i18n","language","language-detection","locale"],"latest_commit_sha":null,"homepage":"","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/wojtekmaj.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"wojtekmaj"}},"created_at":"2018-08-15T09:17:55.000Z","updated_at":"2025-03-31T22:08:26.000Z","dependencies_parsed_at":"2023-10-24T21:32:13.474Z","dependency_job_id":"1fdd1991-fff9-4423-b15a-165fdcb2e216","html_url":"https://github.com/wojtekmaj/get-user-locale","commit_stats":{"total_commits":281,"total_committers":8,"mean_commits":35.125,"dds":0.08540925266903909,"last_synced_commit":"153ba5062984bb6ce62a775fc978db4ca2e30a9a"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wojtekmaj%2Fget-user-locale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wojtekmaj%2Fget-user-locale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wojtekmaj%2Fget-user-locale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wojtekmaj%2Fget-user-locale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wojtekmaj","download_url":"https://codeload.github.com/wojtekmaj/get-user-locale/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254448579,"owners_count":22072764,"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","language","language-detection","locale"],"created_at":"2024-10-13T11:19:25.269Z","updated_at":"2025-05-16T01:05:27.122Z","avatar_url":"https://github.com/wojtekmaj.png","language":"TypeScript","funding_links":["https://github.com/sponsors/wojtekmaj"],"categories":[],"sub_categories":[],"readme":"[![npm](https://img.shields.io/npm/v/get-user-locale.svg)](https://www.npmjs.com/package/get-user-locale) ![downloads](https://img.shields.io/npm/dt/get-user-locale.svg) [![CI](https://github.com/wojtekmaj/get-user-locale/actions/workflows/ci.yml/badge.svg)](https://github.com/wojtekmaj/get-user-locale/actions)\n\n# Get-User-Locale\n\nA function that returns user's locale as an [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag), based on all available sources.\n\n## tl;dr\n\n- Install by executing `npm install get-user-locale` or `yarn add get-user-locale`.\n- Import by adding `import getUserLocale from 'get-user-locale'`.\n- Do stuff with it!\n  ```ts\n  const userLocale = getUserLocale();\n  ```\n\n## User guide\n\n### `getUserLocale()`\n\nA function that returns user's preferred locale as an [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag), based on all available sources.\n\n#### Sample usage\n\n```ts\nimport getUserLocale from 'get-user-locale';\n\ngetUserLocale(); // 'de-DE'\n```\n\nor\n\n```ts\nimport { getUserLocale } from 'get-user-locale';\n\ngetUserLocale(); // 'de-DE'\n```\n\n##### Options\n\n`getUserLocale()` may be called with an optional `options` argument.\n\n`options` object may contain the following properties:\n\n| Property            | Description                         | Default value |\n| ------------------- | ----------------------------------- | ------------- |\n| `fallbackLocale`    | A locale to use as a fallback.      | `en-US`       |\n| `useFallbackLocale` | Whether to use the fallback locale. | `true`        |\n\n### `getUserLocales()`\n\nA function that returns an array of user's preferred locales as an [IETF language tags](https://en.wikipedia.org/wiki/IETF_language_tag), based on all available sources.\n\n#### Sample usage\n\n```ts\nimport { getUserLocales } from 'get-user-locale';\n\ngetUserLocales(); // ['de-DE', 'de', 'en-US', 'en']\n```\n\n##### Options\n\n`getUserLocales()` may be called with an optional `options` argument.\n\n`options` object may contain the following properties:\n\n| Property            | Description                         | Default value |\n| ------------------- | ----------------------------------- | ------------- |\n| `fallbackLocale`    | A locale to use as a fallback.      | `en-US`       |\n| `useFallbackLocale` | Whether to use the fallback locale. | `true`        |\n\n## Technical details\n\nThere are a few ways of determining user's locale:\n\n- `window.navigator.languages`\n- `window.navigator.language`\n\n`…languages` is an array of strings, `…language` is a string. Some browsers return mixed-case [IETF language tags](https://en.wikipedia.org/wiki/IETF_language_tag) (e.g. `de-DE`), while others return lowercase ones (e.g. `de-de`). Finally, non-browser environments will not return anything, so you need a fallback.\n\nGet-User-Locale does the following:\n\n- Combines all of them into one sane set of locales - in that particular order,\n- Dedupes them,\n- Fixes invalid, lowercased [IETF language tags](https://en.wikipedia.org/wiki/IETF_language_tag) (so that the part after `-` is always uppercased),\n- Adds a fallback to `en-US`, so if all else fails, you will get a result that won't crash your app.\n\n## License\n\nThe MIT License.\n\n## Author\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd \u003e\n      \u003cimg src=\"https://avatars.githubusercontent.com/u/5426427?v=4\u0026s=128\" width=\"64\" height=\"64\" alt=\"Wojciech Maj\"\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"https://github.com/wojtekmaj\"\u003eWojciech Maj\u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwojtekmaj%2Fget-user-locale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwojtekmaj%2Fget-user-locale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwojtekmaj%2Fget-user-locale/lists"}