Skip to content
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

Lang package - Set the desired language #5333

Open
2 tasks done
halsten-dev opened this issue Dec 20, 2024 · 13 comments
Open
2 tasks done

Lang package - Set the desired language #5333

halsten-dev opened this issue Dec 20, 2024 · 13 comments

Comments

@halsten-dev
Copy link

Checklist

  • I have searched the issue tracker for open issues that relate to the same feature, before opening a new one.
  • This issue only relates to a single feature. I will open new issues for any other features.

Is your feature request related to a problem?

The new lang package is awesome and I like the simplicity of the json files.

I cannot understand why there is no way to manually change the current language.
Most of the time the language of an app can be changed in settings. But, the setupLang function is not shared.

If it's possible and I missed it, I'm sorry in advance.

Is it possible to construct a solution with the existing API?

It should be pretty simple. I don't know if the current setupLang should simply become public.
I guess it will take a bit more work to make it cleaner.

Describe the solution you'd like to see.

Something like :

lang.SetLang("en") // based on the file name

It would be perfect.

@andydotxyz
Copy link
Member

Does the operating system you are using not provide language setting at a central location?

Many apps are (finally) moving to a model where (like light/dark mode before it) the setting matches across all apps...

@halsten-dev
Copy link
Author

Hi Andy,

Thanks for your answer.

I agree with your design philosophy, but I'm working on a client app for an API and the language in this case is defined by user settings. Maybe you could give me the instruction for the right way to do this with the lang package and I'll implement it on my side. If you really don't think it could be a nice to have feature. Actually, the default behaviour could stay as it is now.

Thanks in advance for your precious help.

Kind regards.

@dweymouth
Copy link
Contributor

There is a PR being worked on to support this - if you're able to build from a Fyne fork you could try to work with it. - #5026

It is also possible to implement this feature without any API support from Fyne in a slightly hacky way. I recently did so to add a lanugage selector to my app because users were asking for it (mostly to force the app to English despite system language). You can load only the translation for the desired language, but in a fyne.Resource that is named as if it were the translation file for the system language.

@halsten-dev
Copy link
Author

Hi Drew,

Indeed I need a language selector too. I'm happy to see that I'm not the only one in this situation.

Thanks for your insight. I guess I can close this feature request. I will wait for this to be available. I will manage things differently for the moment.

Thanks a lot.

Kind regards, Happy Xmas to all of you.

@andydotxyz
Copy link
Member

Maybe we do need to find a clean way to help settings be applied per-app.
As long as it doesn't take us down the road where developers are forcing their preference on edit users like we got with light/dark mode before.

@dweymouth dweymouth reopened this Dec 21, 2024
@halsten-dev
Copy link
Author

That's it. Just as an extra feature. Thanks for amazing work.

@aksdb
Copy link

aksdb commented Dec 22, 2024

IMO, theme variant and language should be able to (and default to) follow system settings, while at the same time providing the ability to override it programmatically (so you CAN offer users the ability to set an exception for the app they use).

So theme variant might be system, light, dark and lang might be empty/unset (= pick the system default) or a value of your choice.

@andydotxyz
Copy link
Member

Yes indeed, that is how theme operates already and what the language defaults to.

Though it is worth noting that Apple devices (macOS and iOS) already have per-app language settings and we are seeing apps prompt users to go to system settings instead of including in the app itself...

@aksdb
Copy link

aksdb commented Dec 23, 2024

My point was rather, that currently it is the only possible option to follow system defaults. For themes this can be worked around by implementing a very simple custom theme that inherits from the default theme but allows overriding the variant (as the fyne_demo does).

For fonts though, fyne currently relies on the locale package to determine the available locales and doesn't allow any programmatic override. On Unix, the locale package honors the LANG env var, so I can more or less customize it for myself, but that is not very user friendly and I wouldn't want to tell my users "please launch my program using this env var if you want a different language". In a reasonably complex application, I have settings menus, so I don't think offering a language override in there is a bad thing.

But just to reiterate this: it's only about developers have the choice to offer that. The default should always be to simply follow system settings. For simple apps or when devs don't care, the app should behave as sane as possible. But for more complicated use-cases, having the ability to intervene and offer the user customizations beyond their system wide settings would be nice to have.


Adding my end-user perspective here, although I am obviously more of a power-user and therefore probably not a representative example:

My system language is typically German; simply because I got used to it and many people around me have their system in German. If I want to help them, it's easier for me to know the German terms for all the menus etc. However, complex/"professional" software tools I use I almost exclusively use in English. It's so much easier to get help online or find blueprints if you work with the English terms that I don't want to translate things back and forth and lose information on the way. Sometimes I also just switch the language temporarily to look something up. If I had to switch the whole OS locale every time, I would go mad.

Similar with themes: my eyes can't stand dark themes most of the time, but individual apps - depending on their color schemes - look better (= less exhausting) in dark mode. So I have most of my system in light mode but individual apps in dark mode (or vice versa). If every app forced me to have a unified light/dark mode, I would also be angry.

So obviously, if I develop an application, I try to give my users the same kind of freedom I would expect: sane defaults but lots of customization if they need it.

@andydotxyz
Copy link
Member

For themes this can be worked around by implementing a very simple custom theme that inherits from the default theme but allows overriding the variant (as the fyne_demo does).

That isn't a workaround, that is the API provided to control theme and variant.

The default should always be to simply follow system settings. For simple apps or when devs don't care, the app should behave as sane as possible. But for more complicated use-cases, having the ability to intervene and offer the user customizations beyond their system wide settings would be nice to have.

Yes. I think your long message basically says we are in agreement.

I was just pointing out that many OS are now handling this per-app so it is worth checking if the work has not already been done for you.

@alexballas
Copy link
Contributor

How I personally do it. https://github.com/alexballas/go2tv/blob/main/internal/gui/gui.go#L247-L256
Just overriding the environmental variable seems to do the trick for me.

@dweymouth
Copy link
Contributor

dweymouth commented Dec 24, 2024

@alexballas FYI that may only work on Linux, I believe on Windows and Mac, the language setting is communicated through OS APIs, not env vars

This is how I did it, if anyone's curious: https://github.com/dweymouth/supersonic/pull/510/files#diff-2873f79a86c0d8b3335cd7731b0ecf7dd4301eb19a82ef7a1cba7589b5252261R50

@alexballas
Copy link
Contributor

thank you @dweymouth! That did the trick for me. Just pushed something similar to your code here. https://github.com/alexballas/go2tv/blob/devel/internal/gui/gui.go#L252-L265

A bit simplistic given the limited number of languages my app supports, but does the trick :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants