From 8a37410ce245986886108b036b6a8ed47cccf679 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 4 Nov 2022 12:04:47 -0700 Subject: [PATCH] Adopt l10n for extension-editing (#165523) For #164438 --- .../code-no-unexternalized-strings.ts | 8 ++++++++ extensions/extension-editing/package.json | 3 +-- .../extension-editing/src/extensionLinter.ts | 20 +++++++++---------- .../src/packageDocumentHelper.ts | 6 ++---- extensions/extension-editing/yarn.lock | 5 ----- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/.eslintplugin/code-no-unexternalized-strings.ts b/.eslintplugin/code-no-unexternalized-strings.ts index 0dc36ff800d..a4e6f83024a 100644 --- a/.eslintplugin/code-no-unexternalized-strings.ts +++ b/.eslintplugin/code-no-unexternalized-strings.ts @@ -138,8 +138,16 @@ export = new class NoUnexternalizedStrings implements eslint.Rule.RuleModule { return { ['Literal']: (node: any) => collectDoubleQuotedStrings(node), ['ExpressionStatement[directive] Literal:exit']: (node: any) => doubleQuotedStringLiterals.delete(node), + + // localize(...) ['CallExpression[callee.type="MemberExpression"][callee.object.name="nls"][callee.property.name="localize"]:exit']: (node: any) => visitLocalizeCall(node), + + // vscode.l10n.t(...) ['CallExpression[callee.type="MemberExpression"][callee.object.property.name="l10n"][callee.property.name="t"]:exit']: (node: any) => visitL10NCall(node), + + // l10n.t(...) + ['CallExpression[callee.object.name="l10n"][callee.property.name="t"]:exit']: (node: any) => visitL10NCall(node), + ['CallExpression[callee.name="localize"][arguments.length>=2]:exit']: (node: any) => visitLocalizeCall(node), ['Program:exit']: reportBadStringsAndBadKeys, }; diff --git a/extensions/extension-editing/package.json b/extensions/extension-editing/package.json index fb50d9163b4..f7ed1ccc164 100644 --- a/extensions/extension-editing/package.json +++ b/extensions/extension-editing/package.json @@ -28,8 +28,7 @@ "dependencies": { "jsonc-parser": "^2.2.1", "markdown-it": "^12.3.2", - "parse5": "^3.0.2", - "vscode-nls": "^5.2.0" + "parse5": "^3.0.2" }, "contributes": { "jsonValidation": [ diff --git a/extensions/extension-editing/src/extensionLinter.ts b/extensions/extension-editing/src/extensionLinter.ts index e1bda75fc04..b95aa7b9e06 100644 --- a/extensions/extension-editing/src/extensionLinter.ts +++ b/extensions/extension-editing/src/extensionLinter.ts @@ -6,13 +6,11 @@ import * as path from 'path'; import * as fs from 'fs'; import { URL } from 'url'; -import * as nls from 'vscode-nls'; -const localize = nls.loadMessageBundle(); import { parseTree, findNodeAtLocation, Node as JsonNode, getNodeValue } from 'jsonc-parser'; import * as MarkdownItType from 'markdown-it'; -import { languages, workspace, Disposable, TextDocument, Uri, Diagnostic, Range, DiagnosticSeverity, Position, env } from 'vscode'; +import { languages, workspace, Disposable, TextDocument, Uri, Diagnostic, Range, DiagnosticSeverity, Position, env, l10n } from 'vscode'; const product = JSON.parse(fs.readFileSync(path.join(env.appRoot, 'product.json'), { encoding: 'utf-8' })); const allowedBadgeProviders: string[] = (product.extensionAllowedBadgeProviders || []).map((s: string) => s.toLowerCase()); @@ -23,14 +21,14 @@ function isTrustedSVGSource(uri: Uri): boolean { return allowedBadgeProviders.includes(uri.authority.toLowerCase()) || allowedBadgeProvidersRegex.some(r => r.test(uri.toString())); } -const httpsRequired = localize('httpsRequired', "Images must use the HTTPS protocol."); -const svgsNotValid = localize('svgsNotValid', "SVGs are not a valid image source."); -const embeddedSvgsNotValid = localize('embeddedSvgsNotValid', "Embedded SVGs are not a valid image source."); -const dataUrlsNotValid = localize('dataUrlsNotValid', "Data URLs are not a valid image source."); -const relativeUrlRequiresHttpsRepository = localize('relativeUrlRequiresHttpsRepository', "Relative image URLs require a repository with HTTPS protocol to be specified in the package.json."); -const relativeIconUrlRequiresHttpsRepository = localize('relativeIconUrlRequiresHttpsRepository', "An icon requires a repository with HTTPS protocol to be specified in this package.json."); -const relativeBadgeUrlRequiresHttpsRepository = localize('relativeBadgeUrlRequiresHttpsRepository', "Relative badge URLs require a repository with HTTPS protocol to be specified in this package.json."); -const apiProposalNotListed = localize('apiProposalNotListed', "This proposal cannot be used because for this extension the product defines a fixed set of API proposals. You can test your extension but before publishing you MUST reach out to the VS Code team."); +const httpsRequired = l10n.t("Images must use the HTTPS protocol."); +const svgsNotValid = l10n.t("SVGs are not a valid image source."); +const embeddedSvgsNotValid = l10n.t("Embedded SVGs are not a valid image source."); +const dataUrlsNotValid = l10n.t("Data URLs are not a valid image source."); +const relativeUrlRequiresHttpsRepository = l10n.t("Relative image URLs require a repository with HTTPS protocol to be specified in the package.json."); +const relativeIconUrlRequiresHttpsRepository = l10n.t("An icon requires a repository with HTTPS protocol to be specified in this package.json."); +const relativeBadgeUrlRequiresHttpsRepository = l10n.t("Relative badge URLs require a repository with HTTPS protocol to be specified in this package.json."); +const apiProposalNotListed = l10n.t("This proposal cannot be used because for this extension the product defines a fixed set of API proposals. You can test your extension but before publishing you MUST reach out to the VS Code team."); enum Context { ICON, diff --git a/extensions/extension-editing/src/packageDocumentHelper.ts b/extensions/extension-editing/src/packageDocumentHelper.ts index 291075d7447..67163900b5b 100644 --- a/extensions/extension-editing/src/packageDocumentHelper.ts +++ b/extensions/extension-editing/src/packageDocumentHelper.ts @@ -5,9 +5,7 @@ import * as vscode from 'vscode'; import { getLocation, Location } from 'jsonc-parser'; -import * as nls from 'vscode-nls'; -const localize = nls.loadMessageBundle(); export class PackageDocument { @@ -40,8 +38,8 @@ export class PackageDocument { } return Promise.resolve([this.newSnippetCompletionItem({ - label: localize('languageSpecificEditorSettings', "Language specific editor settings"), - documentation: localize('languageSpecificEditorSettingsDescription', "Override editor settings for language"), + label: vscode.l10n.t("Language specific editor settings"), + documentation: vscode.l10n.t("Override editor settings for language"), snippet, range })]); diff --git a/extensions/extension-editing/yarn.lock b/extensions/extension-editing/yarn.lock index 2d5b4e2f835..1902937e894 100644 --- a/extensions/extension-editing/yarn.lock +++ b/extensions/extension-editing/yarn.lock @@ -66,8 +66,3 @@ uc.micro@^1.0.1, uc.micro@^1.0.5: version "1.0.6" resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac" integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA== - -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==