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

Switch also the backend locale when changing the language via URL parameter #739

Merged
merged 1 commit into from
Sep 6, 2023

Conversation

lslezak
Copy link
Member

@lslezak lslezak commented Sep 5, 2023

Problem

  • Currently we only change the UI frontend locale, the messages from the backend are not translated

Solution

  • Change also the backend locale to get translated texts from libstorage-ng and others

Testing

  • Added a new unit test
  • Tested manually

Notes

Originally I implemented the backed switcher in the L10nWrapper component which changes the language for the frontend.

But the problem is that switching the backend language requires DBus access which displays a message "Loading installation environment" while initializing. That message would be untranslated and if the DBus initialization failed it would display and an untranslated error as well.

For that reason I have split the language switching into two parts. First it changes the frontend language and reloads the page so it displays the translated message during the DBus initialization. Then it changes the backend language and reloads again.

Two reloads might look a bit too much but the first one is very quick (~200ms in production), the second reload takes more time (1-2s) but at least it displays a translated progress message.

(This is valid for the language switching using the URL parameter, when implementing the language selection in the UI one reload should be enough.)

async setUILanguage(lang) {
const proxy = await this.client.proxy(LANGUAGE_IFACE);
proxy.UILocale = lang;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, there is also method to list UILanguages and it is useful for matching values. As e.g. czech is cs_CZ but in yast we use only cs locale. So there should be ideally some method that do matching of available locales and ones set in cockpit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is for setting the locale via ?lang= URL query parameter. This should be used by experts and the user is responsible for using the correct locale name. I think this is OK as the initial implementation, we can improve it later if needed.

And the UI selector should only offer supported values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, even if it does not work, I think we will find it soon ( as I am not sure if web UI locale will be the same )

@lslezak lslezak merged commit befc585 into master Sep 6, 2023
10 checks passed
@lslezak lslezak deleted the backend_locale branch September 6, 2023 06:59
@imobachgs imobachgs mentioned this pull request Sep 26, 2023
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

Successfully merging this pull request may close these issues.

None yet

2 participants