Adopt l10n for npm package (#165527)

For #164438
This commit is contained in:
Matt Bierner 2022-11-04 13:56:39 -07:00 committed by GitHub
parent ac26690ed8
commit 952bbb6720
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 31 additions and 50 deletions

View file

@ -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"
},

View file

@ -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 {
@ -13,7 +12,6 @@ import {
IFolderTaskItem
} from './tasks';
const localize = nls.loadMessageBundle();
export function runSelectedScript(context: vscode.ExtensionContext) {
const editor = vscode.window.activeTextEditor;
@ -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);
}
}

View file

@ -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';
@ -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);
@ -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 {
@ -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;

View file

@ -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;
@ -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);
@ -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 {
@ -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;
});
@ -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);
}
}
@ -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');

View file

@ -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',
@ -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 [

View file

@ -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,
@ -20,7 +19,6 @@ import {
ITaskWithLocation
} from './tasks';
const localize = nls.loadMessageBundle();
class Folder extends TreeItem {
packages: PackageJSON[] = [];
@ -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)];
}

View file

@ -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;
@ -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")
);
}
@ -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"),
'|'
);
}

View file

@ -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 {
@ -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;
@ -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);
}
}

View file

@ -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"