{"id":20994087,"url":"https://github.com/tradeshift/g11n-langneg","last_synced_at":"2025-05-14T21:30:39.707Z","repository":{"id":37824221,"uuid":"253721735","full_name":"Tradeshift/g11n-langneg","owner":"Tradeshift","description":"Language negotiation helpers","archived":false,"fork":false,"pushed_at":"2025-04-25T15:00:28.000Z","size":893,"stargazers_count":1,"open_issues_count":16,"forks_count":7,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-25T16:21:54.632Z","etag":null,"topics":["bcp-47","globalization","language-negotiation","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/Tradeshift.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}},"created_at":"2020-04-07T07:40:04.000Z","updated_at":"2024-11-19T12:09:33.000Z","dependencies_parsed_at":"2024-01-22T00:39:46.064Z","dependency_job_id":"4f4add1f-919c-4162-94ff-7b6b832751b0","html_url":"https://github.com/Tradeshift/g11n-langneg","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tradeshift%2Fg11n-langneg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tradeshift%2Fg11n-langneg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tradeshift%2Fg11n-langneg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tradeshift%2Fg11n-langneg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tradeshift","download_url":"https://codeload.github.com/Tradeshift/g11n-langneg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254230746,"owners_count":22036230,"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":["bcp-47","globalization","language-negotiation","locale"],"created_at":"2024-11-19T07:16:47.490Z","updated_at":"2025-05-14T21:30:38.903Z","avatar_url":"https://github.com/Tradeshift.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# g11n-langneg\n\nLanguage negotiation helpers\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Usage](#usage)\n  - [Locale](#locale)\n    - [Parsing (strict and lenient)](#parsing-strict-and-lenient)\n    - [Maximization (Likely Subtags)](#maximization-likely-subtags)\n    - [Accessing and modifying subtags](#accessing-and-modifying-subtags)\n- [Release](#release)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Usage\n\n```typescript\nimport { Locale, match } from \"@tradeshift/g11n-langneg\";\n\nconst result: Locale = match(\"pt-Latn-BR\", [\"da\", \"en\", \"es\", \"pt\"]);\n// result == Locale.parse('pt')`\n\n// also accepts `Locale` objects as inputs\nconst result2: Locale = match(Locale.parse(\"pt-Latn-BR\"), [\n  Locale.parse(\"da\"),\n  Locale.parse(\"pt\"),\n]);\n// result2 == Locale.parse('pt')`\n```\n\nIf there's no match, it will return the first candidate in the list, so the first element should always be your preferred/default locale.\n\n```typescript\nconst result: Locale = match(\"pt\", [\"en\", \"da\", \"es\"]);\n// result == Locale.parse('en')`\n```\n\n### Locale\n\n#### Parsing (strict and lenient)\n\n```typescript\nimport { Locale } from \"@tradeshift/g11n-langneg\";\n\n// lenient parsing of locales, invalid locales will parse to `und`\nconst locale: Locale = Locale.parse(\"pt-BR\");\n\n// strict parsing of locales will throw errors for invalid locales\ntry {\n  const invalid = Locale.parseStrict(\"abcdefghijklmnopq\");\n} catch (e) {\n  throw e;\n}\n```\n\n#### Maximization (Likely Subtags)\n\nNote: g11n-langneg uses a small subset of the likely subtags CLDR data\n\n```typescript\nconst locale: Locale = Locale.parse(\"pt-BR\");\nconst maximized: Locale = locale.maximize(); // equivalent to 'pt-Latn-BR'\n```\n\n#### Accessing and modifying subtags\n\n```typescript\nconst locale: Locale = Locale.parse(\"pt-Latn-BR\");\n\nconst language: string = locale.getLanguage(); // pt\nconst script: string = locale.getScript(); // Latn\nconst region: string = locale.getRegion(); // BR\n\nconst ptCyrl: Locale = locale.setScript(\"Cyrl\"); // pt-Cyrl-BR\nconst ptPT: Locale = locale.setRegion(\"PT\"); // pt-Latn-PT\n```\n\n## Release\n\nSemantic release: (Commit conventions)\n\nNo new version will be released unless specific commit message is used. See [Commit conventions](https://github.com/conventional-changelog-archived-repos/conventional-changelog-angular/blob/master/convention.md) for details.\nIf a release is expected, please fix commit messages to align with appropriate format\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftradeshift%2Fg11n-langneg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftradeshift%2Fg11n-langneg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftradeshift%2Fg11n-langneg/lists"}