feat(ai): make lookup language explicit and deterministic (#286) - #287
Merged
Conversation
Look Up's definition/context now always honors the configured lookup
language (English included), fixing the case where an English setting
drifted to the selection's language. Adds a "Same as selection" option
that mirrors the selected text's language — the new default for installs
that never set lookup_language.
- ai.rs: add LOOKUP_LANGUAGE_SELECTION sentinel + main_language_clause;
always emit "Respond entirely in {lang}" for definition and context
(drop the language != "en" guard); handle "selection" in explain;
default lookup_language to "selection" in ai_lookup and ai_explain
- ToolsSettings: add "Same as selection" to the lookup dropdown only,
default the select to selection, and widen it to fit the label
- i18n: add settings.tools.sameAsSelection (en/zh)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Owner
Author
|
Review findings: No remaining must-fix issues found. The PR matches issue #286: lookup/explain prompts now emit explicit response-language directives including English, the Verification:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #286.
Problem
Look Up's main definition/context did not deterministically follow the configured Lookup language:
language != "en", so a Chinese selection with Lookup language = English drifted back to Chinese. (Core bug.)Changes
src-tauri/src/commands/ai.rsLOOKUP_LANGUAGE_SELECTIONsentinel +main_language_clause()helper.lookup_system_promptnow always emits a "Respond entirely in {clause}" directive for both definition and context (drops thelanguage != "en"guard). The brief-translation gloss stays an independent add-on, allowed alongside "Same as selection".explain_system_promptuses the sharedlanguage_namemap, handles"selection"("the same language as the selected passage"), and emits the English directive explicitly.lookup_languagefalls back to"selection"(instead of the app language) in bothai_lookupandai_explain.src/components/settings/ToolsSettings.tsx— prepend a Same as selection option to the Lookup-language dropdown only (gloss/explain/translate keep concrete languages); default the dropdown tolookup_language || "selection"; widen the select to fit the label.settings.tools.sameAsSelection("Same as selection" / "跟随所选内容").No setting keys renamed, no migration:
"selection"is a value the existinglookup_languagekey can hold. Existing installs that never setlookup_languageshift from app-language to source-language definitions — intentional and now self-documenting in Settings.Tests / checks
cargo test— full suite green; new prompt regressions:lookup_english_emits_explicit_english_directive,lookup_selection_uses_source_language,lookup_selection_allows_gloss,explain_selection_uses_source_language(plus updated existing tests).npm run lint— 0 errors (pre-existing warnings only);tsc --noEmit— clean.🤖 Generated with Claude Code