externalize strings

This commit is contained in:
Erich Gamma 2018-03-31 23:06:43 +02:00
parent 14ce79bb4e
commit 3d5f0b75af
4 changed files with 36 additions and 23 deletions

View file

@ -37,7 +37,7 @@
"explorer": [
{
"id": "npm",
"name": "npm scripts",
"name": "%view.name%",
"when": "config.npm.explorerVisible"
}
]
@ -45,19 +45,19 @@
"commands": [
{
"command": "npm.runScript",
"title": "Run"
"title": "%command.run%"
},
{
"command": "npm.debugScript",
"title": "Debug"
"title": "%command.debug%"
},
{
"command": "npm.openScript",
"title": "Open"
"title": "%command.openScript%"
},
{
"command": "npm.refresh",
"title": "Refresh",
"title": "%command.refresh%",
"icon": {
"light": "resources/light/refresh.svg",
"dark": "resources/dark/refresh.svg"
@ -142,7 +142,7 @@
"type": "boolean",
"default": true,
"scope": "resource",
"description": "Show the npm scripts explorer"
"description": "%config.npm.explorerVisible%"
}
}
},

View file

@ -5,7 +5,15 @@
"config.npm.runSilent": "Run npm commands with the `--silent` option.",
"config.npm.packageManager": "The package manager used to run scripts.",
"config.npm.exclude": "Configure glob patterns for folders that should be excluded from automatic script detection.",
"config.npm.explorerVisible": "Show the npm scripts explorer.",
"npm.parseError": "Npm task detection: failed to parse the file {0}",
"taskdef.script": "The npm script to customize.",
"taskdef.path": "The path to the folder of the package.json file that provides the script. Can be ommitted."
"taskdef.path": "The path to the folder of the package.json file that provides the script. Can be ommitted.",
"view.name": "npm scripts",
"command.refresh": "Refresh",
"command.run": "Run",
"command.debug": "Debug",
"command.openScript": "Open",
"npm.scriptInvalid": "Could not find the script '{0}'. Try to refresh the view.",
"npm.noDebugOptions": "Could not launch '{0}' for debugging, the script needs to include the node debug options: '--nolazy --inspect-brk=port', [learn more](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration-support-for-npm-and-other-tools).`"
}

View file

@ -17,20 +17,19 @@ import { provideNpmScripts } from './tasks';
let taskProvider: vscode.Disposable | undefined;
export function activate(context: vscode.ExtensionContext): void {
let provider: vscode.TaskProvider = {
provideTasks: () => {
return provideNpmScripts(localize);
},
resolveTask(_task: vscode.Task): vscode.Task | undefined {
return undefined;
}
};
taskProvider = vscode.workspace.registerTaskProvider('npm', provider);
vscode.window.registerTreeDataProvider('npm', new NpmScriptsTreeDataProvider(context, provider, localize));
if (!vscode.workspace.workspaceFolders) {
return;
if (vscode.workspace.workspaceFolders) {
let provider: vscode.TaskProvider = {
provideTasks: () => {
return provideNpmScripts(localize);
},
resolveTask(_task: vscode.Task): vscode.Task | undefined {
return undefined;
}
};
taskProvider = vscode.workspace.registerTaskProvider('npm', provider);
let treeDataProvider = vscode.window.registerTreeDataProvider('npm', new NpmScriptsTreeDataProvider(context, provider, localize));
context.subscriptions.push(treeDataProvider);
}
configureHttpRequest();

View file

@ -119,7 +119,7 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
let scripts = await getScripts(uri!, this.localize);
if (!await this.scriptIsValid(scripts, task)) {
window.showErrorMessage(`Could not find script '${task.name}'. Try to refresh the view.`);
this.scriptNotValid(task);
return;
}
workspace.executeTask(script.task);
@ -140,13 +140,14 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
let scripts = await getScripts(uri!, this.localize);
if (!await this.scriptIsValid(scripts, task)) {
window.showErrorMessage(`Could not find script '${task.name}'. Try to refresh the view.`);
this.scriptNotValid(task);
return;
}
let port = await this.extractPort(scripts, task);
if (!port) {
window.showErrorMessage(`Could not launch '${task.name}' for debugging, the script needs to include the node debug options: '--nolazy --inspect-brk=port', [learn more](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration-support-for-npm-and-other-tools).`);
let message = this.localize('npm.noDebugOptions', 'Could not launch "{0}" for debugging, the script needs to include the node debug options: "--nolazy --inspect-brk=port", [learn more](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration-support-for-npm-and-other-tools).', task.name);
window.showErrorMessage(message);
return;
}
@ -168,6 +169,11 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
}
}
private scriptNotValid(task: Task) {
let message = this.localize('npm.scriptInvalid', 'Could not find the script "{0}". Try to refresh the view.', task.name);
window.showErrorMessage(message);
}
private async openScript(selection: PackageJSON | NpmScript) {
let uri: Uri | undefined = undefined;
if (selection instanceof PackageJSON) {