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.
Description:
At the moment, fyne loads all base translations, sets the default language to English and merges in translations provided by the user.
This approach has a few downsides, though:
If the user registers only a subset (or a different set) of languages, than the base translations provided, the
closestSupportedLocale
function is not (and cannot be) aware of this. It might pick a language that has only partial (our base) translations and misses user translations. Example: the user provides custom translations for English but the app runs on a German system. Some buttons and menu items are now translated into German, but all others fall back to the provided English translation.The user may not develop their app with English in mind, so falling back to English might not be the best choice for them; especially when paired with the issue above.
This PR proposes a solution to both issues that is (mostly) backwards compatible:
closestSupportedLocale
. So for apps without any custom translations, everything behaves as before.The implementation also has two downsides, but IMO smaller ones:
That the first added translation becomes the default language is more or less implicit. When using
AddTranslationsFS
as the only (or at least first) call, one would have to make sure, that the order makes sense. It can easily be circumvented by either using file name prefixes in that case or by calling one of the otherAddTranslations*
functions first (with an empty JSON).If someone relied on base translations being in place, while they register their own, different, translations, this PR would change behavior; I think it changes for the better, though and IMO it prevents (likely) unexpected side-effects.
Checklist: