Skip to content

Conversation

@lslezak
Copy link
Contributor

@lslezak lslezak commented Apr 30, 2025

Problem

  • The storage page crashes after selecting Chinese language ("zh-Hans")
  • https://bugzilla.suse.com/show_bug.cgi?id=1238584
  • A similar problem exists also with the pt_BR language as it also uses a country code. (All other languages use just a simple language code without any separator.) But it is less serious as the pt_BR locale is known by glibc so we do not need to do any additional conversions besides using the correct language separator.
  • The underlying problem is that Linux and the Web (browsers) use two different standards for identifying locales and languages: POSIX locale identifiers such as zh_TW.UTF-8 and IETF language tags such as zh-Hant. Agama sometimes uses a punctuation-only conversion which only works for some cases.

Solution

  • Change the zh_Hans in Weblate to zh_CN so we do not need to do any conversions
  • Change the web frontend to consistently use the dash (-) separator in all places, avoid unnecessary conversions, convert to underscore only when sending to the backend
  • Convert the underscore (_) separator to dash (-) when importing the frontend translations from Weblate
  • Handle exceptions in the Intl.ListFormat formatting function, in case of exception fallback to a simple formatting function with comma separator (", ")

Notes

  • It turned out that actually only the C.UTF-8 and en_US.UTF-8 locales were present in the Live ISO. Unfortunately the filtering regexp was not updated after renaming the PO translation files from po.<lang>.js to po-<lang>.js. 😱
  • I have changed the code to read the supported languages from the languages.json file. That allows more precise filtering. In the past we kept e.g. all de_DE, de_AT, de_CH for German language. Now we know that after selecting German the de_DE locale will be used so we can delete the de_AT and de_CH locales from the live ISO.

Testing

  • Added a new unit test
  • Tested manually
    • The web frontend does not crash a properly displays the formatted text, the Intl.ListFormat function is used in the New partitions will be created for "/" <and> "swap" text
    • The backend receives a valid Linux locale (zh_CN.UTF-8)
    • The Web UI translation files use the dash separator
    • The Live ISO contains all supported locales (locale -a)

agama-zh-CN

image

Copy link
Contributor

@mvidner mvidner left a comment

Choose a reason for hiding this comment

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

  1. Some more cleanup in the code you have already touched
  2. Unfortunately Weblate is giving us a hybrid of the two language standards, IMHO we should fight back or be forever stuck with a mess

* @see https://datatracker.ietf.org/doc/html/rfc5646
* @see https://www.rfc-editor.org/info/bcp78
*/
function languageToLocale(language: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

please note there is also an inverse languageFromLocale function above, which also needs fixing, and testing

@imobachgs
Copy link
Contributor

May I suggest to prevent crashes by catching exceptions in the formatList function?

Copy link
Contributor

@imobachgs imobachgs left a comment

Choose a reason for hiding this comment

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

In general it looks great. Just a minor comment about the formatList fallback.

Copy link
Contributor

@mvidner mvidner left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Consider applying a jq explanation

install -D -m 0644 --target-directory=%{buildroot}%{_datadir}/agama/web_ui %{_builddir}/agama/dist/*.{css,gz,html,js,json,map,svg}
install -D -m 0644 --target-directory=%{buildroot}%{_datadir}/agama/web_ui/fonts %{_builddir}/agama/dist/fonts/*.ttf
install -D -m 0644 --target-directory=%{buildroot}%{_datadir}/agama/web_ui/assets/logos %{_builddir}/agama/src/assets/products/*.svg
install -D -m 0644 --target-directory=%{buildroot}%{_datadir}/agama/web_ui/assets/logos %{_builddir}/agama/dist/assets/logos/*.svg
Copy link
Contributor

Choose a reason for hiding this comment

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

NP: in the future we might want to go with a web/install.sh approach like the other parts of Agama do (part of #2103). I forgot to do it because I was not doing any changes in the front end at the time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, would be nice to unify this to have a single place for changes.

Co-authored-by: Martin Vidner <[email protected]>
@lslezak lslezak merged commit 6375ae0 into master May 7, 2025
9 checks passed
@lslezak lslezak deleted the locale_fixes branch May 7, 2025 08:59
@imobachgs imobachgs mentioned this pull request May 26, 2025
imobachgs added a commit that referenced this pull request May 26, 2025
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.

6 participants