Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
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
7 changes: 7 additions & 0 deletions live/src/agama-installer.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed May 7 07:07:33 UTC 2025 - Ladislav Slezák <[email protected]>

- Fixed locale cleanup to not delete all locales
(related to bsc#1238584)
- Keep only the UTF-8 locales, non-UTF-8 are not supported

-------------------------------------------------------------------
Tue May 6 14:14:50 UTC 2025 - Imobach Gonzalez Sosa <[email protected]>

Expand Down
11 changes: 8 additions & 3 deletions live/src/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,25 @@ mkdir -p /etc/agama.d
ls -1 -d /usr/lib/locale/*.utf8 | sed -e "s#/usr/lib/locale/##" -e "s#utf8#UTF-8#" >/etc/agama.d/locales

# 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*#")
# build list of ignore options for "ls" with supported languages like "-I cs -I cs_CZ ..."
readarray -t IGNORE_OPTS < <(jq -r keys[] < /usr/share/agama/web_ui/languages.json | sed -e "s/\(.*\)-\(.*\)/-I\n\\1\n-I\n\1_\2/")
# 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/%"

# delete locale definitions for unsupported languages (explicitly keep the C and en_US locales)
ls -1 "${IGNORE_OPTS[@]}" -I "en_US*" -I "C.*" /usr/lib/locale/ | xargs -I% sh -c "echo 'Removing locale %...' && rm -rf /usr/lib/locale/%"
readarray -t IGNORE_OPTS < <(jq -r keys[] < /usr/share/agama/web_ui/languages.json | sed -e "s/-/_/" -e "s/$/.utf8/" -e "s/^/-I\n/")
ls -1 "${IGNORE_OPTS[@]}" -I "en_US.utf8" -I "C.utf8" /usr/lib/locale/ | xargs -I% sh -c "echo 'Removing locale %...' && rm -rf /usr/lib/locale/%"

# delete unused translations (MO files)
for t in zypper gettext-runtime p11-kit; do
rm -f /usr/share/locale/*/LC_MESSAGES/$t.mo
done
du -h -s /usr/{share,lib}/locale/

# remove printing support from GTK
rm -rf /usr/lib64/gtk-3*/*/printbackends
rpm -e --nodeps libcups2 cups-config || true

# remove documentation
du -h -s /usr/share/doc/packages/
rm -rf /usr/share/doc/packages/*
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 May 7 07:07:10 UTC 2025 - Ladislav Slezák <[email protected]>

- Use the correct locale format in the Intl.ListFormat.format call,
if it fails use a fallback formatting function to avoid a crash
(bsc#1238584)

-------------------------------------------------------------------
Mon May 5 14:50:48 UTC 2025 - David Diaz <[email protected]>

Expand Down
4 changes: 2 additions & 2 deletions web/package/agama-web-ui.spec
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ local-npm-registry %{_sourcedir} install --with=dev --legacy-peer-deps || ( find
NODE_ENV="production" npm run build

%install
install -D -m 0644 --target-directory=%{buildroot}%{_datadir}/agama/web_ui %{_builddir}/agama/dist/*.{gz,html,js,map,svg}
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.


%files
%doc README.md
Expand Down
8 changes: 4 additions & 4 deletions web/share/po/po-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function poFiles() {
function supportedLanguages() {
const langs = path.resolve(__dirname, "../../src/languages.json");
const data = JSON.parse(fs.readFileSync(langs, "utf8"));
return Object.keys(data).map((l) => l.replace("-", "_"));
return Object.keys(data);
}

// extract the plural form function
Expand Down Expand Up @@ -62,7 +62,7 @@ function pluralForm(statement) {
function buildFile(po_file) {
return new Promise((resolve, _reject) => {
const parsed = gettext_parser.po.parse(fs.readFileSync(po_file), "utf8");
const language = parsed.headers.Language;
const language = parsed.headers.Language.replace("_", "-");
// remove the second header copy
delete parsed.translations[""][""];

Expand Down Expand Up @@ -107,9 +107,9 @@ function buildFile(po_file) {

const supported = supportedLanguages();
const files = poFiles().filter((f) => {
const base = path.basename(f, ".po");
const base = path.basename(f, ".po").replace("_", "-");
// full match or language match
return supported.includes(base) || supported.some((s) => s.split("_")[0] === base);
return supported.includes(base) || supported.some((s) => s.split("-")[0] === base);
});

Promise.all(files.map((f) => buildFile(f)));
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("returns localized list", () => {
agama.language = "zh-CN";
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");
});
});
});
13 changes: 11 additions & 2 deletions web/src/agama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,17 @@ 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 {
const formatter = new Intl.ListFormat(agama.language, 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 list formatting function for language "${agama.language}", details:`,
e,
);
return list.join(", ");
}
},
};

Expand Down
3 changes: 1 addition & 2 deletions web/src/context/installerL10n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,9 @@ function reload(newLanguage: string) {
*/
async function loadTranslations(locale: string) {
// load the translations dynamically, first try the language + territory
const po = locale.replace("-", "_");
return import(
/* webpackChunkName: "[request]" */
`../po/po.${po}`
`../po/po.${locale}`
)
.then((m) => agama.locale(m.default))
.catch(async () => {
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