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 ts extension #165450

Merged
merged 1 commit 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
22 changes: 22 additions & 0 deletions .eslintplugin/code-no-unexternalized-strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ export = new class NoUnexternalizedStrings implements eslint.Rule.RuleModule {
}
}

function visitL10NCall(node: TSESTree.CallExpression) {

// localize(key, message)
const [messageNode] = (<TSESTree.CallExpression>node).arguments;

// remove message-argument from doubleQuoted list and make
// sure it is a string-literal
if (isStringLiteral(messageNode)) {
doubleQuotedStringLiterals.delete(messageNode);
} else if (messageNode.type === AST_NODE_TYPES.ObjectExpression) {
for (const prop of messageNode.properties) {
if (prop.type === AST_NODE_TYPES.Property) {
if (prop.key.type === AST_NODE_TYPES.Identifier && prop.key.name === 'message') {
doubleQuotedStringLiterals.delete(prop.value);
break;
}
}
}
}
}

function reportBadStringsAndBadKeys() {
// (1)
// report all strings that are in double quotes
Expand Down Expand Up @@ -118,6 +139,7 @@ export = new class NoUnexternalizedStrings implements eslint.Rule.RuleModule {
['Literal']: (node: any) => collectDoubleQuotedStrings(node),
['ExpressionStatement[directive] Literal:exit']: (node: any) => doubleQuotedStringLiterals.delete(node),
['CallExpression[callee.type="MemberExpression"][callee.object.name="nls"][callee.property.name="localize"]:exit']: (node: any) => visitLocalizeCall(node),
['CallExpression[callee.type="MemberExpression"][callee.object.property.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,
};
Expand Down
1 change: 0 additions & 1 deletion extensions/typescript-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"@vscode/extension-telemetry": "0.6.2",
"jsonc-parser": "^2.2.1",
"semver": "5.5.1",
"vscode-nls": "^5.2.0",
"vscode-tas-client": "^0.1.63",
"vscode-uri": "^3.0.3"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import type * as Proto from '../../protocol';
import { CachedResponse } from '../../tsServer/cachedResponse';
import { ITypeScriptServiceClient } from '../../typescriptService';
import { escapeRegExp } from '../../utils/regexp';
import * as typeConverters from '../../utils/typeConverters';

const localize = nls.loadMessageBundle();

export class ReferencesCodeLens extends vscode.CodeLens {
constructor(
Expand All @@ -32,7 +30,7 @@ export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensP
};

public static readonly errorCommand: vscode.Command = {
title: localize('referenceErrorLabel', 'Could not determine references'),
title: vscode.l10n.t("Could not determine references"),
command: ''
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import type * as Proto from '../../protocol';
import * as PConst from '../../protocol.const';
import { CachedResponse } from '../../tsServer/cachedResponse';
Expand All @@ -15,7 +14,6 @@ import { LanguageDescription } from '../../utils/languageDescription';
import * as typeConverters from '../../utils/typeConverters';
import { getSymbolRange, ReferencesCodeLens, TypeScriptBaseCodeLensProvider } from './baseCodeLensProvider';

const localize = nls.loadMessageBundle();

export default class TypeScriptImplementationsCodeLensProvider extends TypeScriptBaseCodeLensProvider {

Expand Down Expand Up @@ -61,8 +59,8 @@ export default class TypeScriptImplementationsCodeLensProvider extends TypeScrip

private getTitle(locations: vscode.Location[]): string {
return locations.length === 1
? localize('oneImplementationLabel', '1 implementation')
: localize('manyImplementationLabel', '{0} implementations', locations.length);
? vscode.l10n.t("1 implementation")
: vscode.l10n.t("{0} implementations", locations.length);
}

protected extractSymbol(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import type * as Proto from '../../protocol';
import * as PConst from '../../protocol.const';
import { CachedResponse } from '../../tsServer/cachedResponse';
Expand All @@ -16,7 +15,6 @@ import { LanguageDescription } from '../../utils/languageDescription';
import * as typeConverters from '../../utils/typeConverters';
import { getSymbolRange, ReferencesCodeLens, TypeScriptBaseCodeLensProvider } from './baseCodeLensProvider';

const localize = nls.loadMessageBundle();

export class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLensProvider {
public constructor(
Expand Down Expand Up @@ -56,8 +54,8 @@ export class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLens

private getCodeLensLabel(locations: ReadonlyArray<vscode.Location>): string {
return locations.length === 1
? localize('oneReferenceLabel', '1 reference')
: localize('manyReferenceLabel', '{0} references', locations.length);
? vscode.l10n.t("1 reference")
: vscode.l10n.t("{0} references", locations.length);
}

protected extractSymbol(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { Command, CommandManager } from '../commands/commandManager';
import type * as Proto from '../protocol';
import * as PConst from '../protocol.const';
Expand All @@ -23,7 +22,6 @@ import * as typeConverters from '../utils/typeConverters';
import TypingsStatus from '../utils/typingsStatus';
import FileConfigurationManager from './fileConfigurationManager';

const localize = nls.loadMessageBundle();

interface DotAccessorContext {
readonly range: vscode.Range;
Expand Down Expand Up @@ -622,7 +620,7 @@ class ApplyCompletionCodeActionCommand implements Command {
description: '',
action,
})), {
placeHolder: localize('selectCodeAction', 'Select code action to apply')
placeHolder: vscode.l10n.t("Select code action to apply")
});

if (selection) {
Expand Down Expand Up @@ -692,12 +690,14 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider<

if (this.typingsStatus.isAcquiringTypings) {
return Promise.reject<vscode.CompletionList<MyCompletionItem>>({
label: localize(
{ key: 'acquiringTypingsLabel', comment: ['Typings refers to the *.d.ts typings files that power our IntelliSense. It should not be localized'] },
'Acquiring typings...'),
detail: localize(
{ key: 'acquiringTypingsDetail', comment: ['Typings refers to the *.d.ts typings files that power our IntelliSense. It should not be localized'] },
'Acquiring typings definitions for IntelliSense.')
label: vscode.l10n.t({
message: "Acquiring typings...",
comment: ['Typings refers to the *.d.ts typings files that power our IntelliSense. It should not be localized'],
}),
detail: vscode.l10n.t({
message: "Acquiring typings definitions for IntelliSense.",
comment: ['Typings refers to the *.d.ts typings files that power our IntelliSense. It should not be localized'],
})
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { ITypeScriptServiceClient } from '../typescriptService';
import API from '../utils/api';
import { DocumentSelector } from '../utils/documentSelector';

const localize = nls.loadMessageBundle();

interface Directive {
readonly value: string;
Expand All @@ -19,29 +17,21 @@ interface Directive {
const tsDirectives: Directive[] = [
{
value: '@ts-check',
description: localize(
'ts-check',
"Enables semantic checking in a JavaScript file. Must be at the top of a file.")
description: vscode.l10n.t("Enables semantic checking in a JavaScript file. Must be at the top of a file.")
}, {
value: '@ts-nocheck',
description: localize(
'ts-nocheck',
"Disables semantic checking in a JavaScript file. Must be at the top of a file.")
description: vscode.l10n.t("Disables semantic checking in a JavaScript file. Must be at the top of a file.")
}, {
value: '@ts-ignore',
description: localize(
'ts-ignore',
"Suppresses @ts-check errors on the next line of a file.")
description: vscode.l10n.t("Suppresses @ts-check errors on the next line of a file.")
}
];

const tsDirectives390: Directive[] = [
...tsDirectives,
{
value: '@ts-expect-error',
description: localize(
'ts-expect-error',
"Suppresses @ts-check errors on the next line of a file, expecting at least one to exist.")
description: vscode.l10n.t("Suppresses @ts-check errors on the next line of a file, expecting at least one to exist.")
}
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { Command, CommandManager } from '../commands/commandManager';
import { ITypeScriptServiceClient } from '../typescriptService';
import API from '../utils/api';
import { isSupportedLanguageMode } from '../utils/languageIds';
import * as typeConverters from '../utils/typeConverters';

const localize = nls.loadMessageBundle();

class FileReferencesCommand implements Command {

Expand All @@ -26,31 +24,31 @@ class FileReferencesCommand implements Command {

public async execute(resource?: vscode.Uri) {
if (this.client.apiVersion.lt(FileReferencesCommand.minVersion)) {
vscode.window.showErrorMessage(localize('error.unsupportedVersion', "Find file references failed. Requires TypeScript 4.2+."));
vscode.window.showErrorMessage(vscode.l10n.t("Find file references failed. Requires TypeScript 4.2+."));
return;
}

resource ??= vscode.window.activeTextEditor?.document.uri;
if (!resource) {
vscode.window.showErrorMessage(localize('error.noResource', "Find file references failed. No resource provided."));
vscode.window.showErrorMessage(vscode.l10n.t("Find file references failed. No resource provided."));
return;
}

const document = await vscode.workspace.openTextDocument(resource);
if (!isSupportedLanguageMode(document)) {
vscode.window.showErrorMessage(localize('error.unsupportedLanguage', "Find file references failed. Unsupported file type."));
vscode.window.showErrorMessage(vscode.l10n.t("Find file references failed. Unsupported file type."));
return;
}

const openedFiledPath = this.client.toOpenedFilePath(document);
if (!openedFiledPath) {
vscode.window.showErrorMessage(localize('error.unknownFile', "Find file references failed. Unknown file type."));
vscode.window.showErrorMessage(vscode.l10n.t("Find file references failed. Unknown file type."));
return;
}

await vscode.window.withProgress({
location: vscode.ProgressLocation.Window,
title: localize('progress.title', "Finding file references")
title: vscode.l10n.t("Finding file references")
}, async (_progress, token) => {

const response = await this.client.execute('fileReferences', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import type * as Proto from '../protocol';
import { ClientCapability, ITypeScriptServiceClient } from '../typescriptService';
import API from '../utils/api';
Expand All @@ -16,7 +15,6 @@ import * as typeConverters from '../utils/typeConverters';
import { DiagnosticsManager } from './diagnostics';
import FileConfigurationManager from './fileConfigurationManager';

const localize = nls.loadMessageBundle();

interface AutoFix {
readonly codes: Set<number>;
Expand Down Expand Up @@ -133,7 +131,7 @@ class SourceFixAll extends SourceAction {
static readonly kind = vscode.CodeActionKind.SourceFixAll.append('ts');

constructor() {
super(localize('autoFix.label', 'Fix all fixable JS/TS issues'), SourceFixAll.kind);
super(vscode.l10n.t("Fix all fixable JS/TS issues"), SourceFixAll.kind);
}

async build(client: ITypeScriptServiceClient, file: string, diagnostics: readonly vscode.Diagnostic[], token: vscode.CancellationToken): Promise<void> {
Expand All @@ -155,7 +153,7 @@ class SourceRemoveUnused extends SourceAction {
static readonly kind = vscode.CodeActionKind.Source.append('removeUnused').append('ts');

constructor() {
super(localize('autoFix.unused.label', 'Remove all unused code'), SourceRemoveUnused.kind);
super(vscode.l10n.t("Remove all unused code"), SourceRemoveUnused.kind);
}

async build(client: ITypeScriptServiceClient, file: string, diagnostics: readonly vscode.Diagnostic[], token: vscode.CancellationToken): Promise<void> {
Expand All @@ -171,7 +169,7 @@ class SourceAddMissingImports extends SourceAction {
static readonly kind = vscode.CodeActionKind.Source.append('addMissingImports').append('ts');

constructor() {
super(localize('autoFix.missingImports.label', 'Add all missing imports'), SourceAddMissingImports.kind);
super(vscode.l10n.t("Add all missing imports"), SourceAddMissingImports.kind);
}

async build(client: ITypeScriptServiceClient, file: string, diagnostics: readonly vscode.Diagnostic[], token: vscode.CancellationToken): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import type * as Proto from '../protocol';
import { ClientCapability, ITypeScriptServiceClient, ServerType } from '../typescriptService';
import { conditionalRegistration, requireSomeCapability } from '../utils/dependentRegistration';
Expand All @@ -13,7 +12,6 @@ import { markdownDocumentation } from '../utils/previewer';
import * as typeConverters from '../utils/typeConverters';
import FileConfigurationManager from './fileConfigurationManager';

const localize = nls.loadMessageBundle();


class TypeScriptHoverProvider implements vscode.HoverProvider {
Expand Down Expand Up @@ -61,10 +59,10 @@ class TypeScriptHoverProvider implements vscode.HoverProvider {

if (source === ServerType.Syntax && this.client.hasCapabilityForResource(resource, ClientCapability.Semantic)) {
displayParts.push(
localize({
key: 'loadingPrefix',
vscode.l10n.t({
message: "(loading...)",
comment: ['Prefix displayed for hover entries while the server is still loading']
}, "(loading...)"));
}));
}

displayParts.push(data.displayString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { ITypeScriptServiceClient } from '../typescriptService';
import { DocumentSelector } from '../utils/documentSelector';
import { LanguageDescription } from '../utils/languageDescription';
import * as typeConverters from '../utils/typeConverters';
import FileConfigurationManager from './fileConfigurationManager';


const localize = nls.loadMessageBundle();

const defaultJsDoc = new vscode.SnippetString(`/**\n * $0\n */`);

Expand All @@ -22,7 +20,7 @@ class JsDocCompletionItem extends vscode.CompletionItem {
public readonly position: vscode.Position
) {
super('/** */', vscode.CompletionItemKind.Text);
this.detail = localize('typescript.jsDocCompletionItem.documentation', 'JSDoc comment');
this.detail = vscode.l10n.t("JSDoc comment");
this.sortText = '\0';

const line = document.lineAt(position.line).text;
Expand Down
Loading