Skip to content

Commit

Permalink
Merge pull request #3982 from balena-io/i18n-sudo-en-fallback
Browse files Browse the repository at this point in the history
patch: fixed mac sudo on other languages
  • Loading branch information
balena-ci authored Jan 19, 2023
2 parents 407138c + 19d1e09 commit 1a368f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/gui/app/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ i18next.use(initReactI18next).init({
},
});

export const supportedLocales = ['en', 'zh'];

export default i18next;
9 changes: 8 additions & 1 deletion lib/shared/catalina-sudo/sudo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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',
Expand All @@ -43,7 +50,7 @@ export async function sudo(
SUDO_ASKPASS: join(
getAppPath(),
__dirname,
'sudo-askpass.osascript-' + lang + '.js',
`sudo-askpass.osascript-${lang}.js`,
),
},
},
Expand Down

0 comments on commit 1a368f5

Please sign in to comment.