-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEATURE: Setting preferred locale and fallback manually #5026
base: release/v2.5.x
Are you sure you want to change the base?
FEATURE: Setting preferred locale and fallback manually #5026
Conversation
…e for app translations.
lang/lang.go
Outdated
@@ -159,6 +161,15 @@ func AddTranslationsFS(fs embed.FS, dir string) (retErr error) { | |||
return retErr | |||
} | |||
|
|||
// SetPreferredLanguage allows an app to set the preferred language for translations, overwriting the System Locale. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this adds a new public API, it will need to be targeted for Fyne 2.6 and should have a Since: 2.6
line in the comment (see other APIs for an example). Also the PR should be based against develop instead of the release branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will leave it to @andydotxyz to manage the branches since I'm not sure what our usual process is for keeping develop
in sync with release/v2.x.x
branches
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Release branch goes back into develop after each point release, so it should have been done a few weeks back.
I see there is a note about branch merging which I will look at shortly. Also an open question - is this a lang package feature or is it a setting (like the font size or colour variant. If you could articulate the use-case it will help us to understand the right place for the feature. |
The use case is for apps to be able to have a user-configurable setting to change the language for just that app. One reason this could be desirable is for apps with incomplete translations, which can happen often with open source projects with volunteer translators. If the system locale for some user is set to German, for example, and they are using an app that has incomplete German translations, but they can speak English well and the app does have complete English translations (since it is the developer's native language), then that user might want to be able to set just that app to use English despite system locale being German. |
Is this impacted by the resolution of #5040 ? |
As far as I can see the API does not match the use-case description then. I know it sounds boring but we have to get right what is expected and have naming that matches that perfectly, otherwise we will get surprising or unfortunate side-effects and follow-on bug reports. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this. As the CI shows, you have to stick to APIs that were in Go 1.19 to maintain support with existing Fyne usage.
Sorry. haven't seen there is already a PR for it as i added the fallback option. Meaning, i sort the translated array instead of adding an english entry, so not sure if we need #5040 then. i guess mine has the benefit that the user can set his own fallback? in any case, in my PR english is the default as well which is tried first as fallback. |
My point was really that the fix was landed already - so is no longer required to make this feature land. According to the title "Setting preferred locale and fallback manually" it implies that the fallback could be set - replacing the current default of "en". This re-uses more of the code and is a smaller change. |
|
||
// SetPreferredLocale allows an app to set the preferred locale for translations, overwriting the System Locale. | ||
// locale can be in format en_US_someVariant, en_US, en-US-someVariant, en-US, en | ||
// Since 2.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't the right format for a since line, missing : and the blank comment line above - see https://github.com/fyne-io/fyne/wiki/Contributing (or other Since: lines in the codebase).
Description:
Sometimes you might want the user to load a different language file, other than the systems current locale.
This adds a
SetPreferredLocale()
that you can call before or after for exampleAddTranslationsFS()
and will set a custom locale.This way, the preferred language is looked up for translations.
Also added a
SetLanguageOrder()
function that reorders the added languages, in which case the first language is used as fallback when no locale is found.with this, on a foreign language OS system, you can call
Checklist:
Where applicable: