<%_* // Gemini API 키를 외부 파일에서 로드 (content 폴더 밖의 secrets.json) const secretsContent = await app.vault.adapter.read(“secrets.json”); const secrets = JSON.parse(secretsContent); const GEMINI_API_KEY = secrets.GEMINI_API_KEY; _%>

<%_* // 번역 프롬프트 정의 const translation_prompt = ` You are an expert technical translator specializing in accurate, context-preserving translations between English and Korean.

Translation Rules:

  1. Preserve technical terminology unless a widely accepted Korean equivalent exists.
  2. Maintain structure and formatting:
    • Headings, lists, tables, code blocks, spacing, callouts 유지
  3. Translate code comments, but never touch actual code syntax.
  4. Never summarize, omit, or add content.
  5. Keep tone neutral, accurate, and consistent.

Output:

  • ONLY output the fully translated Korean markdown
  • NO explanation
  • NO metadata
  • NO reasoning
  • Maintain exact markdown formatting `; _%>

<%_* async function generateTranslation(content) { const model = “gemini-flash-lite-latest”; const url = https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${GEMINI_API_KEY}; const full_prompt = ${translation_prompt}\n\nHere is the content to translate:\n${content};

try {
    const response = await tp.obsidian.requestUrl({
        method: "POST",
        url: url,
        contentType: "application/json",
        body: JSON.stringify({
            contents: [{ parts: [{ text: full_prompt }] }]
        })
    });
    
    return response.json.candidates[0].content.parts[0].text.trim();
} catch (error) {
    console.error("Gemini API Error:", error);
    return null;
}

}

// 현재 활성 문서 가져오기 const file = tp.config.target_file; // 현재 열린 파일 const content = tp.file.content; // 현재 파일의 전체 내용

try { const translated = await generateTranslation(content); if (!translated) throw new Error(“번역 실패”);

// 파일 전체를 번역 결과로 교체
await app.vault.modify(file, translated);

} catch (error) { console.error(“Execution Error:”, error); } _%>