Skip to content

Commit

Permalink
Add more processing for ZH locales (#173167)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzhao271 authored Feb 2, 2023
1 parent c770729 commit 15311ad
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 15311ad

Please sign in to comment.