Skip to content

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

Merged
lslezak merged 1 commit intomasterfrom
backend_locale
Sep 6, 2023
Merged

Switch also the backend locale when changing the language via URL parameter#739
lslezak merged 1 commit intomasterfrom
backend_locale

Conversation

@lslezak
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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
Copy Markdown
Contributor

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
@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.

2 participants