Skip to content

Commit 37d501c

Browse files
committed
setting option for language #180
1 parent 9d81ed5 commit 37d501c

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
"type": "boolean",
6969
"required": false,
7070
"description": "Disable checking of type annotations."
71+
},
72+
"write-your-python-program.language": {
73+
"type": "string",
74+
"enum": ["german", "english", "system default"],
75+
"default": "system default",
76+
"description": "Choose the language for error messages."
7177
}
7278
}
7379
}

src/extension.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const extensionId = 'write-your-python-program';
1313
const python3ConfigKey = 'python3Cmd';
1414
const verboseConfigKey = 'verbose';
1515
const debugConfigKey = 'debug';
16+
const languageKey = 'language';
1617
const disableTypecheckingConfigKey = 'disableTypechecking';
1718
const isWindows = process.platform === "win32";
1819
const exeExt = isWindows ? ".exe" : "";
@@ -217,6 +218,19 @@ function disableTypechecking(context: vscode.ExtensionContext): boolean {
217218
return !!config[disableTypecheckingConfigKey];
218219
}
219220

221+
function getLanguage(context: vscode.ExtensionContext): 'en' | 'de' | undefined {
222+
const config = vscode.workspace.getConfiguration(extensionId);
223+
const lang = config[languageKey];
224+
if (lang === 'english') {
225+
return 'en';
226+
} else if (lang === 'german') {
227+
return 'de';
228+
} else {
229+
return undefined;
230+
}
231+
}
232+
233+
220234
async function fixPylanceConfig(
221235
context: vscode.ExtensionContext,
222236
folder?: vscode.WorkspaceFolder
@@ -413,7 +427,6 @@ export async function activate(context: vscode.ExtensionContext) {
413427
"run",
414428
"▶ RUN",
415429
async (cmdId) => {
416-
await fixPylanceConfig(context);
417430
const file =
418431
(vscode.window.activeTextEditor) ?
419432
vscode.window.activeTextEditor.document.fileName :
@@ -426,6 +439,7 @@ export async function activate(context: vscode.ExtensionContext) {
426439
vscode.window.showWarningMessage('Not a python file');
427440
return;
428441
}
442+
await fixPylanceConfig(context);
429443
await vscode.window.activeTextEditor?.document.save();
430444
const pyCmd = getPythonCmd(pyExt);
431445
let verboseOpt = "";
@@ -437,14 +451,19 @@ export async function activate(context: vscode.ExtensionContext) {
437451
if (verboseOpt !== "") {
438452
verboseOpt = " " + verboseOpt + " --no-clear";
439453
}
454+
const lang = getLanguage(context);
455+
let langOpt = "";
456+
if (lang) {
457+
langOpt = " --lang " + lang;
458+
}
440459
const disableOpt = disableTypechecking(context) ? " --no-typechecking" : "";
441460
if (pyCmd.kind !== "error") {
442461
const pythonCmd = commandListToArgument(pyCmd.cmd);
443462
const cmdTerm = await startTerminal(
444463
terminals[cmdId]?.terminal,
445464
"WYPP - RUN",
446465
pythonCmd + " " + fileToCommandArgument(runProg) + verboseOpt +
447-
disableOpt +
466+
disableOpt + langOpt +
448467
" --interactive " +
449468
" --change-directory " +
450469
fileToCommandArgument(file)

0 commit comments

Comments
 (0)