From 6024dce39387dbfe6dec8d7251e2765c0c90b27a Mon Sep 17 00:00:00 2001 From: Ryan Miller Date: Fri, 16 Feb 2024 10:48:51 +1100 Subject: [PATCH] fix: add LocalizerKeys type to getMessage and remove updateLocale function --- ts/node/global_errors.ts | 10 ++-------- ts/util/i18n.ts | 3 ++- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/ts/node/global_errors.ts b/ts/node/global_errors.ts index b0d8713af..ef7c75eff 100644 --- a/ts/node/global_errors.ts +++ b/ts/node/global_errors.ts @@ -1,11 +1,10 @@ import { app, clipboard, dialog } from 'electron'; import { redactAll } from '../util/privacy'; // checked - only node -import { LocaleMessagesType } from './locale'; // checked - only node import { ConsoleCustom } from './logging'; // checked - only node // We use hard-coded strings until we're able to update these strings from the locale. -let quitText = 'Quit'; -let copyErrorAndQuitText = 'Copy error to clipboard'; +const quitText = 'Quit'; +const copyErrorAndQuitText = 'Copy error to clipboard'; async function handleError(prefix: string, error: any) { if ((console as ConsoleCustom)._error) { @@ -33,11 +32,6 @@ async function handleError(prefix: string, error: any) { } } -export const updateLocale = (messages: LocaleMessagesType) => { - quitText = messages.quit; - copyErrorAndQuitText = messages.copyErrorAndQuit; -}; - export const setupGlobalErrorHandler = () => { // eslint-disable-next-line @typescript-eslint/no-misused-promises process.on('uncaughtException', async error => { diff --git a/ts/util/i18n.ts b/ts/util/i18n.ts index 7701bc06d..732fb2580 100644 --- a/ts/util/i18n.ts +++ b/ts/util/i18n.ts @@ -1,6 +1,7 @@ // this file is a weird one as it is used by both sides of electron at the same time import { LocaleMessagesType } from '../node/locale'; +import { LocalizerKeys } from '../types/LocalizerKeys'; export const setupi18n = (locale: string, messages: LocaleMessagesType) => { if (!locale) { @@ -10,7 +11,7 @@ export const setupi18n = (locale: string, messages: LocaleMessagesType) => { throw new Error('i18n: messages parameter is required'); } - function getMessage(key: string, substitutions: Array) { + function getMessage(key: LocalizerKeys, substitutions: Array) { const message = messages[key]; if (!message) { // eslint:disable: no-console