mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-21 21:01:06 -05:00
Add a preferred language dropdown
This commit is contained in:
@@ -769,8 +769,8 @@ export class Cline {
|
||||
throw new Error("MCP hub not available")
|
||||
}
|
||||
|
||||
const { browserLargeViewport } = await this.providerRef.deref()?.getState() ?? {}
|
||||
const systemPrompt = await SYSTEM_PROMPT(cwd, this.api.getModel().info.supportsComputerUse ?? false, mcpHub, this.diffStrategy, browserLargeViewport) + await addCustomInstructions(this.customInstructions ?? '', cwd)
|
||||
const { browserLargeViewport, preferredLanguage } = await this.providerRef.deref()?.getState() ?? {}
|
||||
const systemPrompt = await SYSTEM_PROMPT(cwd, this.api.getModel().info.supportsComputerUse ?? false, mcpHub, this.diffStrategy, browserLargeViewport) + await addCustomInstructions(this.customInstructions ?? '', cwd, preferredLanguage)
|
||||
|
||||
// If the previous API request's total token usage is close to the context window, truncate the conversation history to free up space for the new request
|
||||
if (previousApiReqIndex >= 0) {
|
||||
|
||||
@@ -772,9 +772,17 @@ async function loadRuleFiles(cwd: string): Promise<string> {
|
||||
return combinedRules
|
||||
}
|
||||
|
||||
export async function addCustomInstructions(customInstructions: string, cwd: string): Promise<string> {
|
||||
export async function addCustomInstructions(customInstructions: string, cwd: string, preferredLanguage?: string): Promise<string> {
|
||||
const ruleFileContent = await loadRuleFiles(cwd)
|
||||
const allInstructions = [customInstructions.trim()]
|
||||
const allInstructions = []
|
||||
|
||||
if (preferredLanguage) {
|
||||
allInstructions.push(`You should always speak and think in the ${preferredLanguage} language.`)
|
||||
}
|
||||
|
||||
if (customInstructions.trim()) {
|
||||
allInstructions.push(customInstructions.trim())
|
||||
}
|
||||
|
||||
if (ruleFileContent && ruleFileContent.trim()) {
|
||||
allInstructions.push(ruleFileContent.trim())
|
||||
|
||||
@@ -71,6 +71,7 @@ type GlobalStateKey =
|
||||
| "alwaysAllowMcp"
|
||||
| "browserLargeViewport"
|
||||
| "fuzzyMatchThreshold"
|
||||
| "preferredLanguage" // Language setting for Cline's communication
|
||||
|
||||
export const GlobalFileNames = {
|
||||
apiConversationHistory: "api_conversation_history.json",
|
||||
@@ -622,6 +623,10 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
await this.updateGlobalState("fuzzyMatchThreshold", message.value)
|
||||
await this.postStateToWebview()
|
||||
break
|
||||
case "preferredLanguage":
|
||||
await this.updateGlobalState("preferredLanguage", message.text)
|
||||
await this.postStateToWebview()
|
||||
break
|
||||
}
|
||||
},
|
||||
null,
|
||||
@@ -951,6 +956,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
taskHistory,
|
||||
soundVolume,
|
||||
browserLargeViewport,
|
||||
preferredLanguage,
|
||||
} = await this.getState()
|
||||
|
||||
const allowedCommands = vscode.workspace
|
||||
@@ -977,6 +983,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
allowedCommands,
|
||||
soundVolume: soundVolume ?? 0.5,
|
||||
browserLargeViewport: browserLargeViewport ?? false,
|
||||
preferredLanguage: preferredLanguage ?? 'English',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1072,6 +1079,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
soundVolume,
|
||||
browserLargeViewport,
|
||||
fuzzyMatchThreshold,
|
||||
preferredLanguage,
|
||||
] = await Promise.all([
|
||||
this.getGlobalState("apiProvider") as Promise<ApiProvider | undefined>,
|
||||
this.getGlobalState("apiModelId") as Promise<string | undefined>,
|
||||
@@ -1112,6 +1120,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
this.getGlobalState("soundVolume") as Promise<number | undefined>,
|
||||
this.getGlobalState("browserLargeViewport") as Promise<boolean | undefined>,
|
||||
this.getGlobalState("fuzzyMatchThreshold") as Promise<number | undefined>,
|
||||
this.getGlobalState("preferredLanguage") as Promise<string | undefined>,
|
||||
])
|
||||
|
||||
let apiProvider: ApiProvider
|
||||
@@ -1170,6 +1179,27 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
soundVolume,
|
||||
browserLargeViewport: browserLargeViewport ?? false,
|
||||
fuzzyMatchThreshold: fuzzyMatchThreshold ?? 1.0,
|
||||
preferredLanguage: preferredLanguage ?? (() => {
|
||||
// Get VSCode's locale setting
|
||||
const vscodeLang = vscode.env.language;
|
||||
// Map VSCode locale to our supported languages
|
||||
const langMap: { [key: string]: string } = {
|
||||
'en': 'English',
|
||||
'es': 'Spanish',
|
||||
'fr': 'French',
|
||||
'de': 'German',
|
||||
'it': 'Italian',
|
||||
'pt': 'Portuguese',
|
||||
'zh': 'Chinese',
|
||||
'ja': 'Japanese',
|
||||
'ko': 'Korean',
|
||||
'ru': 'Russian',
|
||||
'ar': 'Arabic',
|
||||
'hi': 'Hindi'
|
||||
};
|
||||
// Return mapped language or default to English
|
||||
return langMap[vscodeLang.split('-')[0]] ?? 'English';
|
||||
})(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,8 @@ jest.mock('vscode', () => ({
|
||||
onDidCloseTextDocument: jest.fn(() => ({ dispose: jest.fn() }))
|
||||
},
|
||||
env: {
|
||||
uriScheme: 'vscode'
|
||||
uriScheme: 'vscode',
|
||||
language: 'en'
|
||||
}
|
||||
}))
|
||||
|
||||
@@ -235,6 +236,7 @@ describe('ClineProvider', () => {
|
||||
|
||||
const mockState: ExtensionState = {
|
||||
version: '1.0.0',
|
||||
preferredLanguage: 'English',
|
||||
clineMessages: [],
|
||||
taskHistory: [],
|
||||
shouldShowAnnouncement: false,
|
||||
@@ -248,7 +250,7 @@ describe('ClineProvider', () => {
|
||||
alwaysAllowBrowser: false,
|
||||
uriScheme: 'vscode',
|
||||
soundEnabled: false,
|
||||
diffEnabled: false
|
||||
diffEnabled: false,
|
||||
}
|
||||
|
||||
const message: ExtensionMessage = {
|
||||
@@ -300,6 +302,22 @@ describe('ClineProvider', () => {
|
||||
expect(state).toHaveProperty('diffEnabled')
|
||||
})
|
||||
|
||||
test('preferredLanguage defaults to VSCode language when not set', async () => {
|
||||
// Mock VSCode language as Spanish
|
||||
(vscode.env as any).language = 'es-ES';
|
||||
|
||||
const state = await provider.getState();
|
||||
expect(state.preferredLanguage).toBe('Spanish');
|
||||
});
|
||||
|
||||
test('preferredLanguage defaults to English for unsupported VSCode language', async () => {
|
||||
// Mock VSCode language as an unsupported language
|
||||
(vscode.env as any).language = 'unsupported-LANG';
|
||||
|
||||
const state = await provider.getState();
|
||||
expect(state.preferredLanguage).toBe('English');
|
||||
});
|
||||
|
||||
test('diffEnabled defaults to true when not set', async () => {
|
||||
// Mock globalState.get to return undefined for diffEnabled
|
||||
(mockContext.globalState.get as jest.Mock).mockReturnValue(undefined)
|
||||
|
||||
Reference in New Issue
Block a user