agama/web/share
Ladislav Slezák 6375ae0345
Correctly handle the "zh-Hans" language (bsc#1238584) (#2314)
## 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](https://github.com/user-attachments/assets/3c8876c6-c3de-41e6-ad35-e6aff3a499d5)


![image](https://github.com/user-attachments/assets/a9afd37a-243c-445c-8808-de5d39b49947)

---------

Co-authored-by: YaST Bot <yast-devel@opensuse.org>
Co-authored-by: Martin Vidner <mvidner@suse.com>
2025-05-07 10:59:23 +02:00
..
po Correctly handle the "zh-Hans" language (bsc#1238584) (#2314) 2025-05-07 10:59:23 +02:00
locales.json fix(web): fix capitalization of RFC 5646 language tags 2024-11-12 12:54:27 +00:00
update-languages.py fix(web): fix capitalization of RFC 5646 language tags 2024-11-12 12:54:27 +00:00