From 7b6b6869e8f5b71b5e9cdbd3f590b10964f89607 Mon Sep 17 00:00:00 2001 From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com> Date: Tue, 21 Feb 2023 17:26:37 -0800 Subject: [PATCH] Add en as fallback osLocale (#175039) --- src/main.js | 8 +++++--- test/smoke/src/areas/workbench/localization.test.ts | 4 +--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.js b/src/main.js index d9305dfb168..d6f46dba013 100644 --- a/src/main.js +++ b/src/main.js @@ -103,10 +103,12 @@ let osLocale = undefined; // Ref https://github.com/microsoft/vscode/issues/159813 // and https://github.com/electron/electron/pull/36035 if ('getPreferredSystemLanguages' in app - && typeof app.getPreferredSystemLanguages === 'function' - && app.getPreferredSystemLanguages().length) { + && typeof app.getPreferredSystemLanguages === 'function') { // Use the most preferred OS language for language recommendation. - osLocale = app.getPreferredSystemLanguages()[0]; + // The API might return an empty array on Linux, such as when + // the 'C' locale is the user's only configured locale. + // No matter the OS, if the array is empty, default back to 'en'. + osLocale = app.getPreferredSystemLanguages()?.[0] ?? 'en'; if (osLocale) { osLocale = processZhLocale(osLocale.toLowerCase()); } diff --git a/test/smoke/src/areas/workbench/localization.test.ts b/test/smoke/src/areas/workbench/localization.test.ts index 65c60152622..15a71ff505c 100644 --- a/test/smoke/src/areas/workbench/localization.test.ts +++ b/test/smoke/src/areas/workbench/localization.test.ts @@ -8,9 +8,7 @@ import { installAllHandlers } from '../../utils'; export function setup(logger: Logger) { - // BUG: app.getPreferredSystemLanguages() doesn't seem to return anything here on Linux: https://github.com/microsoft/vscode/blob/3ba29f37d6b9f3f2257b48f2b90f0699ea581be4/src/main.js#L100-L113 - // but it should when we move to Electron 22 so we can re-enable this test then. - (process.platform === 'linux' ? describe.skip : describe)('Localization', () => { + describe('Localization', () => { // Shared before/after handling installAllHandlers(logger);