Skip to content

Commit afbecf9

Browse files
committed
localize
1 parent 12f31c1 commit afbecf9

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

Extension/src/LanguageServer/devcmd.ts

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,41 @@ import { vcvars } from 'node-vcvarsall';
88
import { vswhere } from 'node-vswhere';
99
import * as path from 'path';
1010
import * as vscode from 'vscode';
11+
import * as nls from 'vscode-nls';
12+
import { isWindows } from '../constants';
1113
import { CppSettings } from './settings';
1214

15+
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
16+
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
17+
18+
const ERROR_NO_CONTEXT = localize('no.context.provided', 'No context provided');
19+
const NOT_WINDOWS = localize('not.windows', 'This command is only available on Windows');
20+
const ERROR_NO_VS_FOUND = localize('error.no.vs', 'A Visual Studio installation with the C++ compiler was not found');
21+
const ERROR_OPERATION_CANCELLED = localize('operation.cancelled', 'The operation was cancelled');
22+
const ERROR_NO_HOSTS_FOUND = localize('no.hosts', 'No hosts found');
23+
const CONFIGURING_DEV_ENV = localize('config.dev.env', 'Configuring Developer Environment...');
24+
const SELECT_VS_INSTALLATION = localize('select.vs.install', 'Select a Visual Studio installation');
25+
const ADVANCED_OPTIONS = localize('advanced.options', 'Advanced options...');
26+
const ADVANCED_OPTIONS_DESCRIPTION = localize('advanced.options.desc', 'Select a specific host/target architecture, toolset version, etc.');
27+
const SELECT_TOOLSET_VERSION = localize('select.toolset', 'Select a toolset version');
28+
const SELECT_HOST_TARGET_ARCH = localize('select.host.target', 'Select a host and target architecture');
29+
1330
export function isEnvironmentOverrideApplied(context?: vscode.ExtensionContext) {
1431
return context?.environmentVariableCollection.get('VCToolsInstallDir') !== undefined;
1532
}
1633

