使用 Cloud Translation 連接器執行批次翻譯作業

使用 Cloud Translation 連接器執行批次翻譯。

深入探索

如需包含這個程式碼範例的詳細說明文件,請參閱下列內容:

程式碼範例

YAML

main:
  steps:
  - init:
      assign:
      - projectId: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
      - location: ${sys.get_env("GOOGLE_CLOUD_LOCATION")}
      - inputBucketName: ${projectId + "-input-files"}
      - outputBucketName: ${projectId + "-output-files-" + string(int(sys.now()))}
  - createOutputBucket:
        call: googleapis.storage.v1.buckets.insert
        args:
          project: ${projectId}
          body:
            name: ${outputBucketName}
  - batchTranslateText:
      call: googleapis.translate.v3beta1.projects.locations.batchTranslateText
      args:
          parent: ${"projects/" + projectId + "/locations/" + location}
          body:
              inputConfigs:
                gcsSource:
                  inputUri: ${"gs://" + inputBucketName + "/*"}
              outputConfig:
                  gcsDestination:
                    outputUriPrefix: ${"gs://" + outputBucketName + "/"}
              sourceLanguageCode: "en"
              targetLanguageCodes: ["es", "fr"]
      result: batchTranslateTextResult

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱Google Cloud 範例瀏覽器