Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt l10n for npm package #165527

Merged
merged 4 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions extensions/grunt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
"compile": "gulp compile-extension:grunt",
"watch": "gulp watch-extension:grunt"
},
"dependencies": {
"vscode-nls": "^5.2.0"
},
"dependencies": {},
"devDependencies": {
"@types/node": "16.x"
},
Expand Down
8 changes: 3 additions & 5 deletions extensions/grunt/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import * as path from 'path';
import * as fs from 'fs';
import * as cp from 'child_process';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();

type AutoDetect = 'on' | 'off';

Expand Down Expand Up @@ -60,8 +58,8 @@ function getOutputChannel(): vscode.OutputChannel {
}

function showError() {
vscode.window.showWarningMessage(localize('gruntTaskDetectError', 'Problem finding grunt tasks. See the output for more information.'),
localize('gruntShowOutput', 'Go to output')).then(() => {
vscode.window.showWarningMessage(vscode.l10n.t("Problem finding grunt tasks. See the output for more information."),
vscode.l10n.t("Go to output")).then(() => {
getOutputChannel().show(true);
});
}
Expand Down Expand Up @@ -215,7 +213,7 @@ class FolderDetector {
if (err.stdout) {
channel.appendLine(err.stdout);
}
channel.appendLine(localize('execFailed', 'Auto detecting Grunt for folder {0} failed with error: {1}', this.workspaceFolder.name, err.error ? err.error.toString() : 'unknown'));
channel.appendLine(vscode.l10n.t("Auto detecting Grunt for folder {0} failed with error: {1}', this.workspaceFolder.name, err.error ? err.error.toString() : 'unknown"));
showError();
return emptyTasks;
}
Expand Down
5 changes: 0 additions & 5 deletions extensions/grunt/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,3 @@
version "16.11.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.6.tgz#6bef7a2a0ad684cf6e90fcfe31cecabd9ce0a3ae"
integrity sha512-ua7PgUoeQFjmWPcoo9khiPum3Pd60k4/2ZGXt18sm2Slk0W0xZTqt5Y0Ny1NyBiN1EVQ/+FaF9NcY4Qe6rwk5w==

vscode-nls@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-5.2.0.tgz#3cb6893dd9bd695244d8a024bdf746eea665cc3f"
integrity sha512-RAaHx7B14ZU04EU31pT+rKz2/zSl7xMsfIZuo8pd+KZO6PXtQmpevpq3vxvWNcrGbdmhM/rr5Uw5Mz+NBfhVng==
1 change: 0 additions & 1 deletion extensions/npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"jsonc-parser": "^2.2.1",
"minimatch": "^3.0.4",
"request-light": "^0.5.7",
"vscode-nls": "^5.2.0",
"which": "^2.0.2",
"which-pm": "^2.0.0"
},
Expand Down
4 changes: 1 addition & 3 deletions extensions/npm/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as nls from 'vscode-nls';
import * as vscode from 'vscode';

import {
Expand All @@ -13,7 +12,6 @@ import {
IFolderTaskItem
} from './tasks';

const localize = nls.loadMessageBundle();

export function runSelectedScript(context: vscode.ExtensionContext) {
const editor = vscode.window.activeTextEditor;
Expand All @@ -26,7 +24,7 @@ export function runSelectedScript(context: vscode.ExtensionContext) {
if (script) {
runScript(context, script, document);
} else {
const message = localize('noScriptFound', 'Could not find a valid npm script at the selection.');
const message = vscode.l10n.t("Could not find a valid npm script at the selection.");
vscode.window.showErrorMessage(message);
}
}
Expand Down
12 changes: 5 additions & 7 deletions extensions/npm/src/features/bowerJSONContribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

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

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

const USER_AGENT = 'Visual Studio Code';

Expand Down Expand Up @@ -46,7 +44,7 @@ export class BowerJSONContribution implements IJSONContribution {
'main': '${5:pathToMain}',
'dependencies': {}
};
const proposal = new CompletionItem(localize('json.bower.default', 'Default bower.json'));
const proposal = new CompletionItem(l10n.t("Default bower.json"));
proposal.kind = CompletionItemKind.Class;
proposal.insertText = new SnippetString(JSON.stringify(defaultValue, null, '\t'));
collector.add(proposal);
Expand Down Expand Up @@ -93,12 +91,12 @@ export class BowerJSONContribution implements IJSONContribution {
// ignore
}
} else {
collector.error(localize('json.bower.error.repoaccess', 'Request to the bower repository failed: {0}', success.responseText));
collector.error(l10n.t("Request to the bower repository failed: {0}", success.responseText));
return 0;
}
return undefined;
}, (error) => {
collector.error(localize('json.bower.error.repoaccess', 'Request to the bower repository failed: {0}', error.responseText));
collector.error(l10n.t("Request to the bower repository failed: {0}", error.responseText));
return 0;
});
} else {
Expand Down Expand Up @@ -131,7 +129,7 @@ export class BowerJSONContribution implements IJSONContribution {
}
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']))) {
// not implemented. Could be do done calling the bower command. Waiting for web API: https://github.com/bower/registry/issues/26
const proposal = new CompletionItem(localize('json.bower.latest.version', 'latest'));
const proposal = new CompletionItem(l10n.t("latest"));
proposal.insertText = new SnippetString('"${1:latest}"');
proposal.filterText = '""';
proposal.kind = CompletionItemKind.Value;
Expand Down
20 changes: 9 additions & 11 deletions extensions/npm/src/features/packageJSONContribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

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

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

const LIMIT = 40;

Expand Down Expand Up @@ -44,7 +42,7 @@ export class PackageJSONContribution implements IJSONContribution {
'main': '${5:pathToMain}',
'dependencies': {}
};
const proposal = new CompletionItem(localize('json.package.default', 'Default package.json'));
const proposal = new CompletionItem(l10n.t("Default package.json"));
proposal.kind = CompletionItemKind.Module;
proposal.insertText = new SnippetString(JSON.stringify(defaultValue, null, '\t'));
result.add(proposal);
Expand Down Expand Up @@ -113,12 +111,12 @@ export class PackageJSONContribution implements IJSONContribution {
}
collector.setAsIncomplete();
} else {
collector.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', success.responseText));
collector.error(l10n.t("Request to the NPM repository failed: {0}", success.responseText));
return 0;
}
return undefined;
}, (error) => {
collector.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', error.responseText));
collector.error(l10n.t("Request to the NPM repository failed: {0}", error.responseText));
return 0;
});
} else {
Expand Down Expand Up @@ -172,7 +170,7 @@ export class PackageJSONContribution implements IJSONContribution {
}
collector.setAsIncomplete();
} else {
collector.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', success.responseText));
collector.error(l10n.t("Request to the NPM repository failed: {0}", success.responseText));
}
return null;
});
Expand All @@ -195,21 +193,21 @@ export class PackageJSONContribution implements IJSONContribution {
let proposal = new CompletionItem(name);
proposal.kind = CompletionItemKind.Property;
proposal.insertText = name;
proposal.documentation = localize('json.npm.latestversion', 'The currently latest version of the package');
proposal.documentation = l10n.t("The currently latest version of the package");
result.add(proposal);

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

name = JSON.stringify('~' + info.version);
proposal = new CompletionItem(name);
proposal.kind = CompletionItemKind.Property;
proposal.insertText = name;
proposal.documentation = localize('json.npm.minorversion', 'Matches the most recent minor version (1.2.x)');
proposal.documentation = l10n.t("Matches the most recent minor version (1.2.x)");
result.add(proposal);
}
}
Expand All @@ -224,7 +222,7 @@ export class PackageJSONContribution implements IJSONContribution {
}
if (version) {
str.appendText('\n\n');
str.appendText(localize('json.npm.version.hover', 'Latest version: {0}', version));
str.appendText(l10n.t("Latest version: {0}", version));
}
if (homepage) {
str.appendText('\n\n');
Expand Down
7 changes: 3 additions & 4 deletions extensions/npm/src/npmScriptLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import {
languages,
TextDocument,
Uri,
workspace
workspace,
l10n
} from 'vscode';
import * as nls from 'vscode-nls';
import { findPreferredPM } from './preferred-pm';
import { readScripts } from './readScripts';

const localize = nls.loadMessageBundle();

const enum Constants {
ConfigKey = 'debug.javascript.codelens.npmScripts',
Expand Down Expand Up @@ -71,7 +70,7 @@ export class NpmScriptLensProvider implements CodeLensProvider, Disposable {
return [];
}

const title = '$(debug-start) ' + localize('codelens.debug', 'Debug');
const title = '$(debug-start) ' + l10n.t("Debug");
const cwd = path.dirname(document.uri.fsPath);
if (this.lensLocation === 'top') {
return [
Expand Down
8 changes: 3 additions & 5 deletions extensions/npm/src/npmView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import {
Range,
Selection, Task,
TaskGroup, tasks, TextDocument, TextDocumentShowOptions, ThemeIcon, TreeDataProvider, TreeItem, TreeItemLabel, TreeItemCollapsibleState, Uri,
window, workspace, WorkspaceFolder, Position, Location
window, workspace, WorkspaceFolder, Position, Location, l10n
} from 'vscode';
import * as nls from 'vscode-nls';
import { readScripts } from './readScripts';
import {
createTask, getPackageManager, getTaskName, isAutoDetectionEnabled, isWorkspaceFolder, INpmTaskDefinition,
Expand All @@ -20,7 +19,6 @@ import {
ITaskWithLocation
} from './tasks';

const localize = nls.loadMessageBundle();

class Folder extends TreeItem {
packages: PackageJSON[] = [];
Expand Down Expand Up @@ -231,9 +229,9 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
const taskTree = this.buildTaskTree(taskItems);
this.taskTree = this.sortTaskTree(taskTree);
if (this.taskTree.length === 0) {
let message = localize('noScripts', 'No scripts found.');
let message = l10n.t("No scripts found.");
if (!isAutoDetectionEnabled()) {
message = localize('autoDetectIsOff', 'The setting "npm.autoDetect" is "off".');
message = l10n.t('The setting "npm.autoDetect" is "off".');
}
this.taskTree = [new NoScripts(message)];
}
Expand Down
12 changes: 5 additions & 7 deletions extensions/npm/src/scriptHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
import { dirname } from 'path';
import {
CancellationToken, commands, ExtensionContext,
Hover, HoverProvider, MarkdownString, Position, ProviderResult,
Hover, HoverProvider, MarkdownString, l10n, Position, ProviderResult,
tasks, TextDocument,
Uri, workspace
} from 'vscode';
import * as nls from 'vscode-nls';
import { INpmScriptInfo, readScripts } from './readScripts';
import {
createTask,
getPackageManager, startDebugging
} from './tasks';

const localize = nls.loadMessageBundle();

let cachedDocument: Uri | undefined = undefined;
let cachedScripts: INpmScriptInfo | undefined = undefined;
Expand Down Expand Up @@ -81,10 +79,10 @@ export class NpmScriptHoverProvider implements HoverProvider {
script: script,
};
return this.createMarkdownLink(
localize('runScript', 'Run Script'),
l10n.t("Run Script"),
'npm.runScriptFromHover',
args,
localize('runScript.tooltip', 'Run the script as a task')
l10n.t("Run the script as a task")
);
}

Expand All @@ -94,10 +92,10 @@ export class NpmScriptHoverProvider implements HoverProvider {
script: script,
};
return this.createMarkdownLink(
localize('debugScript', 'Debug Script'),
l10n.t("Debug Script"),
'npm.debugScriptFromHover',
args,
localize('debugScript.tooltip', 'Runs the script under the debugger'),
l10n.t("Runs the script under the debugger"),
'|'
);
}
Expand Down
12 changes: 5 additions & 7 deletions extensions/npm/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
import {
TaskDefinition, Task, TaskGroup, WorkspaceFolder, RelativePattern, ShellExecution, Uri, workspace,
TaskProvider, TextDocument, tasks, TaskScope, QuickPickItem, window, Position, ExtensionContext, env,
ShellQuotedString, ShellQuoting, commands, Location, CancellationTokenSource
ShellQuotedString, ShellQuoting, commands, Location, CancellationTokenSource, l10n
} from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import * as minimatch from 'minimatch';
import * as nls from 'vscode-nls';
import { Utils } from 'vscode-uri';
import { findPreferredPM } from './preferred-pm';
import { readScripts } from './readScripts';

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

export interface INpmTaskDefinition extends TaskDefinition {
Expand Down Expand Up @@ -136,9 +134,9 @@ export async function getPackageManager(extensionContext: ExtensionContext, fold
packageManagerName = name;
const neverShowWarning = 'npm.multiplePMWarning.neverShow';
if (showWarning && multiplePMDetected && !extensionContext.globalState.get<boolean>(neverShowWarning)) {
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);
const neverShowAgain = localize('npm.multiplePMWarning.doNotShow', "Do not show again");
const learnMore = localize('npm.multiplePMWarning.learnMore', "Learn more");
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);
const neverShowAgain = l10n.t("Do not show again");
const learnMore = l10n.t("Learn more");
window.showInformationMessage(multiplePMWarning, learnMore, neverShowAgain).then(result => {
switch (result) {
case neverShowAgain: extensionContext.globalState.update(neverShowWarning, true); break;
Expand Down Expand Up @@ -447,7 +445,7 @@ export async function getScripts(packageJsonUri: Uri) {
const document: TextDocument = await workspace.openTextDocument(packageJsonUri);
return readScripts(document);
} catch (e) {
const localizedParseError = localize('npm.parseError', 'Npm task detection: failed to parse the file {0}', packageJsonUri.fsPath);
const localizedParseError = l10n.t("Npm task detection: failed to parse the file {0}", packageJsonUri.fsPath);
throw new Error(localizedParseError);
}
}
5 changes: 0 additions & 5 deletions extensions/npm/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,6 @@ to-regex-range@^5.0.1:
dependencies:
is-number "^7.0.0"

vscode-nls@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-5.2.0.tgz#3cb6893dd9bd695244d8a024bdf746eea665cc3f"
integrity sha512-RAaHx7B14ZU04EU31pT+rKz2/zSl7xMsfIZuo8pd+KZO6PXtQmpevpq3vxvWNcrGbdmhM/rr5Uw5Mz+NBfhVng==

which-pm@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/which-pm/-/which-pm-2.0.0.tgz#8245609ecfe64bf751d0eef2f376d83bf1ddb7ae"
Expand Down