feat: add app.getPreferredSystemLanguages() API (#36035)
* feat: add app.getSystemLanguage() API * Change the API to getPreferredSystemLanguages * Fix test * Clarify docs and add Linux impl * Remove USE_GLIB * Don't add C to list * Remove examples since there's a lot of edge cases * Fix lint * Add examples * Fix compile error * Apply PR feedback * Update the example
This commit is contained in:
parent
8f5959aad2
commit
5fc3ed936e
6 changed files with 76 additions and 9 deletions
|
@ -375,6 +375,7 @@ describe('command line switches', () => {
|
|||
describe('--lang switch', () => {
|
||||
const currentLocale = app.getLocale();
|
||||
const currentSystemLocale = app.getSystemLocale();
|
||||
const currentPreferredLanguages = JSON.stringify(app.getPreferredSystemLanguages());
|
||||
const testLocale = async (locale: string, result: string, printEnv: boolean = false) => {
|
||||
const appPath = path.join(fixturesPath, 'api', 'locale-check');
|
||||
const args = [appPath, `--set-lang=${locale}`];
|
||||
|
@ -397,9 +398,9 @@ describe('command line switches', () => {
|
|||
expect(output).to.equal(result);
|
||||
};
|
||||
|
||||
it('should set the locale', async () => testLocale('fr', `fr|${currentSystemLocale}`));
|
||||
it('should set the locale with country code', async () => testLocale('zh-CN', `zh-CN|${currentSystemLocale}`));
|
||||
it('should not set an invalid locale', async () => testLocale('asdfkl', `${currentLocale}|${currentSystemLocale}`));
|
||||
it('should set the locale', async () => testLocale('fr', `fr|${currentSystemLocale}|${currentPreferredLanguages}`));
|
||||
it('should set the locale with country code', async () => testLocale('zh-CN', `zh-CN|${currentSystemLocale}|${currentPreferredLanguages}`));
|
||||
it('should not set an invalid locale', async () => testLocale('asdfkl', `${currentLocale}|${currentSystemLocale}|${currentPreferredLanguages}`));
|
||||
|
||||
const lcAll = String(process.env.LC_ALL);
|
||||
ifit(process.platform === 'linux')('current process has a valid LC_ALL env', async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue