-
Notifications
You must be signed in to change notification settings - Fork 29.4k
/
remoteLanguagePacks.ts
39 lines (33 loc) · 1.62 KB
/
remoteLanguagePacks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { FileAccess } from '../../base/common/network.js';
import { join } from '../../base/common/path.js';
import type { INLSConfiguration } from '../../nls.js';
import { resolveNLSConfiguration } from '../../base/node/nls.js';
import { Promises } from '../../base/node/pfs.js';
import product from '../../platform/product/common/product.js';
const nlsMetadataPath = join(FileAccess.asFileUri('').fsPath);
const defaultMessagesFile = join(nlsMetadataPath, 'nls.messages.json');
const nlsConfigurationCache = new Map<string, Promise<INLSConfiguration>>();
export async function getNLSConfiguration(language: string, userDataPath: string): Promise<INLSConfiguration> {
if (!product.commit || !(await Promises.exists(defaultMessagesFile))) {
return {
userLocale: 'en',
osLocale: 'en',
resolvedLanguage: 'en',
defaultMessagesFile,
// NLS: below 2 are a relic from old times only used by vscode-nls and deprecated
locale: 'en',
availableLanguages: {}
};
}
const cacheKey = `${language}||${userDataPath}`;
let result = nlsConfigurationCache.get(cacheKey);
if (!result) {
result = resolveNLSConfiguration({ userLocale: language, osLocale: language, commit: product.commit, userDataPath, nlsMetadataPath });
nlsConfigurationCache.set(cacheKey, result);
}
return result;
}