fix(input-tel): use full locale to translate country names in dropdown
What I did
- Pass full locale to
new Intl.DisplayNamesconstructor.
Issue
The constructor accepts either a language (e.g. en, nl, ...) or the full locale (e.g. en-GB, nl-BE, ...).
Instead, we're passing only the region (e.g. GB, BE, ...), which is not a valid param for the constructor.
Sometimes that works because language and region are the same (e.g. fr-FR, de-DE), but that is not always the case.
If the specified locale is not recognized, the translations default to English.
Reproduce
- Go to the demo of input-tel-dropdown extension
- Open the dropdown and check the translations.
- Open the browser dev tools to change the
langof the html tag tonl-BE. - Open the dropdown again.
- The countries are shown in English.
- Change the
langattribute tofr-FR - Open the dropdown again
- The countries are shown in French
Fix
By using the full locale in the constructor for Intl.DisplayNames, the countries are translated correctly to the browser language:
🦋 Changeset detected
Latest commit: 4b1b09ac3aaba030fc25230c9a77388aa2e9810b
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| @lion/ui | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
I have now also added a fix for the nameForRegion, which was displayed incorrectly.
I created a regionCodeToLocale function, which estimates the full locale based on a region code, in order to pass it to the new Intl.DisplayNames constructor.