适用于 Cloud Translation 的连接器

定义用于在工作流内访问 Cloud Translation 的内置函数的 Workflows 连接器。

深入探索

如需查看包含此代码示例的详细文档,请参阅以下内容:

代码示例

YAML

# This workflow demonstrates how to use the Cloud Translate connector.
# The workflow translates some texts and then creates/deletes a glossary.
# Expected successful output: "SUCCESS"

- init:
    assign:
      - project_id: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
      - location_id: "us-central1"
      - glossary_id: "example-glossary-id"
- list_supported_translation:
    call: googleapis.translate.v2.languages.list
    args:
      target: "fr"
- basic_translate:
    call: googleapis.translate.v2.translations.translate
    args:
      q: "hello world"
      target: "fr"
      format: "text"
      source: "en"
- create_glossary:
    call: googleapis.translate.v3.projects.locations.glossaries.create
    args:
      parent: ${"projects/" + project_id + "/locations/" + location_id}
      body:
        name: ${"projects/" + project_id + "/locations/" + location_id + "/glossaries/" + glossary_id}
        inputConfig:
          gcsSource:
            inputUri: "gs://translate-glossary-source/glossary.csv"
        languagePair:
          sourceLanguageCode: "en-US"
          targetLanguageCode: "zh-CN"
- list_glossaries:
    call: googleapis.translate.v3.projects.locations.glossaries.list
    args:
      parent: ${"projects/" + project_id + "/locations/" + location_id}
- delete_glossary:
    call: googleapis.translate.v3.projects.locations.glossaries.delete
    args:
      name: ${"projects/" + project_id + "/locations/" + location_id + "/glossaries/" + glossary_id}
- the_end:
    return: "SUCCESS"

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器