Skip to content

Commit 0bd1531

Browse files
authored
Adopt l10n for ts extension (microsoft#165450)
For microsoft#164438 Also refines the eslint rule from microsoft#165448
1 parent cd29f75 commit 0bd1531

34 files changed

+136
-236
lines changed

extensions/typescript-language-features/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"@vscode/extension-telemetry": "0.6.2",
3838
"jsonc-parser": "^2.2.1",
3939
"semver": "5.5.1",
40-
"vscode-nls": "^5.2.0",
4140
"vscode-tas-client": "^0.1.63",
4241
"vscode-uri": "^3.0.3"
4342
},

extensions/typescript-language-features/src/languageFeatures/codeLens/baseCodeLensProvider.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import * as nls from 'vscode-nls';
87
import type * as Proto from '../../protocol';
98
import { CachedResponse } from '../../tsServer/cachedResponse';
109
import { ITypeScriptServiceClient } from '../../typescriptService';
1110
import { escapeRegExp } from '../../utils/regexp';
1211
import * as typeConverters from '../../utils/typeConverters';
1312

14-
const localize = nls.loadMessageBundle();
1513

1614
export class ReferencesCodeLens extends vscode.CodeLens {
1715
constructor(
@@ -32,7 +30,7 @@ export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensP
3230
};
3331

3432
public static readonly errorCommand: vscode.Command = {
35-
title: localize('referenceErrorLabel', 'Could not determine references'),
33+
title: vscode.l10n.t("Could not determine references"),
3634
command: ''
3735
};
3836

extensions/typescript-language-features/src/languageFeatures/codeLens/implementationsCodeLens.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55

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

18-
const localize = nls.loadMessageBundle();
1917

2018
export default class TypeScriptImplementationsCodeLensProvider extends TypeScriptBaseCodeLensProvider {
2119

@@ -61,8 +59,8 @@ export default class TypeScriptImplementationsCodeLensProvider extends TypeScrip
6159

6260
private getTitle(locations: vscode.Location[]): string {
6361
return locations.length === 1
64-
? localize('oneImplementationLabel', '1 implementation')
65-
: localize('manyImplementationLabel', '{0} implementations', locations.length);
62+
? vscode.l10n.t("1 implementation")
63+
: vscode.l10n.t("{0} implementations", locations.length);
6664
}
6765

6866
protected extractSymbol(

extensions/typescript-language-features/src/languageFeatures/codeLens/referencesCodeLens.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55

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

19-
const localize = nls.loadMessageBundle();
2018

2119
export class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLensProvider {
2220
public constructor(
@@ -56,8 +54,8 @@ export class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLens
5654

5755
private getCodeLensLabel(locations: ReadonlyArray<vscode.Location>): string {
5856
return locations.length === 1
59-
? localize('oneReferenceLabel', '1 reference')
60-
: localize('manyReferenceLabel', '{0} references', locations.length);
57+
? vscode.l10n.t("1 reference")
58+
: vscode.l10n.t("{0} references", locations.length);
6159
}
6260

6361
protected extractSymbol(

extensions/typescript-language-features/src/languageFeatures/completions.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import * as nls from 'vscode-nls';
87
import { Command, CommandManager } from '../commands/commandManager';
98
import type * as Proto from '../protocol';
109
import * as PConst from '../protocol.const';
@@ -23,7 +22,6 @@ import * as typeConverters from '../utils/typeConverters';
2322
import TypingsStatus from '../utils/typingsStatus';
2423
import FileConfigurationManager from './fileConfigurationManager';
2524

26-
const localize = nls.loadMessageBundle();
2725

2826
interface DotAccessorContext {
2927
readonly range: vscode.Range;
@@ -622,7 +620,7 @@ class ApplyCompletionCodeActionCommand implements Command {
622620
description: '',
623621
action,
624622
})), {
625-
placeHolder: localize('selectCodeAction', 'Select code action to apply')
623+
placeHolder: vscode.l10n.t("Select code action to apply")
626624
});
627625

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

693691
if (this.typingsStatus.isAcquiringTypings) {
694692
return Promise.reject<vscode.CompletionList<MyCompletionItem>>({
695-
label: localize(
696-
{ key: 'acquiringTypingsLabel', comment: ['Typings refers to the *.d.ts typings files that power our IntelliSense. It should not be localized'] },
697-
'Acquiring typings...'),
698-
detail: localize(
699-
{ key: 'acquiringTypingsDetail', comment: ['Typings refers to the *.d.ts typings files that power our IntelliSense. It should not be localized'] },
700-
'Acquiring typings definitions for IntelliSense.')
693+
label: vscode.l10n.t({
694+
message: "Acquiring typings...",
695+
comment: ['Typings refers to the *.d.ts typings files that power our IntelliSense. It should not be localized'],
696+
}),
697+
detail: vscode.l10n.t({
698+
message: "Acquiring typings definitions for IntelliSense.",
699+
comment: ['Typings refers to the *.d.ts typings files that power our IntelliSense. It should not be localized'],
700+
})
701701
});
702702
}
703703

extensions/typescript-language-features/src/languageFeatures/directiveCommentCompletions.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import * as nls from 'vscode-nls';
87
import { ITypeScriptServiceClient } from '../typescriptService';
98
import API from '../utils/api';
109
import { DocumentSelector } from '../utils/documentSelector';
1110

12-
const localize = nls.loadMessageBundle();
1311

1412
interface Directive {
1513
readonly value: string;
@@ -19,29 +17,21 @@ interface Directive {
1917
const tsDirectives: Directive[] = [
2018
{
2119
value: '@ts-check',
22-
description: localize(
23-
'ts-check',
24-
"Enables semantic checking in a JavaScript file. Must be at the top of a file.")
20+
description: vscode.l10n.t("Enables semantic checking in a JavaScript file. Must be at the top of a file.")
2521
}, {
2622
value: '@ts-nocheck',
27-
description: localize(
28-
'ts-nocheck',
29-
"Disables semantic checking in a JavaScript file. Must be at the top of a file.")
23+
description: vscode.l10n.t("Disables semantic checking in a JavaScript file. Must be at the top of a file.")
3024
}, {
3125
value: '@ts-ignore',
32-
description: localize(
33-
'ts-ignore',
34-
"Suppresses @ts-check errors on the next line of a file.")
26+
description: vscode.l10n.t("Suppresses @ts-check errors on the next line of a file.")
3527
}
3628
];
3729

3830
const tsDirectives390: Directive[] = [
3931
...tsDirectives,
4032
{
4133
value: '@ts-expect-error',
42-
description: localize(
43-
'ts-expect-error',
44-
"Suppresses @ts-check errors on the next line of a file, expecting at least one to exist.")
34+
description: vscode.l10n.t("Suppresses @ts-check errors on the next line of a file, expecting at least one to exist.")
4535
}
4636
];
4737

extensions/typescript-language-features/src/languageFeatures/fileReferences.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import * as nls from 'vscode-nls';
87
import { Command, CommandManager } from '../commands/commandManager';
98
import { ITypeScriptServiceClient } from '../typescriptService';
109
import API from '../utils/api';
1110
import { isSupportedLanguageMode } from '../utils/languageIds';
1211
import * as typeConverters from '../utils/typeConverters';
1312

14-
const localize = nls.loadMessageBundle();
1513

1614
class FileReferencesCommand implements Command {
1715

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

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

3331
resource ??= vscode.window.activeTextEditor?.document.uri;
3432
if (!resource) {
35-
vscode.window.showErrorMessage(localize('error.noResource', "Find file references failed. No resource provided."));
33+
vscode.window.showErrorMessage(vscode.l10n.t("Find file references failed. No resource provided."));
3634
return;
3735
}
3836

3937
const document = await vscode.workspace.openTextDocument(resource);
4038
if (!isSupportedLanguageMode(document)) {
41-
vscode.window.showErrorMessage(localize('error.unsupportedLanguage', "Find file references failed. Unsupported file type."));
39+
vscode.window.showErrorMessage(vscode.l10n.t("Find file references failed. Unsupported file type."));
4240
return;
4341
}
4442

4543
const openedFiledPath = this.client.toOpenedFilePath(document);
4644
if (!openedFiledPath) {
47-
vscode.window.showErrorMessage(localize('error.unknownFile', "Find file references failed. Unknown file type."));
45+
vscode.window.showErrorMessage(vscode.l10n.t("Find file references failed. Unknown file type."));
4846
return;
4947
}
5048

5149
await vscode.window.withProgress({
5250
location: vscode.ProgressLocation.Window,
53-
title: localize('progress.title', "Finding file references")
51+
title: vscode.l10n.t("Finding file references")
5452
}, async (_progress, token) => {
5553

5654
const response = await this.client.execute('fileReferences', {

extensions/typescript-language-features/src/languageFeatures/fixAll.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import * as nls from 'vscode-nls';
87
import type * as Proto from '../protocol';
98
import { ClientCapability, ITypeScriptServiceClient } from '../typescriptService';
109
import API from '../utils/api';
@@ -16,7 +15,6 @@ import * as typeConverters from '../utils/typeConverters';
1615
import { DiagnosticsManager } from './diagnostics';
1716
import FileConfigurationManager from './fileConfigurationManager';
1817

19-
const localize = nls.loadMessageBundle();
2018

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

135133
constructor() {
136-
super(localize('autoFix.label', 'Fix all fixable JS/TS issues'), SourceFixAll.kind);
134+
super(vscode.l10n.t("Fix all fixable JS/TS issues"), SourceFixAll.kind);
137135
}
138136

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

157155
constructor() {
158-
super(localize('autoFix.unused.label', 'Remove all unused code'), SourceRemoveUnused.kind);
156+
super(vscode.l10n.t("Remove all unused code"), SourceRemoveUnused.kind);
159157
}
160158

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

173171
constructor() {
174-
super(localize('autoFix.missingImports.label', 'Add all missing imports'), SourceAddMissingImports.kind);
172+
super(vscode.l10n.t("Add all missing imports"), SourceAddMissingImports.kind);
175173
}
176174

177175
async build(client: ITypeScriptServiceClient, file: string, diagnostics: readonly vscode.Diagnostic[], token: vscode.CancellationToken): Promise<void> {

extensions/typescript-language-features/src/languageFeatures/hover.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55

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

16-
const localize = nls.loadMessageBundle();
1715

1816

1917
class TypeScriptHoverProvider implements vscode.HoverProvider {
@@ -61,10 +59,10 @@ class TypeScriptHoverProvider implements vscode.HoverProvider {
6159

6260
if (source === ServerType.Syntax && this.client.hasCapabilityForResource(resource, ClientCapability.Semantic)) {
6361
displayParts.push(
64-
localize({
65-
key: 'loadingPrefix',
62+
vscode.l10n.t({
63+
message: "(loading...)",
6664
comment: ['Prefix displayed for hover entries while the server is still loading']
67-
}, "(loading...)"));
65+
}));
6866
}
6967

7068
displayParts.push(data.displayString);

extensions/typescript-language-features/src/languageFeatures/jsDocCompletions.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import * as nls from 'vscode-nls';
87
import { ITypeScriptServiceClient } from '../typescriptService';
98
import { DocumentSelector } from '../utils/documentSelector';
109
import { LanguageDescription } from '../utils/languageDescription';
1110
import * as typeConverters from '../utils/typeConverters';
1211
import FileConfigurationManager from './fileConfigurationManager';
1312

1413

15-
const localize = nls.loadMessageBundle();
1614

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

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

2826
const line = document.lineAt(position.line).text;

0 commit comments

Comments
 (0)