1734
export async function setEnvironment(context?: vscode.ExtensionContext) {
35+
if (!isWindows) {
36+
throw new Error(NOT_WINDOWS);
37+
}
38+
1839
if (!context) {
19-
throw new Error('No context provided');
40+
throw new Error(ERROR_NO_CONTEXT);
2041
}
2142

2243
const vses = await getVSInstallations();
2344
if (!vses) {
24-
throw new Error('A Visual Studio installation with the C++ compiler was not found');
45+
throw new Error(ERROR_NO_VS_FOUND);
2546
}
2647

2748
let vs = await chooseVSInstallation(vses);
@@ -34,11 +55,11 @@ export async function setEnvironment(context?: vscode.ExtensionContext) {
3455
const vars = await vscode.window.withProgress({
3556
cancellable: false,
3657
location: vscode.ProgressLocation.Notification,
37-
title: 'Configuring Developer Environment...'
58+
title: CONFIGURING_DEV_ENV
3859
}, () => vcvars.getVCVars(vs, options));
3960

4061
if (!vars || !vars['INCLUDE']) {
41-
throw new Error(`Something went wrong: ${JSON.stringify(vars)}`);
62+
throw new Error(localize('something.wrong', 'Something went wrong: {0}', JSON.stringify(vars)));
4263
}
4364

4465
const host = vars['VSCMD_ARG_HOST_ARCH'];
@@ -53,7 +74,7 @@ export async function setEnvironment(context?: vscode.ExtensionContext) {
5374
for (const key of Object.keys(vars)) {
5475
context.environmentVariableCollection.replace(key, vars[key].replace(`%${key}%`, '${env:' + key + '}'));
5576
}
56-
context.environmentVariableCollection.description = (arch ? `${arch} ` : '') + 'Developer Command Prompt for ' + vs.displayName;
77+
context.environmentVariableCollection.description = localize('dev.env.for', '{0} Developer Environment for {1}', arch, vs.displayName);
5778
context.environmentVariableCollection.persistent = settings.persistDevEnvironment;
5879

5980
return true;
@@ -68,25 +89,25 @@ async function getVSInstallations() {
6889
});
6990

7091
if (installations.length === 0) {
71-
throw new Error('A Visual Studio installation with the C++ compiler was not found');
92+
throw new Error(ERROR_NO_VS_FOUND);
7293
}
7394
return installations;
7495
}
7596

7697
async function chooseVSInstallation(installations: vswhere.Installation[]): Promise<vswhere.Installation | undefined> {
7798
const items: vscode.QuickPickItem[] = installations.map(installation => <vscode.QuickPickItem>{
7899
label: installation.displayName,
79-
description: `Default settings for ${installation.displayName}`
100+
description: localize('default.settings', 'Default settings for {0}', installation.displayName)
80101
});
81102
items.push({
82-
label: 'Advanced options...',
83-
description: 'Select a specific host/target architecture, toolset version, etc.'
103+
label: ADVANCED_OPTIONS,
104+
description: ADVANCED_OPTIONS_DESCRIPTION
84105
});
85106
const selection = await vscode.window.showQuickPick(items, {
86-
placeHolder: 'Select a Visual Studio installation'
107+
placeHolder: SELECT_VS_INSTALLATION
87108
});
88109
if (!selection) {
89-
throw new Error('The operation was cancelled');
110+
throw new Error(ERROR_OPERATION_CANCELLED);
90111
}
91112

92113
return installations.find(installation => installation.displayName === selection.label);
@@ -95,7 +116,7 @@ async function chooseVSInstallation(installations: vswhere.Installation[]): Prom
95116
async function getAdvancedConfiguration(vses: vswhere.Installation[]): Promise<Compiler> {
96117
const compiler = await chooseCompiler(vses);
97118
if (!compiler) {
98-
throw new Error('The operation was cancelled');
119+
throw new Error(ERROR_OPERATION_CANCELLED);
99120
}
100121
await setOptions(compiler);
101122
return compiler;
@@ -125,10 +146,10 @@ async function chooseCompiler(vses: vswhere.Installation[]): Promise<Compiler |
125146
description: compiler.vs.displayName
126147
});
127148
const selection = await vscode.window.showQuickPick(items, {
128-
placeHolder: 'Select a toolset version'
149+
placeHolder: SELECT_TOOLSET_VERSION
129150
});
130151
if (!selection) {
131-
throw new Error('The operation was cancelled');
152+
throw new Error(ERROR_OPERATION_CANCELLED);
132153
}
133154
return compilers.find(compiler => compiler.version === selection.label && compiler.vs.displayName === selection.description);
134155
}
@@ -139,13 +160,13 @@ async function setOptions(compiler: Compiler): Promise<void> {
139160
if (hostTargets.length > 1) {
140161
const items = hostTargets.map(ht => <vscode.QuickPickItem>{
141162
label: vcvars.getArchitecture(ht),
142-
description: `host = ${ht.host}, target = ${ht.target}`
163+
description: localize('host.target', 'host = {0}, target = {1}', ht.host, ht.target)
143164
});
144165
const selection = await vscode.window.showQuickPick(items, {
145-
placeHolder: 'Select a host and target architecture'
166+
placeHolder: SELECT_HOST_TARGET_ARCH
146167
});
147168
if (!selection) {
148-
throw new Error('The operation was cancelled');
169+
throw new Error(ERROR_OPERATION_CANCELLED);
149170
}
150171
compiler.options.arch = <vcvars.Architecture>selection.label;
151172
}
@@ -154,7 +175,7 @@ async function setOptions(compiler: Compiler): Promise<void> {
154175
async function getHostsAndTargets(vcPath: string): Promise<vcvars.HostTarget[]> {
155176
const hosts = await fs.readdir(vcPath);
156177
if (hosts.length === 0) {
157-
throw new Error('No hosts found');
178+
throw new Error(ERROR_NO_HOSTS_FOUND);
158179
}
159180
const hostTargets: vcvars.HostTarget[] = [];
160181
for (const host of hosts) {

0 commit comments

Comments
 (0)