Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions live/src/agama-installer.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Apr 30 11:14:55 UTC 2025 - Ladislav Slezák <[email protected]>

- Fixed locale cleanup to not delete all locales
- Correctly handle the "zh-Hans" language (bsc#1238584)

-------------------------------------------------------------------
Tue Apr 29 11:30:59 UTC 2025 - Ladislav Slezák <[email protected]>

Expand Down
2 changes: 1 addition & 1 deletion live/src/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ ls -1 -d /usr/lib/locale/*.utf8 | sed -e "s#/usr/lib/locale/##" -e "s#utf8#UTF-8

# delete translations and unsupported languages (makes ISO about 22MiB smaller)
# build list of ignore options for "ls" with supported languages like "-I cs* -I de* -I es* ..."
readarray -t IGNORE_OPTS < <(ls /usr/share/agama/web_ui/po.*.js.gz | sed -e "s#/usr/share/agama/web_ui/po\.\(.*\)\.js\.gz#-I\n\\1*#")
readarray -t IGNORE_OPTS < <(ls /usr/share/agama/web_ui/po-*.js.gz | sed -e "s#/usr/share/agama/web_ui/po-\(.*\)\.js\.gz#-I\n\\1*#" -e "s/zh_Hans/zh_CN/")
# additionally keep the en_US translations
ls -1 "${IGNORE_OPTS[@]}" -I en_US /usr/share/locale/ | xargs -I% sh -c "echo 'Removing translations %...' && rm -rf /usr/share/locale/%"

Expand Down
7 changes: 7 additions & 0 deletions web/package/agama-web-ui.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Apr 30 11:45:08 UTC 2025 - Ladislav Slezák <[email protected]>

- Use the correct locale format in the Intl.ListFormat.format call
(bsc#1238584)
- Set the "zh_CN" locale in backend for the "zh-Hans" language

-------------------------------------------------------------------
Tue Apr 22 14:14:53 UTC 2025 - Imobach Gonzalez Sosa <[email protected]>

Expand Down
47 changes: 47 additions & 0 deletions web/src/agama.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) [2025] SUSE LLC
*
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, contact SUSE LLC.
*
* To contact SUSE LLC about this file by physical or electronic mail, you may
* find current contact information at www.suse.com.
*/

import agama from "~/agama";

describe("agama", () => {
describe("formatList", () => {
afterEach(() => {
// restore the default language
agama.language = "en";
});

it("it accepts a locale with underscore", () => {
agama.language = "zh_Hans";
const list = agama.formatList(["1", "2", "3"], {});
expect(list).toEqual("1、2和3");
});

it("it fallbacks to a simple formatting when the localized function fails", () => {
agama.language = "invalid:language";
// disable the console logging in this test, a failure is expected so do
// not mess the output with a false alarm
jest.spyOn(console, "warn").mockImplementation();
const list = agama.formatList(["1", "2", "3"], {});
expect(list).toEqual("1, 2, 3");
});
});
});
11 changes: 9 additions & 2 deletions web/src/agama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,15 @@ const agama = {
* @param options passed to the Intl.ListFormat constructor
*/
formatList: (list: string[], options: object): string => {
const formatter = new Intl.ListFormat(agama.language, options);
return formatter.format(list);
try {
// convert the locale string ("_" separator) to HTTP language code ("-" separator)
const formatter = new Intl.ListFormat(agama.language.replace("_", "-"), options);
return formatter.format(list);
} catch (e) {
// use a trivial formatting with commas when the locale formatting fails for whatever reason
console.warn("Using fallback function for formatting localized array:", e);
return list.join(", ");
}
},
};

Expand Down
8 changes: 7 additions & 1 deletion web/src/context/installerL10n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ function languageFromLocale(locale: string): string {
* @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

const [lang, country] = language.split("-");
let [lang, country] = language.split("-");

// glibc does not know the "zh_HANS.UTF-8" locale, change it to "zh_CN.UTF-8"
if (country === "Hans") {
country = "CN";
}

const locale = country ? `${lang}_${country.toUpperCase()}` : lang;
return `${locale}.UTF-8`;
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import { _, n_, N_, Nn_ } from "~/i18n";
import agama from "~/agama";

// mock the cockpit gettext functions
// mock the gettext functions
jest.mock("~/agama", () => ({
...jest.requireActual("~/agama"),
gettext: jest.fn(),
Expand Down