Skip to content

Commit

Permalink
[Enhancement #505] Accept values map from the backend error for local…
Browse files Browse the repository at this point in the history
…ized message formatting.
  • Loading branch information
lukaskabc committed Sep 13, 2024
1 parent 133ca25 commit d79e364
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/component/audit/ErrorLogViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { GoTrashcan } from "react-icons/go";
import { useI18n } from "../hook/useI18n";

const ErrorLogViewer: React.FC = () => {
const { i18n, locale } = useI18n();
const { i18n, formatMessage, locale } = useI18n();
const errors = useSelector((state: TermItState) => state.errors);
const dispatch: ThunkDispatch = useDispatch();
const clear = () => {
Expand Down Expand Up @@ -43,9 +43,15 @@ const ErrorLogViewer: React.FC = () => {
{errors.map((item) => {
let error = item.error;
if (error.messageId) {
error = Object.assign({}, error, {
message: i18n(error.messageId),
});
if (error.values && Object.keys(error.values).length > 0) {
error = Object.assign({}, error, {
message: formatMessage(error.messageId, error.values),
});
} else {
error = Object.assign({}, error, {
message: i18n(error.messageId),
});
}
}
return (
<tr key={item.timestamp}>
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ const cs = {
"Excel obsahuje více pojmů se stejným identifikátorem.",
"error.vocabulary.import.excel.duplicateLabel":
"Excel obsahuje více pojmů se stejným názvem.",
"error.vocabulary.import.excel.labelWithDifferentIdentifierExists":
'Slovník již obsahuje pojem s názvem "{label}" s rozdílným identifikátorem než s jakým byl importován. Existující identifikátor: {existingUri}',

"history.label": "Historie změn",
"history.loading": "Načítám historii...",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,8 @@ const en = {
"The Excel file contains multiple terms with the same identifier.",
"error.vocabulary.import.excel.duplicateLabel":
"The Excel file contains multiple terms with the same label.",
"error.vocabulary.import.excel.labelWithDifferentIdentifierExists":
'Vocabulary already contains a term with label "{label}" with a different identifier than the imported one. Existing identifier: {existingUri}',

"history.label": "Change history",
"history.loading": "Loading history...",
Expand Down
5 changes: 4 additions & 1 deletion src/model/ErrorInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ export interface ErrorData {
requestUrl?: string;
messageId?: string;
message?: string;
/// values used for formatting localized message
values?: { [key: string]: string };
status?: number; // Response status
}

/**
* Represents error received from the server API.
*/
export default class ErrorInfo {
export default class ErrorInfo implements ErrorData {
public readonly origin: string;
public readonly requestUrl?: string;
public readonly messageId?: string;
public readonly message?: string;
public readonly status?: number;
public readonly values?: { [key: string]: string };

constructor(origin: string, data: ErrorData) {
this.origin = origin;
Expand Down

0 comments on commit d79e364

Please sign in to comment.