🌍 Translation Workflows
🎯 Mục tiêu bài học
Sau bài học này, bạn sẽ:
✅ Xây dựng basic translation workflow với language detection
✅ Tạo email auto-translation pipeline
✅ Build batch document translation với smart chunking
✅ Implement translation memory và multi-language pipeline
Build automated translation pipelines cho multi-language content, email, documents, và real-time translation.
🏗️ Translation Architecture
Checkpoint
Translation pipeline gồm những bước chính nào?
🔍 Basic Translation Workflow
1// OpenAI Translation prompt2const translatePrompt = `3You are a professional translator. Translate the following text.45Source language: ${$json.sourceLang || "auto-detect"}6Target language: ${$json.targetLang}78Translation rules:91. Maintain the original tone and style102. Use natural, fluent ${$json.targetLang}113. Keep technical terms in English if more commonly used124. Preserve formatting (bullet points, paragraphs)135. Do not add or remove information1415Text to translate:16${$json.text}1718Return JSON:19{20 "detectedLanguage": "source language",21 "translation": "translated text",22 "confidence": 0.0-1.0,23 "notes": "any translation notes"24}`;Checkpoint
Những translation rules quan trọng nào cần đưa vào prompt?
📧 Email Auto-Translation
1// Code node: Language detection + routing2const body = $json.emailBody;34// Simple detection using OpenAI5const detectPrompt = `6Detect the language of this text. Return only the ISO 639-1 code (e.g., "en", "vi", "ja", "zh").78Text: ${body.substring(0, 500)}910Language code:`;1112return { prompt: detectPrompt, emailBody: body };1// Translation with context preservation2const emailTranslatePrompt = `3Translate this business email from ${$json.sourceLang} to Vietnamese.45Keep:6- Professional tone7- Names unchanged 8- Company names unchanged9- Technical terms in English (in parentheses add Vietnamese)10- Email formatting1112Email:13${$json.emailBody}1415Translation:`;Checkpoint
Khi translate business email, những yếu tố nào cần giữ nguyên?
📄 Batch Document Translation
1// Workflow: Translate multiple documents2// Google Drive Trigger → Read File → Split into chunks → Translate → Merge → Save34// Code node: Smart text splitting5function splitText(text, maxChars = 3000) {6 const paragraphs = text.split('\n\n');7 const chunks = [];8 let current = '';9 10 for (const para of paragraphs) {11 if ((current + para).length > maxChars) {12 if (current) chunks.push(current.trim());13 current = para;14 } else {15 current += '\n\n' + para;16 }17 }18 if (current) chunks.push(current.trim());19 20 return chunks;21}2223const chunks = splitText($json.content);24return chunks.map((chunk, i) => ({25 json: { 26 chunk, 27 index: i, 28 total: chunks.length,29 targetLang: $json.targetLang 30 }31}));Checkpoint
Tại sao cần split text thành chunks trước khi translate?
🧠 Translation Memory
1// Code node: Simple translation memory with Google Sheets2// Saves translated segments for reuse34const segment = $json.originalText;5const translation = $json.translatedText;67// Check if already translated (before calling AI)8// Google Sheets Lookup: search for segment9const cached = $json.cachedTranslation;1011if (cached) {12 return { translation: cached, source: "cache", cost: 0 };13}1415// If not cached, use AI translation then save16return { 17 translation: $json.aiTranslation, 18 source: "ai",19 saveToMemory: true20};Checkpoint
Translation memory giúp tiết kiệm chi phí như thế nào?
🌐 Multi-Language Content Pipeline
1// Translate one piece of content to multiple languages2const languages = ["vi", "ja", "ko", "zh", "th"];34const translations = languages.map(lang => ({5 json: {6 targetLang: lang,7 content: $json.originalContent,8 contentType: $json.contentType9 }10}));1112return translations;- Context matters: Cung cấp context (business email vs casual chat) để translation chính xác hơn
- Glossary: Tạo glossary cho technical terms để đảm bảo nhất quán
- Review: Với content quan trọng, luôn có human review step
- Chunking: Split text dài thành paragraphs, không cắt giữa câu
Checkpoint
Những best practices nào giúp cải thiện chất lượng translation?
📝 Bài Tập Thực Hành
- Build email auto-translator (detect language, translate to Vietnamese)
- Create batch document translation pipeline
- Implement translation memory với Google Sheets
- Build multi-language content pipeline (1 source, 5 languages)
Checkpoint
Bạn đã hoàn thành email auto-translator chưa? Test với ngôn ngữ nào?
🚀 Bài tiếp theo
Content Repurposing — Biến một nội dung thành nhiều định dạng khác nhau với AI.
