Add language support for DevChat interface

This commit is contained in:
bobo.yang 2023-12-25 14:03:37 +08:00
parent b1dd28c934
commit 9e6eeef721
4 changed files with 37 additions and 2 deletions

View File

@ -551,6 +551,16 @@
"type": "string",
"default": "",
"description": "Path to the Python virtual environment for AskCode."
},
"DevChat.Language": {
"type": "string",
"default": "en",
"enum": ["en", "zh-cn"],
"enumDescriptions": [
"English",
"Simplified Chinese"
],
"description": "The language used for DevChat interface."
}
}
},

View File

@ -15,6 +15,7 @@ import { getSetting, updateSetting } from './userSettingHandler';
import { featureToggle, getFeatureToggles } from './featureToggleHandler';
import { getUserAccessKey } from './accessKeyHandler';
import { getValidLlmModelList } from './llmModelHandler';
import { getIdeLanguage } from './langHandler';
// According to the context menu selected by the user, add the corresponding context file
@ -78,3 +79,5 @@ messageHandler.registerHandler('getUserAccessKey', getUserAccessKey);
messageHandler.registerHandler('regModelList', getValidLlmModelList);
messageHandler.registerHandler('userInput', userInput);
messageHandler.registerHandler('getIdeLanguage', getIdeLanguage);

View File

@ -0,0 +1,22 @@
import * as vscode from 'vscode';
import { regInMessage, regOutMessage } from '../util/reg_messages'; // Ensure these functions are imported
import { MessageHandler } from './messageHandler';
// Register the incoming and outgoing messages for the 'getIdeLanguage' command
regInMessage({ command: 'getIdeLanguage' });
regOutMessage({ command: 'ideLanguage', lang: "" }); // Placeholder for the lang property
// Implement the handler function to get the current IDE language setting
export async function getIdeLanguage(panel: vscode.WebviewPanel | vscode.WebviewView): Promise<void> {
// Get the current IDE language setting
const ideLanguage = vscode.env.language;
// 'en' stands for English, 'zh-cn' stands for Simplified Chinese
// Construct the message with the language information
const langMessage = {
"command": "ideLanguage",
"lang": ideLanguage
};
// Send the message to the webview panel or view
MessageHandler.sendMessage(panel, langMessage);
}

View File

@ -33,8 +33,8 @@ const functionRegistry: any = {
"/ide_language": {
"keys": [],
"handler": async () => {
const config = vscode.workspace.getConfiguration();
const language = config.get('workbench.editor.languageDetection') ? vscode.env.language : config.get('window.menuBarVisibility');
const language = vscode.env.language;
// 'en' stands for English, 'zh-cn' stands for Simplified Chinese
return language;
}
},