From 15311ad783da9896fa374d53e4c3ded5ff29c0c1 Mon Sep 17 00:00:00 2001 From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com> Date: Thu, 2 Feb 2023 09:22:11 -0800 Subject: [PATCH] Add more processing for ZH locales (#173167) Ref #172240 --- src/main.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main.js b/src/main.js index b4caa6616b1..99f828167b5 100644 --- a/src/main.js +++ b/src/main.js @@ -554,6 +554,26 @@ async function mkdirpIgnoreError(dir) { //#region NLS Support +function processZhLocale(appLocale) { + if (appLocale.startsWith('zh')) { + const region = appLocale.split('-')[1]; + // On Windows and macOS, Chinese languages returned by + // app.getPreferredSystemLanguages() start with zh-hans + // for Simplified Chinese or zh-hant for Traditional Chinese, + // so we can easily determine whether to use Simplified or Traditional. + // However, on Linux, Chinese languages returned by that same API + // are of the form zh-XY, where XY is a country code. + // For China (CN), Singapore (SG), and Malaysia (MY) + // country codes, assume they use Simplified Chinese. + // For other cases, assume they use Traditional. + if (['hans', 'cn', 'sg', 'my'].includes(region)) { + return 'zh-cn'; + } + return 'zh-tw'; + } + return appLocale; +} + /** * Resolve the NLS configuration * @@ -590,15 +610,8 @@ async function resolveNlsConfiguration() { if (!appLocale) { nlsConfiguration = { locale: 'en', availableLanguages: {} }; } else { - // See above the comment about the loader and case sensitiveness - appLocale = appLocale.toLowerCase(); - - if (appLocale.startsWith('zh-hans')) { - appLocale = 'zh-cn'; - } else if (appLocale.startsWith('zh-hant')) { - appLocale = 'zh-tw'; - } + appLocale = processZhLocale(appLocale.toLowerCase()); const { getNLSConfiguration } = require('./vs/base/node/languagePacks'); nlsConfiguration = await getNLSConfiguration(product.commit, userDataPath, metaDataFile, appLocale);