2
0
mirror of https://github.com/frappe/books.git synced 2024-11-14 09:24:04 +00:00

fix: imports and translations

This commit is contained in:
18alantom 2022-01-24 12:14:11 +05:30 committed by Alan
parent c3c72470dc
commit 7587c22e5b

View File

@ -1,6 +1,6 @@
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import frappe from 'frappejs'; import frappe, { t } from 'frappe';
import { MandatoryError, ValidationError } from 'frappejs/common/errors'; import { MandatoryError, ValidationError } from 'frappe/common/errors';
import { IPC_ACTIONS } from './messages'; import { IPC_ACTIONS } from './messages';
import { showMessageDialog, showToast } from './utils'; import { showMessageDialog, showToast } from './utils';
@ -17,13 +17,13 @@ function reportError(errorLogObj) {
function getToastProps(errorLogObj) { function getToastProps(errorLogObj) {
const props = { const props = {
message: _(`Error: `) + errorLogObj.name, message: t`Error: ` + errorLogObj.name,
type: 'error', type: 'error',
}; };
if (!frappe.SystemSettings.autoReportErrors) { if (!frappe.SystemSettings.autoReportErrors) {
Object.assign(props, { Object.assign(props, {
actionText: frappe._('Report Error'), actionText: t`Report Error`,
action: () => { action: () => {
reportError(errorLogObj); reportError(errorLogObj);
}, },
@ -54,16 +54,13 @@ export function handleError(shouldLog, error, more = {}) {
} }
export function getErrorMessage(e, doc) { export function getErrorMessage(e, doc) {
let errorMessage = e.message || _('An error occurred.'); let errorMessage = e.message || t`An error occurred.`;
const { doctype, name } = doc; const { doctype, name } = doc;
const canElaborate = doctype && name; const canElaborate = doctype && name;
if (e.type === frappe.errors.LinkValidationError && canElaborate) { if (e.type === frappe.errors.LinkValidationError && canElaborate) {
errorMessage = _('{0} {1} is linked with existing records.', [ errorMessage = t`${doctype} ${name} is linked with existing records.`;
doctype,
name,
]);
} else if (e.type === frappe.errors.DuplicateEntryError && canElaborate) { } else if (e.type === frappe.errors.DuplicateEntryError && canElaborate) {
errorMessage = _('{0} {1} already exists.', [doctype, name]); errorMessage = t`${doctype} ${name} already exists.`;
} }
return errorMessage; return errorMessage;
} }
@ -78,10 +75,8 @@ export function handleErrorWithDialog(error, doc = {}) {
export async function showErrorDialog({ title, content }) { export async function showErrorDialog({ title, content }) {
// To be used for show stopper errors // To be used for show stopper errors
title ??= frappe._('Error'); title ??= t`Error`;
content ??= frappe._( content ??= t`Something has gone terribly wrong. Please check the console and raise an issue.`;
'Something has gone terribly wrong. Please check the console and raise an issue.'
);
await ipcRenderer.invoke(IPC_ACTIONS.SHOW_ERROR, { title, content }); await ipcRenderer.invoke(IPC_ACTIONS.SHOW_ERROR, { title, content });
} }