From 19d1e093fc2b1588492c9868f7604ee15ab3fd5b Mon Sep 17 00:00:00 2001 From: Peter Makra <6892971+mcraa@users.noreply.github.com> Date: Thu, 19 Jan 2023 11:56:44 +0100 Subject: [PATCH] patch: fixed mac sudo on other languages --- lib/gui/app/i18n.ts | 2 ++ lib/shared/catalina-sudo/sudo.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/gui/app/i18n.ts b/lib/gui/app/i18n.ts index 78ec6225ee..5809a6fe33 100644 --- a/lib/gui/app/i18n.ts +++ b/lib/gui/app/i18n.ts @@ -39,4 +39,6 @@ i18next.use(initReactI18next).init({ }, }); +export const supportedLocales = ['en', 'zh']; + export default i18next; diff --git a/lib/shared/catalina-sudo/sudo.ts b/lib/shared/catalina-sudo/sudo.ts index 3653e50a91..b4f03abbd1 100644 --- a/lib/shared/catalina-sudo/sudo.ts +++ b/lib/shared/catalina-sudo/sudo.ts @@ -20,6 +20,7 @@ import { env } from 'process'; import { promisify } from 'util'; import { getAppPath } from '../utils'; +import { supportedLocales } from '../../gui/app/i18n'; const execFileAsync = promisify(execFile); @@ -32,6 +33,12 @@ export async function sudo( try { let lang = Intl.DateTimeFormat().resolvedOptions().locale; lang = lang.substr(0, 2); + if (supportedLocales.indexOf(lang) > -1) { + // language should be present + } else { + // fallback to eng + lang = 'en'; + } const { stdout, stderr } = await execFileAsync( 'sudo', @@ -43,7 +50,7 @@ export async function sudo( SUDO_ASKPASS: join( getAppPath(), __dirname, - 'sudo-askpass.osascript-' + lang + '.js', + `sudo-askpass.osascript-${lang}.js`, ), }, },