提交 53ec5ac5 编写于 作者: R Ramya Achutha Rao

Support promptText for multiple languages

上级 852cfdaa
......@@ -10,6 +10,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IExtensionsViewlet } from 'vs/workbench/parts/extensions/common/extensions';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
import { language } from 'vs/base/common/platform';
export class ExperimentalPrompts extends Disposable implements IWorkbenchContribution {
private _disposables: IDisposable[] = [];
......@@ -50,7 +51,8 @@ export class ExperimentalPrompts extends Disposable implements IWorkbenchContrib
};
const actionProperties = (<IExperimentActionPromptProperties>experiment.action.properties);
if (!actionProperties || !actionProperties.promptText) {
const promptText = ExperimentalPrompts.getPromptText(actionProperties, language);
if (!actionProperties || !promptText) {
return;
}
if (!actionProperties.commands) {
......@@ -80,7 +82,7 @@ export class ExperimentalPrompts extends Disposable implements IWorkbenchContrib
};
});
this.notificationService.prompt(Severity.Info, actionProperties.promptText, choices, {
this.notificationService.prompt(Severity.Info, promptText, choices, {
onCancel: () => {
logTelemetry();
this.experimentService.markAsCompleted(experiment.id);
......@@ -91,4 +93,15 @@ export class ExperimentalPrompts extends Disposable implements IWorkbenchContrib
dispose() {
this._disposables = dispose(this._disposables);
}
static getPromptText(actionProperties: IExperimentActionPromptProperties, displayLanguage: string): string {
if (typeof actionProperties.promptText === 'string') {
return actionProperties.promptText;
}
displayLanguage = displayLanguage.toLowerCase();
if (!actionProperties.promptText[displayLanguage] && displayLanguage.indexOf('-') === 2) {
displayLanguage = displayLanguage.substr(0, 2);
}
return actionProperties.promptText[displayLanguage];
}
}
......@@ -76,7 +76,7 @@ export enum ExperimentActionType {
}
export interface IExperimentActionPromptProperties {
promptText: string;
promptText: string | { [key: string]: string };
commands: IExperimentActionPromptCommand[];
}
......
......@@ -5,7 +5,7 @@
import * as assert from 'assert';
import { IExperiment, ExperimentActionType, IExperimentService, ExperimentState } from 'vs/workbench/parts/experiments/node/experimentService';
import { IExperiment, ExperimentActionType, IExperimentService, ExperimentState, IExperimentActionPromptProperties } from 'vs/workbench/parts/experiments/node/experimentService';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { Emitter } from 'vs/base/common/event';
......@@ -157,4 +157,28 @@ suite('Experimental Prompts', () => {
});
});
test('Test getPromptText', () => {
const simpleTextCase: IExperimentActionPromptProperties = {
promptText: 'My simple prompt',
commands: []
};
const englishTextCase: IExperimentActionPromptProperties = {
promptText: {
en: 'My simple prompt for en'
},
commands: []
};
const englishUSTextCase: IExperimentActionPromptProperties = {
promptText: {
'en-us': 'My simple prompt for en'
},
commands: []
};
assert.equal(ExperimentalPrompts.getPromptText(simpleTextCase, 'any-language'), simpleTextCase.promptText);
assert.equal(ExperimentalPrompts.getPromptText(englishTextCase, 'en'), englishTextCase.promptText['en']);
assert.equal(ExperimentalPrompts.getPromptText(englishUSTextCase, 'en-us'), englishUSTextCase.promptText['en-us']);
assert.equal(ExperimentalPrompts.getPromptText(englishTextCase, 'en-au'), englishTextCase.promptText['en']);
assert.equal(!!ExperimentalPrompts.getPromptText(englishTextCase, 'de'), false);
});
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册