惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
小众软件
小众软件
美团技术团队
Martin Fowler
Martin Fowler
爱范儿
爱范儿
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
J
Java Code Geeks
B
Blog
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
博客园 - Franky

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Localizing Gemini Prompts — Getting AI Responses in the U...
hiyoyo · 2026-05-05 · via DEV Community
Cover image for Localizing Gemini Prompts — Getting AI Responses in the User's Language

hiyoyo

If this is useful, a ❤️ helps others find it.

All tests run on an 8-year-old MacBook Air.

HiyokoLogcat supports Japanese and English. The AI diagnosis needed to respond in whichever language the user chose.

The simplest solution: write the system prompt in the target language. Gemini follows it reliably.


The naive approach (wrong)

// Don't do this
let prompt = format!("Analyze this log: {}\nRespond in Japanese.", context);

Enter fullscreen mode Exit fullscreen mode

Tacking "respond in Japanese" onto an English prompt produces inconsistent results. Sometimes Gemini complies, sometimes it doesn't.


The right approach: prompt in the target language

pub enum Lang {
    Japanese,
    English,
}

pub fn build_system_prompt(lang: &Lang) -> &'static str {
    match lang {
        Lang::Japanese =>
            "あなたはAndroid開発のスペシャリストです。\
             以下のlogcatからエラーの根本原因と解決策を、\
             日本語で簡潔に3〜5文で答えてください。\
             KEY ERROR LINEが対象のエラーです。",

        Lang::English =>
            "You are an Android development specialist. \
             Identify the root cause of the KEY ERROR LINE \
             and suggest a fix. Be concise — 3 to 5 sentences.",
    }
}

pub async fn diagnose(
    context: &str,
    api_key: &str,
    lang: &Lang,
) -> Result {
    let system = build_system_prompt(lang);
    call_gemini_with_system(system, context, api_key).await
}

Enter fullscreen mode Exit fullscreen mode

Japanese system prompt → Japanese response. Every time. No post-processing.


Reading the language from app state

#[tauri::command]
pub async fn run_diagnosis(
    context: String,
    api_key: String,
    language: String,  // "ja" or "en" from frontend i18n state
) -> Result {
    let lang = match language.as_str() {
        "ja" => Lang::Japanese,
        _ => Lang::English,
    };

    diagnose(&context, &api_key, &lang)
        .await
        .map_err(|e| format!("{:?}", e))
}

Enter fullscreen mode Exit fullscreen mode

The frontend passes its current locale string. Rust maps it to the enum. The prompt is built from there.


Adding a new language

pub enum Lang {
    Japanese,
    English,
    Korean,  // add new variant
}

pub fn build_system_prompt(lang: &Lang) -> &'static str {
    match lang {
        Lang::Korean =>
            "당신은 Android 개발 전문가입니다. \
             KEY ERROR LINE의 근본 원인과 해결책을 \
             한국어로 간결하게 3~5문장으로 답해주세요.",
        // ...
    }
}

Enter fullscreen mode Exit fullscreen mode

One new match arm. That's the whole change.


What about translation APIs?

Unnecessary complexity. Writing the prompt in the target language is simpler, cheaper (no extra API call), and more reliable than translating the response after the fact.


Hiyoko PDF Vault → https://hiyokoko.gumroad.com/l/HiyokoPDFVault
X → @hiyoyok