Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webui: adding PRETTY_NAME to use in title instead of anaconda generic title #4830

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 7 additions & 3 deletions ui/webui/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import { PayloadsClient } from "../apis/payloads";

import { readBuildstamp, getIsFinal } from "../helpers/betanag.js";
import { readConf } from "../helpers/conf.js";

const _ = cockpit.gettext;
import { getOsReleaseByKey } from "../helpers/product.js";

export const Application = () => {
const [address, setAddress] = useState();
Expand All @@ -46,6 +45,7 @@ export const Application = () => {
const [notifications, setNotifications] = useState({});
const [isHelpExpanded, setIsHelpExpanded] = useState(false);
const [helpContent, setHelpContent] = useState("");
const [prettyName, setPrettyName] = useState("");

useEffect(() => {
cockpit.file("/run/anaconda/bus.address").watch(address => {
Expand All @@ -69,6 +69,10 @@ export const Application = () => {
buildstamp => setBeta(!getIsFinal(buildstamp)),
ex => console.error("Failed to parse anaconda buildstamp file")
);

getOsReleaseByKey("PRETTY_NAME").then(
setPrettyName
);
}, []);

const onAddNotification = (notificationProps) => {
Expand All @@ -95,7 +99,7 @@ export const Application = () => {
}
console.info("conf: ", conf);

const title = _("Anaconda installer");
const title = cockpit.format("$0 installation", prettyName);

const page = (
<Page
Expand Down
12 changes: 10 additions & 2 deletions ui/webui/src/components/localization/InstallationLanguage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with This program; If not, see <http://www.gnu.org/licenses/>.
*/

import React from "react";
import React, { useEffect, useState } from "react";
import cockpit from "cockpit";

import {
Expand Down Expand Up @@ -53,6 +53,7 @@ import {
setLangCookie
} from "../../helpers/language.js";
import { AnacondaPage } from "../AnacondaPage.jsx";
import { getOsReleaseByKey } from "../../helpers/product.js";

import "./InstallationLanguage.scss";

Expand Down Expand Up @@ -317,9 +318,16 @@ LanguageSelector.contextType = AddressContext;
export const InstallationLanguage = ({ idPrefix, setIsFormValid, onAddErrorNotification }) => {
const [nativeName, setNativeName] = React.useState(false);
const { setLanguage } = React.useContext(LanguageContext);
const [distributionName, setDistributionName] = useState("");

useEffect(() => {
getOsReleaseByKey("NAME").then(
setDistributionName
);
}, []);

return (
<AnacondaPage title={_("Welcome to the Anaconda installer")}>
<AnacondaPage title={cockpit.format("Welcome to $0", distributionName)}>
<Title
headingLevel="h3"
>
Expand Down
33 changes: 33 additions & 0 deletions ui/webui/src/helpers/product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2023 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with This program; If not, see <http://www.gnu.org/licenses/>.
*/
import cockpit from "cockpit";

export const getOsReleaseByKey = (key) => {
const confFile = cockpit.file("/etc/os-release");
console.log(confFile);

return confFile
.read()
.then((content) =>
content
.split(/\r?\n/)
?.find((item) => item?.includes(key))
.split("=")[1]
.replace(/['"]+/g, "")
)
.finally(confFile.close);
};
7 changes: 3 additions & 4 deletions ui/webui/test/check-language
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TestLanguage(anacondalib.VirtInstallMachineCase):

# Expect the backend set language to be preselected and the WebUI translated
l.check_selected_locale("de_DE")
b.wait_in_text("h1", "Anaconda-Installationsprogramm")
b.wait_in_text("h2 + h3", "Wählen Sie eine Sprache aus")

def testLanguageSwitching(self):
b = self.browser
Expand All @@ -53,7 +53,7 @@ class TestLanguage(anacondalib.VirtInstallMachineCase):
i.open()

# Expect the default language - this is en at this point - adjust the test when better guess is implemented
b.wait_in_text("h2", "Welcome to the Anaconda installer")
b.wait_in_text("h2", "Welcome to Fedora Linux")

l.check_selected_locale("en_US")

Expand Down Expand Up @@ -93,8 +93,7 @@ class TestLanguage(anacondalib.VirtInstallMachineCase):
wait_animations=False,
)

# TODO: Add checks for translations when these are present
b.wait_in_text("h1", "Anaconda-Installationsprogramm")
b.wait_in_text("h2 + h3", "Wählen Sie eine Sprache aus")
# TODO: Add checks for plural translations when these are present

# Check that the language is updated in the backend
Expand Down