Match more specific locales to supported ones #1241
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1205
I noticed that the linked issue could be solved by the
nonExplicitSupportedLngs
setting for i18next (see here), but the existing system for choosing the language bypassed the i18next code where that setting applied. Therefore I moved the code for getting languages into a simplelanguageDetector
plugin for i18next.For reference on these plugins, I used the docs and the source of the package i18next-browser-languagedetector.
I was then able to simplify some other code that references the current language by referring to the value tracked by i18next.
I've tested the code locally to confirm that the issue is resolved. I tested using a browser language order of
["en-GB", "nl", "en-US", "en"]
. The behaviour without my changes is to show the site in Dutch (it skipped"en-GB"
and found"nl"
). The behaviour with my changes is to show the site in English (it recognises that"en"
strings are suitable for the"en-GB"
locale).