Skip to content

Commit 952bbb6

Browse files
authored
Adopt l10n for npm package (microsoft#165527)
For microsoft#164438
1 parent ac26690 commit 952bbb6

File tree

9 files changed

+31
-50
lines changed

9 files changed

+31
-50
lines changed

extensions/npm/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"jsonc-parser": "^2.2.1",
2323
"minimatch": "^3.0.4",
2424
"request-light": "^0.5.7",
25-
"vscode-nls": "^5.2.0",
2625
"which": "^2.0.2",
2726
"which-pm": "^2.0.0"
2827
},

extensions/npm/src/commands.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as nls from 'vscode-nls';
76
import * as vscode from 'vscode';
87

98
import {
@@ -13,7 +12,6 @@ import {
1312
IFolderTaskItem
1413
} from './tasks';
1514

16-
const localize = nls.loadMessageBundle();
1715

1816
export function runSelectedScript(context: vscode.ExtensionContext) {
1917
const editor = vscode.window.activeTextEditor;
@@ -26,7 +24,7 @@ export function runSelectedScript(context: vscode.ExtensionContext) {
2624
if (script) {
2725
runScript(context, script, document);
2826
} else {
29-
const message = localize('noScriptFound', 'Could not find a valid npm script at the selection.');
27+
const message = vscode.l10n.t("Could not find a valid npm script at the selection.");
3028
vscode.window.showErrorMessage(message);
3129
}
3230
}

extensions/npm/src/features/bowerJSONContribution.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { MarkdownString, CompletionItemKind, CompletionItem, DocumentSelector, SnippetString, workspace, Uri } from 'vscode';
6+
import { MarkdownString, CompletionItemKind, CompletionItem, DocumentSelector, SnippetString, workspace, Uri, l10n } from 'vscode';
77
import { IJSONContribution, ISuggestionsCollector } from './jsonContributions';
88
import { XHRRequest } from 'request-light';
99
import { Location } from 'jsonc-parser';
1010

11-
import * as nls from 'vscode-nls';
12-
const localize = nls.loadMessageBundle();
1311

1412
const USER_AGENT = 'Visual Studio Code';
1513

@@ -46,7 +44,7 @@ export class BowerJSONContribution implements IJSONContribution {
4644
'main': '${5:pathToMain}',
4745
'dependencies': {}
4846
};
49-
const proposal = new CompletionItem(localize('json.bower.default', 'Default bower.json'));
47+
const proposal = new CompletionItem(l10n.t("Default bower.json"));
5048
proposal.kind = CompletionItemKind.Class;
5149
proposal.insertText = new SnippetString(JSON.stringify(defaultValue, null, '\t'));
5250
collector.add(proposal);
@@ -93,12 +91,12 @@ export class BowerJSONContribution implements IJSONContribution {
9391
// ignore
9492
}
9593
} else {
96-
collector.error(localize('json.bower.error.repoaccess', 'Request to the bower repository failed: {0}', success.responseText));
94+
collector.error(l10n.t("Request to the bower repository failed: {0}", success.responseText));
9795
return 0;
9896
}
9997
return undefined;
10098
}, (error) => {
101-
collector.error(localize('json.bower.error.repoaccess', 'Request to the bower repository failed: {0}', error.responseText));
99+
collector.error(l10n.t("Request to the bower repository failed: {0}", error.responseText));
102100
return 0;
103101
});
104102
} else {
@@ -131,7 +129,7 @@ export class BowerJSONContribution implements IJSONContribution {
131129
}
132130
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']))) {
133131
// not implemented. Could be do done calling the bower command. Waiting for web API: https://github.com/bower/registry/issues/26
134-
const proposal = new CompletionItem(localize('json.bower.latest.version', 'latest'));
132+
const proposal = new CompletionItem(l10n.t("latest"));
135133
proposal.insertText = new SnippetString('"${1:latest}"');
136134
proposal.filterText = '""';
137135
proposal.kind = CompletionItemKind.Value;

extensions/npm/src/features/packageJSONContribution.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { CompletionItemKind, CompletionItem, DocumentSelector, SnippetString, workspace, MarkdownString, Uri } from 'vscode';
6+
import { CompletionItemKind, CompletionItem, DocumentSelector, SnippetString, workspace, MarkdownString, Uri, l10n } from 'vscode';
77
import { IJSONContribution, ISuggestionsCollector } from './jsonContributions';
88
import { XHRRequest } from 'request-light';
99
import { Location } from 'jsonc-parser';
1010

1111
import * as cp from 'child_process';
12-
import * as nls from 'vscode-nls';
1312
import { dirname } from 'path';
14-
const localize = nls.loadMessageBundle();
1513

1614
const LIMIT = 40;
1715

@@ -44,7 +42,7 @@ export class PackageJSONContribution implements IJSONContribution {
4442
'main': '${5:pathToMain}',
4543
'dependencies': {}
4644
};
47-
const proposal = new CompletionItem(localize('json.package.default', 'Default package.json'));
45+
const proposal = new CompletionItem(l10n.t("Default package.json"));
4846
proposal.kind = CompletionItemKind.Module;
4947
proposal.insertText = new SnippetString(JSON.stringify(defaultValue, null, '\t'));
5048
result.add(proposal);
@@ -113,12 +111,12 @@ export class PackageJSONContribution implements IJSONContribution {
113111
}
114112
collector.setAsIncomplete();
115113
} else {
116-
collector.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', success.responseText));
114+
collector.error(l10n.t("Request to the NPM repository failed: {0}", success.responseText));
117115
return 0;
118116
}
119117
return undefined;
120118
}, (error) => {
121-
collector.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', error.responseText));
119+
collector.error(l10n.t("Request to the NPM repository failed: {0}", error.responseText));
122120
return 0;
123121
});
124122
} else {
@@ -172,7 +170,7 @@ export class PackageJSONContribution implements IJSONContribution {
172170
}
173171
collector.setAsIncomplete();
174172
} else {
175-
collector.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', success.responseText));
173+
collector.error(l10n.t("Request to the NPM repository failed: {0}", success.responseText));
176174
}
177175
return null;
178176
});
@@ -195,21 +193,21 @@ export class PackageJSONContribution implements IJSONContribution {
195193
let proposal = new CompletionItem(name);
196194
proposal.kind = CompletionItemKind.Property;
197195
proposal.insertText = name;
198-
proposal.documentation = localize('json.npm.latestversion', 'The currently latest version of the package');
196+
proposal.documentation = l10n.t("The currently latest version of the package");
199197
result.add(proposal);
200198

201199
name = JSON.stringify('^' + info.version);
202200
proposal = new CompletionItem(name);
203201
proposal.kind = CompletionItemKind.Property;
204202
proposal.insertText = name;
205-
proposal.documentation = localize('json.npm.majorversion', 'Matches the most recent major version (1.x.x)');
203+
proposal.documentation = l10n.t("Matches the most recent major version (1.x.x)");
206204
result.add(proposal);
207205

208206
name = JSON.stringify('~' + info.version);
209207
proposal = new CompletionItem(name);
210208
proposal.kind = CompletionItemKind.Property;
211209
proposal.insertText = name;
212-
proposal.documentation = localize('json.npm.minorversion', 'Matches the most recent minor version (1.2.x)');
210+
proposal.documentation = l10n.t("Matches the most recent minor version (1.2.x)");
213211
result.add(proposal);
214212
}
215213
}
@@ -224,7 +222,7 @@ export class PackageJSONContribution implements IJSONContribution {
224222
}
225223
if (version) {
226224
str.appendText('\n\n');
227-
str.appendText(localize('json.npm.version.hover', 'Latest version: {0}', version));
225+
str.appendText(l10n.t("Latest version: {0}", version));
228226
}
229227
if (homepage) {
230228
str.appendText('\n\n');

extensions/npm/src/npmScriptLens.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ import {
1212
languages,
1313
TextDocument,
1414
Uri,
15-
workspace
15+
workspace,
16+
l10n
1617
} from 'vscode';
17-
import * as nls from 'vscode-nls';
1818
import { findPreferredPM } from './preferred-pm';
1919
import { readScripts } from './readScripts';
2020

21-
const localize = nls.loadMessageBundle();
2221

2322
const enum Constants {
2423
ConfigKey = 'debug.javascript.codelens.npmScripts',
@@ -71,7 +70,7 @@ export class NpmScriptLensProvider implements CodeLensProvider, Disposable {
7170
return [];
7271
}
7372

74-
const title = '$(debug-start) ' + localize('codelens.debug', 'Debug');
73+
const title = '$(debug-start) ' + l10n.t("Debug");
7574
const cwd = path.dirname(document.uri.fsPath);
7675
if (this.lensLocation === 'top') {
7776
return [

extensions/npm/src/npmView.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import {
99
Range,
1010
Selection, Task,
1111
TaskGroup, tasks, TextDocument, TextDocumentShowOptions, ThemeIcon, TreeDataProvider, TreeItem, TreeItemLabel, TreeItemCollapsibleState, Uri,
12-
window, workspace, WorkspaceFolder, Position, Location
12+
window, workspace, WorkspaceFolder, Position, Location, l10n
1313
} from 'vscode';
14-
import * as nls from 'vscode-nls';
1514
import { readScripts } from './readScripts';
1615
import {
1716
createTask, getPackageManager, getTaskName, isAutoDetectionEnabled, isWorkspaceFolder, INpmTaskDefinition,
@@ -20,7 +19,6 @@ import {
2019
ITaskWithLocation
2120
} from './tasks';
2221

23-
const localize = nls.loadMessageBundle();
2422

2523
class Folder extends TreeItem {
2624
packages: PackageJSON[] = [];
@@ -231,9 +229,9 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
231229
const taskTree = this.buildTaskTree(taskItems);
232230
this.taskTree = this.sortTaskTree(taskTree);
233231
if (this.taskTree.length === 0) {
234-
let message = localize('noScripts', 'No scripts found.');
232+
let message = l10n.t("No scripts found.");
235233
if (!isAutoDetectionEnabled()) {
236-
message = localize('autoDetectIsOff', 'The setting "npm.autoDetect" is "off".');
234+
message = l10n.t('The setting "npm.autoDetect" is "off".');
237235
}
238236
this.taskTree = [new NoScripts(message)];
239237
}

extensions/npm/src/scriptHover.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@
66
import { dirname } from 'path';
77
import {
88
CancellationToken, commands, ExtensionContext,
9-
Hover, HoverProvider, MarkdownString, Position, ProviderResult,
9+
Hover, HoverProvider, MarkdownString, l10n, Position, ProviderResult,
1010
tasks, TextDocument,
1111
Uri, workspace
1212
} from 'vscode';
13-
import * as nls from 'vscode-nls';
1413
import { INpmScriptInfo, readScripts } from './readScripts';
1514
import {
1615
createTask,
1716
getPackageManager, startDebugging
1817
} from './tasks';
1918

20-
const localize = nls.loadMessageBundle();
2119

2220
let cachedDocument: Uri | undefined = undefined;
2321
let cachedScripts: INpmScriptInfo | undefined = undefined;
@@ -81,10 +79,10 @@ export class NpmScriptHoverProvider implements HoverProvider {
8179
script: script,
8280
};
8381
return this.createMarkdownLink(
84-
localize('runScript', 'Run Script'),
82+
l10n.t("Run Script"),
8583
'npm.runScriptFromHover',
8684
args,
87-
localize('runScript.tooltip', 'Run the script as a task')
85+
l10n.t("Run the script as a task")
8886
);
8987
}
9088

@@ -94,10 +92,10 @@ export class NpmScriptHoverProvider implements HoverProvider {
9492
script: script,
9593
};
9694
return this.createMarkdownLink(
97-
localize('debugScript', 'Debug Script'),
95+
l10n.t("Debug Script"),
9896
'npm.debugScriptFromHover',
9997
args,
100-
localize('debugScript.tooltip', 'Runs the script under the debugger'),
98+
l10n.t("Runs the script under the debugger"),
10199
'|'
102100
);
103101
}

extensions/npm/src/tasks.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@
66
import {
77
TaskDefinition, Task, TaskGroup, WorkspaceFolder, RelativePattern, ShellExecution, Uri, workspace,
88
TaskProvider, TextDocument, tasks, TaskScope, QuickPickItem, window, Position, ExtensionContext, env,
9-
ShellQuotedString, ShellQuoting, commands, Location, CancellationTokenSource
9+
ShellQuotedString, ShellQuoting, commands, Location, CancellationTokenSource, l10n
1010
} from 'vscode';
1111
import * as path from 'path';
1212
import * as fs from 'fs';
1313
import * as minimatch from 'minimatch';
14-
import * as nls from 'vscode-nls';
1514
import { Utils } from 'vscode-uri';
1615
import { findPreferredPM } from './preferred-pm';
1716
import { readScripts } from './readScripts';
1817

19-
const localize = nls.loadMessageBundle();
2018
const excludeRegex = new RegExp('^(node_modules|.vscode-test)$', 'i');
2119

2220
export interface INpmTaskDefinition extends TaskDefinition {
@@ -136,9 +134,9 @@ export async function getPackageManager(extensionContext: ExtensionContext, fold
136134
packageManagerName = name;
137135
const neverShowWarning = 'npm.multiplePMWarning.neverShow';
138136
if (showWarning && multiplePMDetected && !extensionContext.globalState.get<boolean>(neverShowWarning)) {
139-
const multiplePMWarning = localize('npm.multiplePMWarning', 'Using {0} as the preferred package manager. Found multiple lockfiles for {1}. To resolve this issue, delete the lockfiles that don\'t match your preferred package manager or change the setting "npm.packageManager" to a value other than "auto".', packageManagerName, folder.fsPath);
140-
const neverShowAgain = localize('npm.multiplePMWarning.doNotShow', "Do not show again");
141-
const learnMore = localize('npm.multiplePMWarning.learnMore', "Learn more");
137+
const multiplePMWarning = l10n.t('Using {0} as the preferred package manager. Found multiple lockfiles for {1}. To resolve this issue, delete the lockfiles that don\'t match your preferred package manager or change the setting "npm.packageManager" to a value other than "auto".', packageManagerName, folder.fsPath);
138+
const neverShowAgain = l10n.t("Do not show again");
139+
const learnMore = l10n.t("Learn more");
142140
window.showInformationMessage(multiplePMWarning, learnMore, neverShowAgain).then(result => {
143141
switch (result) {
144142
case neverShowAgain: extensionContext.globalState.update(neverShowWarning, true); break;
@@ -447,7 +445,7 @@ export async function getScripts(packageJsonUri: Uri) {
447445
const document: TextDocument = await workspace.openTextDocument(packageJsonUri);
448446
return readScripts(document);
449447
} catch (e) {
450-
const localizedParseError = localize('npm.parseError', 'Npm task detection: failed to parse the file {0}', packageJsonUri.fsPath);
448+
const localizedParseError = l10n.t("Npm task detection: failed to parse the file {0}", packageJsonUri.fsPath);
451449
throw new Error(localizedParseError);
452450
}
453451
}

extensions/npm/yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,6 @@ to-regex-range@^5.0.1:
192192
dependencies:
193193
is-number "^7.0.0"
194194

195-
vscode-nls@^5.2.0:
196-
version "5.2.0"
197-
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-5.2.0.tgz#3cb6893dd9bd695244d8a024bdf746eea665cc3f"
198-
integrity sha512-RAaHx7B14ZU04EU31pT+rKz2/zSl7xMsfIZuo8pd+KZO6PXtQmpevpq3vxvWNcrGbdmhM/rr5Uw5Mz+NBfhVng==
199-
200195
which-pm@^2.0.0:
201196
version "2.0.0"
202197
resolved "https://registry.yarnpkg.com/which-pm/-/which-pm-2.0.0.tgz#8245609ecfe64bf751d0eef2f376d83bf1ddb7ae"

0 commit comments

Comments
 (0)