Skip to content

Commit

Permalink
Fix message map translations (#7353)
Browse files Browse the repository at this point in the history
* Clean up message map usage

* msgMap -> messageMap

* Update changes
  • Loading branch information
Etheryte authored Aug 3, 2023
1 parent 42aeb6e commit 27f9d91
Show file tree
Hide file tree
Showing 23 changed files with 116 additions and 90 deletions.
11 changes: 4 additions & 7 deletions web/html/src/components/FormulaForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { Loading } from "./utils";

const capitalize = Utils.capitalize;

const defaultMessageTexts = {
pillar_only_formula_saved: <p>{t("Formula saved. Applying the highstate is not needed for this formula.")}</p>,
const defaultMessageMap = {
pillar_only_formula_saved: t("Formula saved. Applying the highstate is not needed for this formula."),
};

export enum SectionState {
Expand Down Expand Up @@ -204,11 +204,8 @@ class FormulaForm extends React.Component<Props, State> {
}
};

getMessageText = (msg) => {
if (!this.props.messageTexts[msg] && defaultMessageTexts[msg]) {
return defaultMessageTexts[msg];
}
return this.props.messageTexts[msg] ? this.props.messageTexts[msg] : msg;
getMessageText = (msg: string) => {
return this.props.messageTexts[msg] || defaultMessageMap[msg] || msg;
};

render() {
Expand Down
2 changes: 1 addition & 1 deletion web/html/src/components/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class Messages extends React.Component<Props> {

var msgs = items.map((item, index) => (
<div key={"msg" + index} className={"alert alert-" + _classNames[item.severity]}>
{Array.isArray(item.text) ? item.text.map((txt, i) => <div key={i}>{txt}</div>) : item.text}
{item.text}
</div>
));

Expand Down
6 changes: 4 additions & 2 deletions web/html/src/core/channels/api/use-mandatory-channels-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { MessageType } from "components/messages";
import { JsonResult } from "utils/network";
import Network from "utils/network";

const msgMap = {
const messageMap = {
base_not_found_or_not_authorized: t("Base channel not found or not authorized."),
child_not_found_or_not_authorized: t("Child channel not found or not authorized."),
invalid_channel_id: t("Invalid channel id"),
Expand Down Expand Up @@ -63,7 +63,9 @@ const useMandatoryChannelsApi = (): UseMandatoryChannelsApiReturnType => {
setRequiredByChannels(dependencies.requiredByChannels);
})
.catch((jqXHR: JQueryXHR, arg: string = "") => {
const msg = Network.responseErrorMessage(jqXHR, (status, msg) => (msgMap[msg] ? t(msgMap[msg], arg) : null));
const msg = Network.responseErrorMessage(jqXHR, (status, msg) =>
messageMap[msg] ? t(messageMap[msg], arg) : null
);
setMessages(messages.concat(msg));
})
.finally(() => setIsDependencyDataLoaded(true));
Expand Down
16 changes: 9 additions & 7 deletions web/html/src/manager/admin/config/monitoring-admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const { capitalize } = Utils;

const msgRestart = t("Restart is needed for the configuration changes to take effect.");

const msgMap = {
const messageMap = {
internal_error: t("An internal error has occurred. See the server logs for details."),
enabling_failed: t("Enabling monitoring failed. See the server logs for details."),
enabling_failed_partially: t(
Expand Down Expand Up @@ -78,7 +78,7 @@ const ExporterIcon = (props: {
? "item-enabled-pending"
: "item-enabled";
if (props.message) {
tooltip = t("Enabled") + ". " + msgMap[props.name + "_msg_" + props.message];
tooltip = t("Enabled") + ". " + messageMap[props.name + "_msg_" + props.message];
} else {
tooltip = t("Enabled");
}
Expand All @@ -88,7 +88,7 @@ const ExporterIcon = (props: {
? "item-error-pending"
: "item-error";
if (props.message) {
tooltip = t("Disabled") + ". " + msgMap[props.name + "_msg_" + props.message];
tooltip = t("Disabled") + ". " + messageMap[props.name + "_msg_" + props.message];
} else {
tooltip = t("Disabled");
}
Expand Down Expand Up @@ -192,7 +192,7 @@ const ExportersMessages = (props: {
.map((key) => (
<li key={key}>
<Icon type="system-warn" className="fa-1-5x" />
{msgMap[key + "_msg_" + props.messages[key]]}
{messageMap[key + "_msg_" + props.messages[key]]}
</li>
))}
</ul>
Expand All @@ -219,7 +219,9 @@ const MonitoringAdmin = (props: MonitoringAdminProps) => {
} = useMonitoringApi();

const handleResponseError = (jqXHR: JQueryXHR, arg: string = "") => {
const msg = Network.responseErrorMessage(jqXHR, (status, msg) => (msgMap[msg] ? t(msgMap[msg], arg) : null));
const msg = Network.responseErrorMessage(jqXHR, (status, msg) =>
messageMap[msg] ? t(messageMap[msg], arg) : null
);
setMessages(msg);
};

Expand All @@ -234,9 +236,9 @@ const MonitoringAdmin = (props: MonitoringAdminProps) => {
changeStatus(enable)
.then((result: any) => {
if (result.success) {
setMessages(MessagesUtils.success(msgMap[result.message]));
setMessages(MessagesUtils.success(messageMap[result.message]));
} else {
setMessages(MessagesUtils.error(result.message in msgMap ? msgMap[result.message] : result.message));
setMessages(MessagesUtils.error(result.message in messageMap ? messageMap[result.message] : result.message));
}
})
.catch(handleResponseError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Messages, MessageType } from "components/messages";

import Network from "utils/network";

const msgMap = {
const messageMap = {
// Nothing for now
};

Expand Down Expand Up @@ -136,7 +136,9 @@ class SCCDialog extends React.Component<Props> {
currentStep.inProgress = false;
currentStep.success = false;
}
const msg = Network.responseErrorMessage(jqXHR, (status, msg) => (msgMap[msg] ? t(msgMap[msg], arg) : null));
const msg = Network.responseErrorMessage(jqXHR, (status, msg) =>
messageMap[msg] ? t(messageMap[msg], arg) : null
);
this.setState({ steps: stepList, errors: this.state.errors.concat(msg) });
};

Expand Down
6 changes: 4 additions & 2 deletions web/html/src/manager/admin/setup/products/products.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ declare global {
}
}

const msgMap = {
const messageMap = {
// Nothing for now
};

Expand Down Expand Up @@ -281,7 +281,9 @@ class ProductsPageWrapper extends React.Component {
};

handleResponseError = (jqXHR: JQueryXHR, arg = "") => {
const msg = Network.responseErrorMessage(jqXHR, (status, msg) => (msgMap[msg] ? t(msgMap[msg], arg) : null));
const msg = Network.responseErrorMessage(jqXHR, (status, msg) =>
messageMap[msg] ? t(messageMap[msg], arg) : null
);
this.setState({ errors: this.state.errors.concat(msg) });
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ import Network from "utils/network";
const capitalize = Utils.capitalize;

export const renderer = (renderId, { groupId, warningMessage }) => {
const messageTexts = {
formulas_saved: (
<p>
{t("Formula saved. Edit configuration options in the enabled formulas and apply the ")}
<a href={"/rhn/manager/groups/details/highstate?sgid=" + groupId}>{t("Highstate")}</a>
{t(" for the changes to take effect.")}
</p>
const messageMap = {
formulas_saved: t(
"Formula saved. Edit configuration options in the enabled formulas and apply the <link>Highstate</link> for the changes to take effect.",
{
link: (str) => (
<a href={"/rhn/manager/groups/details/highstate?sgid=" + groupId} key="link">
{str}
</a>
),
}
),
error_invalid_target: t("Invalid target type."),
};

function getMessageText(msg) {
return messageTexts[msg] ? t(messageTexts[msg]) : msg;
function getMessageText(msg: string) {
return messageMap[msg] || msg;
}

function saveRequest(component, selectedFormulas) {
Expand Down
18 changes: 9 additions & 9 deletions web/html/src/manager/groups/formula/group-formula.renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { DEPRECATED_unsafeEquals } from "utils/legacy";
const capitalize = Utils.capitalize;

export const renderer = (renderId, { groupId, formulaId }) => {
const msgMap = {
formula_saved: (
<p>
{t("Formula saved. Apply the ")}
<a href={"/rhn/manager/groups/details/highstate?sgid=" + groupId}>{t("Highstate")}</a>
{t(" for the changes to take effect.")}
</p>
),
const messageMap = {
formula_saved: t("Formula saved. Apply the <link>Highstate</link> for the changes to take effect.", {
link: (str) => (
<a href={"/rhn/manager/groups/details/highstate?sgid=" + groupId} key="link">
{str}
</a>
),
}),
error_invalid_target: t("Invalid target type."),
};

Expand Down Expand Up @@ -53,7 +53,7 @@ export const renderer = (renderId, { groupId, formulaId }) => {
return "/rhn/manager/groups/details/formula/" + id + "?sgid=" + groupId;
}}
scope="group"
messageTexts={msgMap}
messageTexts={messageMap}
/>,
document.getElementById(renderId)
);
Expand Down
4 changes: 2 additions & 2 deletions web/html/src/manager/images/image-build.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const typeMap = {
kiwi: { name: "Kiwi", buildType: "osimage_build_host" },
};

const msgMap = {
const messageMap = {
unknown_error: t("An unknown error has occurred."),
build_scheduled: t("The image build has been scheduled."),
taskomatic_error: t(
Expand Down Expand Up @@ -222,7 +222,7 @@ class BuildImage extends React.Component<Props, State> {
messages: (
<Messages
items={data.messages.map((msg) => {
return { severity: "error", text: msgMap[msg] };
return { severity: "error", text: messageMap[msg] };
})}
/>
),
Expand Down
6 changes: 4 additions & 2 deletions web/html/src/manager/images/image-import.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { TopPanel } from "components/panels/TopPanel";
import { Utils } from "utils/functions";
import Network from "utils/network";

const msgMap = {
const messageMap = {
not_found: t("Image store not found"),
build_scheduled: t("The image import has been scheduled."),
taskomatic_error: t(
Expand Down Expand Up @@ -188,7 +188,9 @@ class ImageImport extends React.Component {
Utils.urlBounce("/rhn/manager/cm/images");
} else {
this.setState({
messages: MessagesUtils.error(msgMap[data.messages[0]] ? msgMap[data.messages[0]] : data.messages[0]),
messages: MessagesUtils.error(
messageMap[data.messages[0]] ? messageMap[data.messages[0]] : data.messages[0]
),
});
}
})
Expand Down
6 changes: 3 additions & 3 deletions web/html/src/manager/images/image-profile-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const typeMap = {
kiwi: { name: "Kiwi", storeType: "os_image" },
};

const msgMap = {
const messageMap = {
invalid_type: "Invalid image type.",
activation_key_required: "Please give an activation key",
"": "There was an error.",
Expand Down Expand Up @@ -200,7 +200,7 @@ class CreateImageProfile extends React.Component<Props, State> {
messages: (
<Messages
items={data.messages.map((msg) => {
return { severity: "error", text: msgMap[msg] };
return { severity: "error", text: messageMap[msg] };
})}
/>
),
Expand All @@ -226,7 +226,7 @@ class CreateImageProfile extends React.Component<Props, State> {
messages: (
<Messages
items={data.messages.map((msg) => {
return { severity: "error", text: msgMap[msg] };
return { severity: "error", text: messageMap[msg] };
})}
/>
),
Expand Down
6 changes: 3 additions & 3 deletions web/html/src/manager/images/image-profiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const typeMap = {
kiwi: t("Kiwi"),
};

const msgMap = {
const messageMap = {
not_found: t("Image profile cannot be found."),
delete_success: t("Image profile has been deleted."),
delete_success_p: t("Image profiles have been deleted."),
Expand Down Expand Up @@ -99,7 +99,7 @@ class ImageProfiles extends React.Component<Props, State> {
items={[
{
severity: "success",
text: msgMap[idList.length > 1 ? "delete_success_p" : "delete_success"],
text: messageMap[idList.length > 1 ? "delete_success_p" : "delete_success"],
},
]}
/>
Expand All @@ -112,7 +112,7 @@ class ImageProfiles extends React.Component<Props, State> {
messages: (
<Messages
items={data.messages.map((msg) => {
return { severity: "error", text: msgMap[msg] };
return { severity: "error", text: messageMap[msg] };
})}
/>
),
Expand Down
6 changes: 3 additions & 3 deletions web/html/src/manager/images/image-store-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const typeMap = {
os_image: "OS Image",
};

const msgMap = {
const messageMap = {
// Nothing for now
};

Expand Down Expand Up @@ -104,7 +104,7 @@ class CreateImageStore extends React.Component<Props, State> {
messages: (
<Messages
items={data.messages.map((msg) => {
return { severity: "error", text: msgMap[msg] };
return { severity: "error", text: messageMap[msg] };
})}
/>
),
Expand All @@ -128,7 +128,7 @@ class CreateImageStore extends React.Component<Props, State> {
messages: (
<Messages
items={data.messages.map((msg) => {
return { severity: "error", text: msgMap[msg] };
return { severity: "error", text: messageMap[msg] };
})}
/>
),
Expand Down
6 changes: 3 additions & 3 deletions web/html/src/manager/images/image-stores.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ declare global {
}
}

const msgMap = {
const messageMap = {
not_found: t("Image store cannot be found."),
delete_success: t("Image store has been deleted."),
delete_success_p: t("Image stores have been deleted."),
Expand Down Expand Up @@ -99,7 +99,7 @@ class ImageStores extends React.Component<Props, State> {
items={[
{
severity: "success",
text: msgMap[idList.length > 1 ? "delete_success_p" : "delete_success"],
text: messageMap[idList.length > 1 ? "delete_success_p" : "delete_success"],
},
]}
/>
Expand All @@ -112,7 +112,7 @@ class ImageStores extends React.Component<Props, State> {
messages: (
<Messages
items={data.messages.map((msg) => {
return { severity: "error", text: msgMap[msg] };
return { severity: "error", text: messageMap[msg] };
})}
/>
),
Expand Down
10 changes: 6 additions & 4 deletions web/html/src/manager/images/image-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ declare global {
}
}

const msgMap = {
const messageMap = {
not_found: "Image cannot be found.",
cluster_info_err:
"Cannot retrieve data from cluster '{arg}'. Please check the logs and make sure the cluster API is accessible.",
Expand Down Expand Up @@ -98,8 +98,8 @@ class ImageView extends React.Component<ImageViewProps, ImageViewState> {
const add = this.state.messages;

const getMsgObj = (msg) => {
if (typeof msgMap[msg] === "string") {
return { severity: severity, text: msgMap[msg] };
if (typeof messageMap[msg] === "string") {
return { severity: severity, text: messageMap[msg] };
} else {
return { severity: severity, text: msg };
}
Expand Down Expand Up @@ -152,7 +152,9 @@ class ImageView extends React.Component<ImageViewProps, ImageViewState> {
};

handleResponseError(jqXHR, arg = "") {
const msg = Network.responseErrorMessage(jqXHR, (status, msg) => (msgMap[msg] ? t(msgMap[msg], { arg }) : null));
const msg = Network.responseErrorMessage(jqXHR, (status, msg) =>
messageMap[msg] ? t(messageMap[msg], { arg }) : null
);
this.setState({ messages: this.state.messages.concat(msg) });
}

Expand Down
Loading

0 comments on commit 27f9d91

Please sign in to comment.