Step 1: Chọn nhà cung cấp dịch thuật
Hành động này hoạt động với Trình dịch Azure AI, Dịch AWS và Dịch thuật Google Cloud đằng sau một nền tảng API hợp nhất. Chọn một nhà cung cấp duy nhất cho mỗi lần chạy với đầu vào provider — quy trình làm việc hoạt động giống hệt nhau bất kể nhà cung cấp nào; Chỉ có thông tin đăng nhập khác nhau. Xem Nhà cung cấp dịch thuật để so sánh đầy đủ.
Step 2: Thêm thông tin đăng nhập và quy trình làm việc
Lưu trữ thông tin đăng nhập của nhà cung cấp dưới dạng bí mật kho lưu trữ GitHub, sau đó tạo .github/workflows/translate.yml. Chọn nhà cung cấp của bạn bên dưới để thiết lập cụ thể — phần còn lại của quy trình làm việc giống hệt nhau.
Trình dịch Azure AI
Azure là nhà cung cấp mặc định, vì vậy provider có thể bị bỏ qua. Cung cấp tài nguyên Azure AI Translator trong cổng thông tin Azure, sau đó lưu trữ thông tin đăng nhập của tài nguyên đó:
Lưu trữ chúng dưới dạng bí mật kho lưu trữ
TRANSLATOR_KEY— khóa đăng ký cho tài nguyên.TRANSLATOR_ENDPOINT— URL điểm cuối khu vực.TRANSLATOR_REGION— khu vực Azure của tài nguyên.
Thêm quy trình làm việc
name: translate
on: push: branches: [main] paths: - "src/**/*.en.resx" - "src/**/*.en.json"
permissions: contents: write pull-requests: write
jobs: translate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - id: translate uses: IEvangelist/resource-translator@v3 with: provider: | azure: subscriptionKey: ${{ secrets.TRANSLATOR_KEY }} endpoint: ${{ secrets.TRANSLATOR_ENDPOINT }} region: ${{ secrets.TRANSLATOR_REGION }} sourceLocale: en toLocales: '["fr","de","es"]' - if: steps.translate.outputs.has-new-translations == 'true' uses: peter-evans/create-pull-request@v7 with: title: ${{ steps.translate.outputs.summary-title }} body: ${{ steps.translate.outputs.summary-details }} branch: machine-translationDịch AWS
Đặt provider thành aws. Ưu tiên OIDC qua aws-actions/configure-aws-credentials để không có bí mật tồn tại lâu dài nào được lưu trữ - bước xuất AWS_REGION cho bạn. Để sử dụng khóa tĩnh, hãy lưu trữ:
Lưu trữ chúng dưới dạng bí mật kho lưu trữ
AWS_ACCESS_KEY_ID— ID khóa truy cập AWS của bạn.AWS_SECRET_ACCESS_KEY— khóa truy cập bí mật AWS của bạn.
Một khu vực luôn được yêu cầu - đặt nó bằng awsRegion hoặc biến môi trường AWS_REGION.
Thêm quy trình làm việc
name: translate
on: push: branches: [main] paths: - "src/**/*.en.resx" - "src/**/*.en.json"
permissions: id-token: write # for aws-actions/configure-aws-credentials (OIDC) contents: write pull-requests: write
jobs: translate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - uses: aws-actions/configure-aws-credentials@v4 with: role-to-assume: arn:aws:iam::123456789012:role/gh-actions-translate aws-region: us-east-1 - id: translate uses: IEvangelist/resource-translator@v3 with: provider: | aws: region: us-east-1 # or rely on AWS_REGION from the step above formality: FORMAL brevity: true sourceLocale: en toLocales: '["fr","de","es"]' - if: steps.translate.outputs.has-new-translations == 'true' uses: peter-evans/create-pull-request@v7 with: title: ${{ steps.translate.outputs.summary-title }} body: ${{ steps.translate.outputs.summary-details }} branch: machine-translationDịch thuật Google Cloud
Đặt provider thành google. Xác thực bằng thông tin xác thực JSON tài khoản dịch vụ hoặc khóa API - cung cấp chính xác một:
Lưu trữ chúng dưới dạng bí mật kho lưu trữ
GCP_TRANSLATE_CREDENTIALS— khóa JSON tài khoản dịch vụ (dưới dạng chuỗi JSON).GCP_TRANSLATE_API_KEY— hoặc khoá API Google Cloud.
Một googleProjectId tùy chọn được suy ra từ thông tin xác thực khi bị bỏ qua.
Thêm quy trình làm việc
name: translate
on: push: branches: [main] paths: - "src/**/*.en.resx" - "src/**/*.en.json"
permissions: contents: write pull-requests: write
jobs: translate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - id: translate uses: IEvangelist/resource-translator@v3 with: provider: | google: # Provide EITHER a service-account JSON credential... credentials: ${{ secrets.GCP_TRANSLATE_CREDENTIALS }} # ...OR an API key: # apiKey: ${{ secrets.GCP_TRANSLATE_API_KEY }} model: nmt sourceLocale: en toLocales: '["fr","de","es"]' - if: steps.translate.outputs.has-new-translations == 'true' uses: peter-evans/create-pull-request@v7 with: title: ${{ steps.translate.outputs.summary-title }} body: ${{ steps.translate.outputs.summary-details }} branch: machine-translationStep 3: Cam kết tệp tài nguyên nguồn
Các tệp tài nguyên sử dụng quy ước Name.<sourceLocale>.<ext>. Ví dụ, Greetings.en.resx trở thành Greetings.fr.resx, Greetings.de.resx, v.v. sau khi chạy.
Step 4: Let smart change detection protect your bill
changeDetection defaults to smart and stores a compact .github/resource-translator-state.json manifest in the repo. Commit that file so future runs can reuse stable translations, preserve manual target edits, and send only new, missing, changed, or settings-invalidated keys to the provider. If localized files already exist, run once with snapshotOnly: true to create the manifest without provider calls.
Step 5: Kiểm tra đầu ra
Sau khi quy trình làm việc kết thúc, hành động sẽ hiển thị ba đầu ra mà bạn có thể kết nối vào mô tả PR: summary-title, summary-details và has-new-translations. Nó cũng viết một bản tóm tắt Markdown vào trang việc làm thông qua core.summary.