Skip to content

fix: use UI language setting in prompt suggestions#278

Open
Perlenjaeger wants to merge 1 commit into
zerx-lab:mainfrom
Perlenjaeger:fix/prompt-suggestions-english
Open

fix: use UI language setting in prompt suggestions#278
Perlenjaeger wants to merge 1 commit into
zerx-lab:mainfrom
Perlenjaeger:fix/prompt-suggestions-english

Conversation

@Perlenjaeger

Copy link
Copy Markdown

This PR fixes the AI inline suggestions ignoring the user's UI language setting.

Problem:

  • The prompt_suggestions_system.j2 template contained Chinese examples and an ambiguous instruction to Match the user's language.
  • The model (e.g. Kimi via Moonshot AI, GLM5.1 via Z.ai) consistently output Chinese suggestions because all few-shot examples were in Chinese.
  • The template did not receive the actual UI language from the application settings.

Changes:

  1. Read the user's UI language from LanguageSettings and pass it to the prompt template via a language variable.
  2. Replace the ambiguous instruction with an explicit Respond in {{ language }}. directive.
  3. Translate all Chinese example queries in the few-shot prompts to English.

Fixes: #191

The prompt_suggestions_system.j2 template contained Chinese examples
and an instruction to 'Match the user's language'. This caused the
model to consistently output Chinese suggestions because all
few-shot examples were in Chinese.

This change:
1. Reads the user's UI language from LanguageSettings
2. Passes it to the prompt template via a 'language' variable
3. Replaces all Chinese example queries with English equivalents

Fixes: AI inline suggestions ignoring UI language preference

@zerx-lab zerx-lab left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(详见 inline comments 和下方总结 comment)

— 由 Claude Routine 自动生成;如需复评请 @ 维护者人工触发。


Generated by Claude Code

let system = render("prompt_suggestions_system.j2", context! {});
let language = *LanguageSettings::as_ref(app).language;
let language_str = match language {
Language::System => "English".to_string(),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Language::System 映射到 "English" 是否正确?

Language::System 的含义是「跟随操作系统语言」,如果用户的操作系统设置为日语或中文,他们会期待提示语言与系统语言一致。这里将其硬编码为 "English" 会导致:系统语言为中文 + 应用选择 Language::System 的用户,在此 PR 修复后反而会得到英文建议。

PR body 里提到「与 app 的 i18n fallback 行为一致」——但 i18n fallback 只是 UI 文本的兜底逻辑,不代表应该对 AI 提示也做同样处理。

建议:如果 LanguageSettings 提供了「解析后的实际语言」(而不只是原始枚举值),可以在此处用它;否则至少加一条注释说明这是已知的近似处理,并在 Language::System 下附上一个 TODO。


Generated by Claude Code

let language = *LanguageSettings::as_ref(app).language;
let language_str = match language {
Language::System => "English".to_string(),
_ => language.to_string(),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: language.to_string() 会产生什么字符串?

Language::SimplifiedChineseLanguage::JapaneseDisplay 实现会输出什么?如果是 "SimplifiedChinese" 或 Rust 枚举名,模型大概率无法识别。如果是 "Simplified Chinese""Japanese" 之类的自然语言描述则没问题。

建议确认 LanguageDisplay impl,或用显式的 match 替换 _ 通配,把每个 variant 映射到模型能理解的字符串(如 "Simplified Chinese" / "Japanese"),而不是依赖 to_string() 的隐式行为。


Generated by Claude Code

Copy link
Copy Markdown
Owner

Review 总结

整体判断:Comment(需确认两处问题后可合并)。改动方向正确——将 context! {} 替换为携带实际 language 变量,并把 5 条中文 few-shot 示例改为英文,消除了语言偏置。但有两处需要确认(见 inline comments)。

另注:PR #277 对同一 issue 做了几乎相同的修复,建议维护者确认只合并其中一个。


阻塞问题

无强阻塞,但建议合并前确认:

  1. Language::System"English" 的正确性:操作系统设置为中文或日文且应用选择 System 的用户,修复后会收到英文建议,与预期相反。
  2. language.to_string() 的格式:若 Language::SimplifiedChineseDisplay 输出是 Rust 枚举名(如 "SimplifiedChinese"),模型大概率无法识别。

建议

  • _ => language.to_string() 替换为显式 match,把每个 variant 映射到模型可理解的自然语言名称("Simplified Chinese""Japanese" 等)。

看起来不错的地方

  • context!{ language => language_str } 写法与同文件其他 render() 调用一致
  • 将 5 条中文示例统一翻译为英文,英文基准配合 {{ language }} 指令泛化效果更好

— 由 Claude Routine 自动生成;如需复评请 @ 维护者人工触发。


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants