Mapping detected browser locale to available locales
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.9k
- Forks
- 457
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 16
Description
Hello, I want to detect the locale from users browser for which I used the detect-locale library. However, it can return basically any locale like 'en-GB', but in my app I support only 'en' locale so I need to map it to one of the available locales based on the CLDR inheritance, but I didn't find a way to do this using Lingui apart from implementing it myself, which seems ridiculous. I thought that if I load only the available locales and then I activate whichever locale is detected from browser and the library will handle the inheritance and fallback automatically, but that does not seem to be the case, it just prints a warning, that en-GB was not loaded and uses the default messages (not the en/messages.po) and I do have set up `default: "en"` in the fallbackLocales in the config. I think there should be some utility function that will get fallback to the available locales based on given locale, because it's needed for dynamic imports where you have to specify the path to .po file based on locale. Or am I missing something?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing locale activation, fallbackLocales, and the dynamic-import path selection described in the issue. Define how an unavailable browser locale such as en-GB should resolve against the available locales and CLDR inheritance, then verify that the resolved locale selects the corresponding .po file and messages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- internationalization, localization
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100