Merge pull request #2005 from zhangxy-zju/feat/strengthen-output-language-template
Some checks are pending
Qwen Code CI / CodeQL (push) Waiting to run
Qwen Code CI / Lint (push) Waiting to run
Qwen Code CI / Test (push) Blocked by required conditions
Qwen Code CI / Test-1 (push) Blocked by required conditions
Qwen Code CI / Test-2 (push) Blocked by required conditions
Qwen Code CI / Test-3 (push) Blocked by required conditions
Qwen Code CI / Test-4 (push) Blocked by required conditions
Qwen Code CI / Test-5 (push) Blocked by required conditions
Qwen Code CI / Test-6 (push) Blocked by required conditions
Qwen Code CI / Test-7 (push) Blocked by required conditions
Qwen Code CI / Test-8 (push) Blocked by required conditions
Qwen Code CI / Post Coverage Comment (push) Blocked by required conditions
E2E Tests / E2E Test (Linux) - sandbox:docker (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:none (push) Waiting to run
E2E Tests / E2E Test - macOS (push) Waiting to run

feat(i18n): strengthen output-language.md template to enforce language compliance
This commit is contained in:
tanzhenxin 2026-03-02 23:07:18 +08:00 committed by GitHub
commit 407a66c959
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 5 deletions

View file

@ -218,6 +218,43 @@ describe('languageUtils', () => {
'<!-- qwen-code:llm-output-language: TestLanguage -->',
);
});
it('should use mandatory language rule instead of preference', () => {
writeOutputLanguageFile('Chinese');
const writtenContent = vi.mocked(fs.writeFileSync).mock
.calls[0][1] as string;
expect(writtenContent).toContain(
'You MUST always respond in **Chinese**',
);
expect(writtenContent).toContain(
'This is a mandatory requirement, not a preference.',
);
expect(writtenContent).not.toContain('Prefer responding');
});
it('should include exception clause for explicit user language requests', () => {
writeOutputLanguageFile('English');
const writtenContent = vi.mocked(fs.writeFileSync).mock
.calls[0][1] as string;
expect(writtenContent).toContain('## Exception');
expect(writtenContent).toContain(
"switch to the user's requested language for the remainder of the conversation",
);
});
it('should use the correct language name throughout the template', () => {
writeOutputLanguageFile('Japanese');
const writtenContent = vi.mocked(fs.writeFileSync).mock
.calls[0][1] as string;
expect(writtenContent).toContain(
'You MUST always respond in **Japanese**',
);
expect(writtenContent).toContain('## Rule');
expect(writtenContent).toContain('## Exception');
});
});
describe('updateOutputLanguageFile', () => {

View file

@ -89,17 +89,18 @@ function generateOutputLanguageFileContent(language: string): string {
return `# Output language preference: ${language}
<!-- ${LLM_OUTPUT_LANGUAGE_MARKER_PREFIX} ${safeLanguage} -->
## Goal
Prefer responding in **${language}** for normal assistant messages and explanations.
## Rule
You MUST always respond in **${language}** regardless of the user's input language.
This is a mandatory requirement, not a preference.
## Exception
If the user **explicitly** requests a response in a specific language (e.g., "please reply in English", "用中文回答"), switch to the user's requested language for the remainder of the conversation.
## Keep technical artifacts unchanged
Do **not** translate or rewrite:
- Code blocks, CLI commands, file paths, stack traces, logs, JSON keys, identifiers
- Exact quoted text from the user (keep quotes verbatim)
## When a conflict exists
If higher-priority instructions (system/developer) require a different behavior, follow them.
## Tool / system outputs
Raw tool/system outputs may contain fixed-format English. Preserve them verbatim, and if needed, add a short **${language}** explanation below.
`;