ข้ามไปยังเนื้อหาหลัก

การทำงานร่วมกับ CI/CD

ทำให้การแปลภาษาใน build pipeline ของคุณเป็นแบบอัตโนมัติ

GitHub Actions: ซิงค์เมื่อมีการ Push

เพิ่มการซิงค์การแปลภาษาลงใน build pipeline เดิมของคุณ:

.github/workflows/deploy.yml
jobs:
build:
steps:
- uses: actions/checkout@v4
- run: npm ci
- name: Sync translations
env:
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
run: npx i18n-rosetta sync
- run: npm run build

GitHub Actions: ซิงค์ตามกำหนดเวลา

รันการแปลภาษาตามกำหนดเวลาและ auto-commit:

.github/workflows/i18n-sync.yml
name: Sync translations
on:
schedule:
- cron: '0 6 * * *'
workflow_dispatch:

jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- name: Sync translations
env:
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
run: npx i18n-rosetta sync
- name: Commit updated translations
run: |
git config user.name "i18n-rosetta"
git config user.email "bot@example.com"
git add i18n/ content/ locales/ messages/
git diff --staged --quiet || git commit -m "chore: sync translations"
git push

วิธีการใช้ Google Translate

หากใช้วิธีการ Google Translate ที่มีมาให้ในตัวแทนการใช้ OpenRouter:

- name: Sync translations
env:
GOOGLE_TRANSLATE_API_KEY: ${{ secrets.GOOGLE_TRANSLATE_API_KEY }}
run: npx i18n-rosetta sync

ผู้ให้บริการ LLM โดยตรง

หากใช้วิธีการ openai, anthropic หรือ gemini โดยตรง:

# OpenAI
- name: Sync translations
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: npx i18n-rosetta sync --method openai

# Anthropic
- name: Sync translations
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: npx i18n-rosetta sync --method anthropic

# Gemini (free tier available)
- name: Sync translations
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: npx i18n-rosetta sync --method gemini

DeepL

- name: Sync translations
env:
DEEPL_API_KEY: ${{ secrets.DEEPL_API_KEY }}
run: npx i18n-rosetta sync --method deepl

Remote Translation API

หากใช้ remote translation endpoint (เช่น บริการแปลภาษาที่โฮสต์ไว้):

- name: Sync translations
env:
ROSETTA_API_KEY: ${{ secrets.ROSETTA_API_KEY }}
run: npx i18n-rosetta sync

CI Pipeline แบบสามชั้น

เพื่อให้ครอบคลุม i18n มากที่สุด ให้ควบคุม pipeline ของคุณด้วยเครื่องมือทั้งสามนี้:

jobs:
i18n:
steps:
- uses: actions/checkout@v4
- run: npm ci

# 1. Catch hardcoded strings before they ship
- run: npx i18n-rosetta lint

# 2. Translate missing keys
- run: npx i18n-rosetta sync
env:
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}

# 3. Fail if any locale is incomplete
- run: npx i18n-rosetta audit
ชั้นคำสั่งเมื่อใดวัตถุประสงค์
LintlintPre-commitบล็อกการ commit ที่มี hardcoded strings
SyncsyncPost-commit / CIแปลคีย์ที่ขาดหายไปและมีการเปลี่ยนแปลง
AuditauditBuild stepทำให้การ deploy ล้มเหลวหากมี locale ใดไม่สมบูรณ์

ดูเพิ่มเติม