implement locale fallback for all locales #5718
Open
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.
This implements language fallbacks in a more generic approach.
Instead of picking the locale string collection at the start, we try the locales and their fallbacks in order searching for a specific string.
The goal is to allow supporting custom locales more easily:
nl-something
, which is unknown would result in strings from thenl
translations.The idea is that instead of picking a whole locale dictionary at the start, we just define all possible locales.
Imagine this situation:
In the current version, requesting an unknown language will just use the
currentLocale
, and if that doesn't exist use thedefaultLocale
.This PR changes this behavior to be more granular. It will check each dictionary:
this.locales["nl-test"]
if found returnthis.locales["nl"]
if found returnthis.locales["de-DE"]
if found returnthis.locales["de"]
if found returnthis.locales["en-US"]
if found returnthis.locales["en"]
if found returnthis.onGetExternalString(...)
Marking as a draft so we can discuss the implementation. Tests still pass even though the implementation and behavior changed, this means that the tests were not thorough enough to detect this change in behavior.