Skip to content

Commit

Permalink
Adopt l10n for ts extension (#165450)
Browse files Browse the repository at this point in the history
For #164438

Also refines the eslint rule from #165448
  • Loading branch information
mjbvz authored Nov 4, 2022
1 parent cd29f75 commit 0bd1531
Show file tree
Hide file tree
Showing 34 changed files with 136 additions and 236 deletions.
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
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 { OrganizeImportsMode } from '../protocol.const';
Expand All @@ -17,7 +16,6 @@ import { TelemetryReporter } from '../utils/telemetry';
import * as typeConverters from '../utils/typeConverters';
import FileConfigurationManager from './fileConfigurationManager';

const localize = nls.loadMessageBundle();

interface OrganizeImportsCommandMetadata {
readonly ids: readonly string[];
Expand All @@ -30,23 +28,23 @@ interface OrganizeImportsCommandMetadata {
const organizeImportsCommand: OrganizeImportsCommandMetadata = {
ids: ['typescript.organizeImports'],
minVersion: API.v280,
title: localize('organizeImportsAction.title', "Organize Imports"),
title: vscode.l10n.t("Organize Imports"),
kind: vscode.CodeActionKind.SourceOrganizeImports,
mode: OrganizeImportsMode.All,
};

const sortImportsCommand: OrganizeImportsCommandMetadata = {
ids: ['typescript.sortImports', 'javascript.sortImports'],
minVersion: API.v430,
title: localize('sortImportsAction.title', "Sort Imports"),
title: vscode.l10n.t("Sort Imports"),
kind: vscode.CodeActionKind.Source.append('sortImports'),
mode: OrganizeImportsMode.SortAndCombine,
};

const removeUnusedImportsCommand: OrganizeImportsCommandMetadata = {
ids: ['typescript.removeUnusedImports', 'javascript.removeUnusedImports'],
minVersion: API.v490,
title: localize('removeUnusedImportsAction.title', "Remove Unused Imports"),
title: vscode.l10n.t("Remove Unused Imports"),
kind: vscode.CodeActionKind.Source.append('removeUnusedImports'),
mode: OrganizeImportsMode.RemoveUnused,
};
Expand All @@ -73,15 +71,15 @@ class OrganizeImportsCommand implements Command {
if (!file) {
const activeEditor = vscode.window.activeTextEditor;
if (!activeEditor) {
vscode.window.showErrorMessage(localize('error.organizeImports.noResource', "Organize Imports failed. No resource provided."));
vscode.window.showErrorMessage(vscode.l10n.t("Organize Imports failed. No resource provided."));
return;
}

const resource = activeEditor.document.uri;
const document = await vscode.workspace.openTextDocument(resource);
const openedFiledPath = this.client.toOpenedFilePath(document);
if (!openedFiledPath) {
vscode.window.showErrorMessage(localize('error.organizeImports.unknownFile', "Organize Imports failed. Unknown file type."));
vscode.window.showErrorMessage(vscode.l10n.t("Organize Imports failed. Unknown file type."));
return;
}

Expand Down
Loading

0 comments on commit 0bd1531

Please sign in to comment.