MinAI - Về trang chủ
Lý thuyết
10/1330 phút
Đang tải...

Translation Workflows

Xây dựng hệ thống dịch đa ngôn ngữ tự động với AI trong n8n

🌍 Translation Workflows

0

🎯 Mục tiêu bài học

TB5 min

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.

1

🏗️ Translation Architecture

TB5 min
Diagram
Đang vẽ diagram...

Checkpoint

Translation pipeline gồm những bước chính nào?

2

🔍 Basic Translation Workflow

TB5 min
Diagram
Đang vẽ diagram...
JavaScript
1// OpenAI Translation prompt
2const translatePrompt = `
3You are a professional translator. Translate the following text.
4
5Source language: ${$json.sourceLang || "auto-detect"}
6Target language: ${$json.targetLang}
7
8Translation rules:
91. Maintain the original tone and style
102. Use natural, fluent ${$json.targetLang}
113. Keep technical terms in English if more commonly used
124. Preserve formatting (bullet points, paragraphs)
135. Do not add or remove information
14
15Text to translate:
16${$json.text}
17
18Return 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?

3

📧 Email Auto-Translation

TB5 min
Diagram
Đang vẽ diagram...
JavaScript
1// Code node: Language detection + routing
2const body = $json.emailBody;
3
4// Simple detection using OpenAI
5const detectPrompt = `
6Detect the language of this text. Return only the ISO 639-1 code (e.g., "en", "vi", "ja", "zh").
7
8Text: ${body.substring(0, 500)}
9
10Language code:`;
11
12return { prompt: detectPrompt, emailBody: body };
JavaScript
1// Translation with context preservation
2const emailTranslatePrompt = `
3Translate this business email from ${$json.sourceLang} to Vietnamese.
4
5Keep:
6- Professional tone
7- Names unchanged
8- Company names unchanged
9- Technical terms in English (in parentheses add Vietnamese)
10- Email formatting
11
12Email:
13${$json.emailBody}
14
15Translation:`;

Checkpoint

Khi translate business email, những yếu tố nào cần giữ nguyên?

4

📄 Batch Document Translation

TB5 min
JavaScript
1// Workflow: Translate multiple documents
2// Google Drive Trigger → Read File → Split into chunks → Translate → Merge → Save
3
4// Code node: Smart text splitting
5function 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}
22
23const 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?

5

🧠 Translation Memory

TB5 min
JavaScript
1// Code node: Simple translation memory with Google Sheets
2// Saves translated segments for reuse
3
4const segment = $json.originalText;
5const translation = $json.translatedText;
6
7// Check if already translated (before calling AI)
8// Google Sheets Lookup: search for segment
9const cached = $json.cachedTranslation;
10
11if (cached) {
12 return { translation: cached, source: "cache", cost: 0 };
13}
14
15// If not cached, use AI translation then save
16return {
17 translation: $json.aiTranslation,
18 source: "ai",
19 saveToMemory: true
20};

Checkpoint

Translation memory giúp tiết kiệm chi phí như thế nào?

6

🌐 Multi-Language Content Pipeline

TB5 min
JavaScript
1// Translate one piece of content to multiple languages
2const languages = ["vi", "ja", "ko", "zh", "th"];
3
4const translations = languages.map(lang => ({
5 json: {
6 targetLang: lang,
7 content: $json.originalContent,
8 contentType: $json.contentType
9 }
10}));
11
12return translations;
Quality Tips
  • 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?

7

📝 Bài Tập Thực Hành

TB5 min
Exercises
  1. Build email auto-translator (detect language, translate to Vietnamese)
  2. Create batch document translation pipeline
  3. Implement translation memory với Google Sheets
  4. 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.