提交 56920f14 编写于 作者: D Dirk Baeumer

Fixes #4305: Provide API to access the locale and ui language

上级 91f2bd1c
......@@ -12,15 +12,24 @@ let _isLinux = false;
let _isNative = false;
let _isWeb = false;
let _isQunit = false;
let _locale = undefined;
let _language = undefined;
interface NLSConfig {
locale: string;
availableLanguages: { [key: string]: string; };
}
interface INodeProcess {
platform: string;
env: { [key: string]: string; };
}
declare let process: INodeProcess;
declare let global: any;
interface INavigator {
userAgent:string;
userAgent: string;
language: string;
}
declare let navigator: INavigator;
declare let self: any;
......@@ -30,6 +39,17 @@ if (typeof process === 'object') {
_isWindows = (process.platform === 'win32');
_isMacintosh = (process.platform === 'darwin');
_isLinux = (process.platform === 'linux');
let vscode_nls_config = process.env['VSCODE_NLS_CONFIG'];
if (vscode_nls_config) {
try {
let nlsConfig:NLSConfig = JSON.parse(vscode_nls_config);
let resolved = nlsConfig.availableLanguages['*'];
_locale = nlsConfig.locale;
// VSCode's default language is 'en'
_language = resolved ? resolved : 'en';
} catch (e) {
}
}
_isNative = true;
} else if (typeof navigator === 'object') {
let userAgent = navigator.userAgent;
......@@ -37,7 +57,8 @@ if (typeof process === 'object') {
_isMacintosh = userAgent.indexOf('Macintosh') >= 0;
_isLinux = userAgent.indexOf('Linux') >= 0;
_isWeb = true;
_locale = navigator.language;
_language = _locale;
_isQunit = !!(<any>self).QUnit;
}
......@@ -67,6 +88,16 @@ export const isWeb = _isWeb;
export const isQunit = _isQunit;
export const platform = _platform;
/**
* The language used for the user interface.
*/
export const language = _language;
/**
* The OS locale or the locale specified by --locale
*/
export const locale = _locale;
export interface TimeoutToken {
}
......
......@@ -85,8 +85,6 @@ export interface IConfiguration {
}
export interface IEnvironment {
language: string;
appName: string;
appRoot: string;
isBuilt: boolean;
......
......@@ -6,6 +6,7 @@
import {Emitter} from 'vs/base/common/event';
import {score} from 'vs/editor/common/modes/languageSelector';
import * as Platform from 'vs/base/common/platform';
import {regExpLeadsToEndlessLoop} from 'vs/base/common/strings';
import {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
import * as errors from 'vs/base/common/errors';
......@@ -152,7 +153,7 @@ export class ExtHostAPIImplementation {
this.env = Object.freeze({
get machineId() { return telemetryInfo.machineId; },
get sessionId() { return telemetryInfo.sessionId; },
get language() { return contextService.getConfiguration().env.language; }
get language() { return Platform.language; }
});
telemetryService.getTelemetryInfo().then(info => telemetryInfo = info, errors.onUnexpectedError);
......
......@@ -50,16 +50,6 @@ export function startup(environment: IMainEnvironment, globalSettings: IGlobalSe
env: environment
};
// Inherit navigator language
let language = navigator.language;
try {
var config = process.env['VSCODE_NLS_CONFIG'];
if (config) {
language = JSON.parse(config).locale;
}
} catch (e) {
}
environment.language = language;
// Shell Options
let filesToOpen = environment.filesToOpen && environment.filesToOpen.length ? toInputs(environment.filesToOpen) : null;
......
......@@ -591,18 +591,11 @@ export class VSCodeMenu {
env.product.reportIssueUrl ? new MenuItem({ label: mnemonicLabel(nls.localize('miReportIssues', "Report &&Issues")), click: () => openUrl(env.product.reportIssueUrl, 'openReportIssues') }) : null,
(env.product.twitterUrl || env.product.requestFeatureUrl || env.product.reportIssueUrl) ? __separator__() : null,
env.product.licenseUrl ? new MenuItem({ label: mnemonicLabel(nls.localize('miLicense', "&&View License")), click: () => {
let nlsConfig = process.env['VSCODE_NLS_CONFIG'];
if (nlsConfig) {
try {
let languages = JSON.parse(nlsConfig).availableLanguages;
if (languages && languages['*']) {
openUrl(`${env.product.licenseUrl}?lang=${languages['*']}`, 'openLicenseUrl');
return;
}
} catch (e) {
}
}
if (platform.language) {
openUrl(`${env.product.licenseUrl}?lang=${platform.language}`, 'openLicenseUrl');
} else {
openUrl(env.product.licenseUrl, 'openLicenseUrl');
}
}}) : null,
env.product.privacyStatementUrl ? new MenuItem({ label: mnemonicLabel(nls.localize('miPrivacyStatement', "&&Privacy Statement")), click: () => openUrl(env.product.privacyStatementUrl, 'openPrivacyStatement') }) : null,
(env.product.licenseUrl || env.product.privacyStatementUrl) ? __separator__() : null,
......
......@@ -6,6 +6,7 @@
'use strict';
import * as nls from 'vs/nls';
import * as Platform from 'vs/base/common/platform';
import pfs = require('vs/base/node/pfs');
import {IExtensionDescription, IMessage} from 'vs/platform/extensions/common/extensions';
import Severity from 'vs/base/common/severity';
......@@ -24,18 +25,10 @@ interface NlsConfiguration {
locale: string;
pseudo: boolean;
}
const nlsConfig = function(): NlsConfiguration {
if (process.env['VSCODE_NLS_CONFIG']) {
try {
return JSON.parse(process.env['VSCODE_NLS_CONFIG']);
} catch (err) {
return {
locale: undefined,
pseudo: false
};
}
}
}();
const nlsConfig: NlsConfiguration = {
locale: Platform.locale,
pseudo: Platform.locale === 'pseudo'
};
export class MessagesCollector {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册