airflow.providers.google.cloud.hooks.translate

此模块包含一个 Google Cloud Translate Hook。

异常

WaitOperationNotDoneYetError

等待操作尚未完成错误。

CloudTranslateHook

Google Cloud 翻译 API 的 Hook。

TranslateHook

使用 V3 客户端版本的 Google Cloud 翻译 (高级) 的 Hook。

模块内容

exception airflow.providers.google.cloud.hooks.translate.WaitOperationNotDoneYetError[source]

基类: Exception

等待操作尚未完成错误。

class airflow.providers.google.cloud.hooks.translate.CloudTranslateHook(gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]

基类: airflow.providers.google.common.hooks.base_google.GoogleBaseHook

Google Cloud 翻译 API 的 Hook。

Hook 中所有使用 project_id 的方法必须使用关键字参数调用,而不是位置参数。

get_conn()[source]

检索到 Cloud Translate 的连接。

返回:

Google Cloud Translate 客户端对象。

返回类型:

google.cloud.translate_v2.Client

translate(values, target_language, format_=None, source_language=None, model=None)[source]

翻译一个字符串或字符串列表。

参考 https://cloud.google.com/translate/docs/translating-text

参数:
  • values (str | list[str]) – 要翻译的字符串或字符串列表。

  • target_language (str) – 要将结果翻译成的语言。这是 API 必需的参数,默认使用当前实例的目标语言。

  • format_ – (可选) `text` 或 `html` 之一,用于指定输入文本是纯文本还是 HTML。

  • source_language (str | None) – (可选) 要翻译的文本的语言。

  • model (str | list[str] | None) – (可选) 用于翻译文本的模型,例如 `base` 或 `NMT`。

返回:

返回一个列表,其中包含每个查询值的字典。每个字典通常包含三个键(并非所有情况下都存在)

  • `detectedSourceLanguage`: 检测到的文本语言(以 ISO 639-1 语言代码表示)。

  • `translatedText`: 文本翻译成目标语言的结果。

  • `input`: 对应的输入值。

  • `model`: 用于翻译文本的模型。

如果只传递单个值,则仅返回一个字典。

抛出:

`ValueError` 如果值和翻译的数量不同。

返回类型:

dict

class airflow.providers.google.cloud.hooks.translate.TranslateHook(gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]

基类: airflow.providers.google.common.hooks.base_google.GoogleBaseHook, airflow.providers.google.common.hooks.operation_helpers.OperationHelper

使用 V3 客户端版本的 Google Cloud 翻译 (高级) 的 Hook。

参考相关文档 https://cloud.google.com/translate/docs/editions#advanced

get_client()[source]

检索 TranslationService 客户端。

返回:

Google Cloud Translation Service 客户端对象。

返回类型:

google.cloud.translate_v3.TranslationServiceClient

static wait_for_operation_done(*, operation, timeout=None, initial=3, multiplier=2, maximum=3600)[source]

等待长时间运行的操作完成。

调用 operation.done() 直到成功或超时,遵循指数退避重试策略。参考 `google.api_core.retry.Retry`。其预期用途是在设计上具有空结果(:`google.protobuf.empty_pb2.Empty`)的 `Operation` 实例上。因此,对此类操作调用 operation.result() 会触发异常 `GoogleAPICallError("Unexpected state: Long-running operation had neither response nor error set.")`,即使操作本身完全正常。

static extract_object_id(obj)[source]

返回对象的唯一 ID。

translate_text(*, project_id=PROVIDE_PROJECT_ID, contents, target_language_code, source_language_code=None, mime_type=None, location=None, model=None, transliteration_config=None, glossary_config=None, labels=None, timeout=DEFAULT, metadata=(), retry=DEFAULT)[source]

翻译提供的文本内容。

参数:
  • project_id (str) – 必需。服务所属的 Google Cloud 项目的 ID。

  • contents (collections.abc.Sequence[str]) – 必需。输入内容的字符串格式。建议最大长度为 1024 项,30,000 个码位。

  • mime_type (str | None) – 可选。源文本的格式,如果留空,MIME 类型默认为“text/html”。

  • source_language_code (str | None) – 可选。如果已知输入文本的 ISO-639 语言代码。如果未指定源语言,API 会尝试自动识别源语言并在响应中返回源语言。

  • target_language_code (str) – 必需。用于翻译输入文本的 ISO-639 语言代码

  • location (str | None) – 可选。进行调用的项目或位置。必须引用调用者的项目。如果未指定,则使用“global”。使用 AutoML 模型或自定义词汇表时,需要非 global 位置。模型和词汇表必须位于同一区域(具有相同的 location-id)。

  • model (str | None) –

    可选。此翻译请求的模型类型 `model`。如果未提供,将使用默认的 Google 模型 (NMT)。格式取决于模型类型

    • AutoML Translation 模型: `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`

    • 通用(内置)模型: `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`

    • Translation LLM 模型: `projects/{project-number-or-id}/locations/{location-id}/models/general/translation-llm`

    对于 global(无区域)请求,使用 `location-id` `global`。例如,`projects/{project-number-or-id}/locations/global/models/general/nmt`。

  • glossary_config (google.cloud.translate_v3.types.TranslateTextGlossaryConfig | None) – 可选。要应用的词汇表。词汇表必须位于与模型同一区域(具有相同的 location-id)。

  • transliteration_config (google.cloud.translate_v3.types.TransliterationConfig | None) – 可选。要应用的音译配置。

  • labels (str | None) – 可选。包含用户定义元数据的请求标签。有关更多信息,请参阅 https://cloud.google.com/translate/docs/advanced/labels

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault | None) – 指定哪些错误(如果有)应重试。

  • timeout (float | google.api_core.gapic_v1.method._MethodDefault) – 此请求的超时时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]) – 应随请求一起作为元数据发送的字符串。

返回:

API 响应中的翻译文本结果。

返回类型:

dict

batch_translate_text(*, project_id=PROVIDE_PROJECT_ID, location, source_language_code, target_language_codes, input_configs, output_config, models=None, glossaries=None, labels=None, timeout=DEFAULT, metadata=(), retry=DEFAULT)[source]

翻译大量文本数据。

参数:
返回:

包含批量文本翻译结果的 Operation 对象,结果会随着准备就绪而分批返回。

返回类型:

google.api_core.operation.Operation

create_dataset(*, project_id=PROVIDE_PROJECT_ID, location, dataset, timeout=DEFAULT, metadata=(), retry=DEFAULT)[source]

创建翻译数据集。

参数:
  • dataset (dict | google.cloud.translate_v3.types.automl_translation.Dataset) – 要创建的数据集。如果提供了 dict,它必须与 automl_translation.Dataset 类型对应。

  • project_id (str) – 数据集所在的 Google Cloud 项目 ID。如果未提供,则使用默认 project_id。

  • location (str) – 项目的位置。

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault | None) – 用于重试请求的重试对象。如果指定了 `None`,则不会重试请求。

  • timeout (float | google.api_core.gapic_v1.method._MethodDefault) – 等待请求完成的时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供给方法的额外元数据。

返回:

待创建数据集的 `Operation` 对象。

返回类型:

google.api_core.operation.Operation

get_dataset(dataset_id, project_id, location, retry=DEFAULT, timeout=DEFAULT, metadata=())[source]

检索给定 dataset_id 的数据集。

参数:
  • dataset_id (str) – 要检索的翻译数据集 ID。

  • project_id (str) – 数据集所在的 Google Cloud 项目 ID。如果未提供,则使用默认 project_id。

  • location (str) – 项目的位置。

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用于重试请求的重试对象。如果指定了 `None`,则不会重试请求。

  • timeout (float | google.api_core.gapic_v1.method._MethodDefault) – 等待请求完成的时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供给方法的额外元数据。

返回:

`automl_translation.Dataset` 实例。

返回类型:

google.cloud.translate_v3.types.automl_translation.Dataset

import_dataset_data(dataset_id, location, input_config, project_id=PROVIDE_PROJECT_ID, retry=DEFAULT, timeout=None, metadata=())[source]

将数据导入翻译数据集。

参数:
  • dataset_id (str) – 翻译数据集的 ID。

  • input_config (dict | google.cloud.translate_v3.types.DatasetInputConfig) – 期望的输入位置及其特定于域的语义(如果有)。如果提供了 dict,其形式必须与 protobuf 消息 InputConfig 相同。

  • project_id (str) – 数据集所在的 Google Cloud 项目 ID,如果为 None,则使用默认 project_id。

  • location (str) – 项目的位置。

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用于重试请求的重试对象。如果指定了 `None`,则不会重试请求。

  • timeout (float | None) – 等待请求完成的时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供给方法的额外元数据。

返回:

数据导入的 `Operation` 对象。

返回类型:

google.api_core.operation.Operation

list_datasets(project_id, location, retry=DEFAULT, timeout=DEFAULT, metadata=())[source]

列出项目中的翻译数据集。

参数:
  • project_id (str) – 数据集所在的 Google Cloud 项目 ID。如果未提供,则使用默认 project_id。

  • location (str) – 项目的位置。

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用于重试请求的重试对象。如果指定了 `None`,则不会重试请求。

  • timeout (float | google.api_core.gapic_v1.method._MethodDefault) – 等待请求完成的时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供给方法的额外元数据。

返回:

pagers.ListDatasetsPager 实例,用于检索数据集列表的可迭代对象。

返回类型:

google.cloud.translate_v3.services.translation_service.pagers.ListDatasetsPager

delete_dataset(dataset_id, project_id, location, retry=DEFAULT, timeout=None, metadata=())[source]

删除翻译数据集及其所有内容。

参数:
  • dataset_id (str) – 要删除的数据集的 ID。

  • project_id (str) – 数据集所在的 Google Cloud 项目 ID。如果未提供,则使用默认 project_id。

  • location (str) – 项目的位置。

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用于重试请求的重试对象。如果指定了 `None`,则不会重试请求。

  • timeout (float | None) – 等待请求完成的时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供给方法的额外元数据。

返回:

包含数据集删除结果的 Operation 对象(操作完成后)。

返回类型:

google.api_core.operation.Operation

create_model(dataset_id, display_name, project_id, location, retry=DEFAULT, timeout=None, metadata=())[source]

通过提供的翻译数据集训练创建原生模型。

参数:
  • dataset_id (str) – 用于模型训练的数据集的 ID。

  • display_name (str) – 已训练模型的显示名称。可包含 A-Z 和 a-z、下划线 (_) 以及 ASCII 数字 0-9。

  • project_id (str) – 数据集所在的 Google Cloud 项目 ID。如果未提供,则使用默认 project_id。

  • location (str) – 项目的位置。

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用于重试请求的重试对象。如果指定了 `None`,则不会重试请求。

  • timeout (float | None) – 等待请求完成的时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供给方法的额外元数据。

返回:

包含模型创建结果的 Operation 对象(操作完成后)。

返回类型:

google.api_core.operation.Operation

get_model(model_id, project_id, location, retry=DEFAULT, timeout=DEFAULT, metadata=())[source]

根据给定的 model_id 检索数据集。

参数:
  • model_id (str) – 要检索的翻译模型的 ID。

  • project_id (str) – 数据集所在的 Google Cloud 项目 ID。如果未提供,则使用默认 project_id。

  • location (str) – 项目的位置。

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用于重试请求的重试对象。如果指定了 `None`,则不会重试请求。

  • timeout (float | google.api_core.gapic_v1.method._MethodDefault) – 等待请求完成的时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供给方法的额外元数据。

返回:

automl_translation.Model 实例。

返回类型:

google.cloud.translate_v3.types.automl_translation.Model

list_models(project_id, location, filter_str=None, page_size=None, retry=DEFAULT, timeout=DEFAULT, metadata=())[source]

列出项目中的翻译模型。

参数:
  • project_id (str) – 模型所在的 Google Cloud 项目的 ID。如果未提供,则使用默认的 project_id。

  • location (str) – 项目的位置。

  • filter_str (str | None) – 用于过滤将返回模型的可选表达式。支持的过滤器:dataset_id=${dataset_id}

  • page_size (int | None) – 可选的自定义页面大小值。服务器返回的结果可能少于请求的数量。

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用于重试请求的重试对象。如果指定了 `None`,则不会重试请求。

  • timeout (float | google.api_core.gapic_v1.method._MethodDefault) – 等待请求完成的时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供给方法的额外元数据。

返回:

pagers.ListDatasetsPager 实例,用于检索数据集列表的可迭代对象。

返回类型:

google.cloud.translate_v3.services.translation_service.pagers.ListModelsPager

delete_model(model_id, project_id, location, retry=DEFAULT, timeout=None, metadata=())[source]

删除翻译模型及其所有内容。

参数:
  • model_id (str) – 要删除的模型 ID。

  • project_id (str) – 数据集所在的 Google Cloud 项目 ID。如果未提供,则使用默认 project_id。

  • location (str) – 项目的位置。

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用于重试请求的重试对象。如果指定了 `None`,则不会重试请求。

  • timeout (float | None) – 等待请求完成的时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供给方法的额外元数据。

返回:

包含数据集删除结果的 Operation 对象(操作完成后)。

返回类型:

google.api_core.operation.Operation

translate_document(*, project_id=PROVIDE_PROJECT_ID, source_language_code=None, target_language_code, location=None, document_input_config, document_output_config=None, customized_attribution=None, is_translate_native_pdf_only=False, enable_shadow_removal_native_pdf=False, enable_rotation_correction=False, model=None, glossary_config=None, labels=None, timeout=DEFAULT, metadata=(), retry=DEFAULT)[source]

翻译提供的文档。

参数:
  • project_id (str) – 必需。服务所属的 Google Cloud 项目的 ID。

  • source_language_code (str | None) – 可选。如果已知输入文档文本的 ISO-639 语言代码。如果未指定源语言,API 会尝试自动识别源语言并在响应中返回源语言。

  • target_language_code (str) – 必需。用于翻译输入文档文本的 ISO-639 语言代码。

  • location (str | None) – 可选。进行调用的项目或位置。必须引用调用者的项目。如果未指定,则使用“global”。使用 AutoML 模型或自定义词汇表时,需要非 global 位置。模型和词汇表必须位于同一区域(具有相同的 location-id)。

  • document_input_config (google.cloud.translate_v3.types.DocumentInputConfig | dict) – 文档翻译请求的输入配置。

  • document_output_config (google.cloud.translate_v3.types.DocumentOutputConfig | dict | None) – 可选。文档翻译请求的输出配置。如果未提供,则翻译后的文件仅通过字节流返回,并且其输出 MIME 类型将与输入文件的 MIME 类型相同。

  • customized_attribution (str | None) – 可选。此标记用于支持用户自定义归属。如果未提供,默认值为 Machine Translated by Google。自定义归属应遵循 https://cloud.google.com/translate/attribution#attribution_and_logos 中的规则。

  • is_translate_native_pdf_only (bool) – 可选。面向外部客户的参数。如果为 true,则在线原生 PDF 翻译的页面限制为 300 页,并且仅翻译原生 PDF 页面。

  • enable_shadow_removal_native_pdf (bool) – 可选。如果为 true,则使用文本移除服务器移除原生 PDF 翻译中背景图像上的阴影文本。阴影移除功能仅在 is_translate_native_pdf_onlypdf_native_only 都为 False 时启用。

  • enable_rotation_correction (bool) – 可选。如果为 true,则在 DVS 中启用自动旋转校正。

  • model (str | None) –

    可选。此翻译请求的模型类型 `model`。如果未提供,将使用默认的 Google 模型 (NMT)。格式取决于模型类型

    • AutoML Translation 模型: `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`

    • 通用(内置)模型:projects/{project-number-or-id}/locations/{location-id}/models/general/nmt,

    如果未提供,则使用默认的 Google 模型 (NMT) 进行翻译。

  • glossary_config (google.cloud.translate_v3.types.TranslateTextGlossaryConfig | None) – 可选。要应用的词汇表。词汇表必须位于与模型同一区域(具有相同的 location-id)。

  • labels (str | None) – 可选。包含用户定义元数据的请求标签。有关更多信息,请参阅 https://cloud.google.com/translate/docs/advanced/labels

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault | None) – 指定哪些错误(如果有)应重试。

  • timeout (float | google.api_core.gapic_v1.method._MethodDefault) – 此请求的超时时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]) – 应随请求一起作为元数据发送的字符串。

返回:

API 响应中的文档翻译结果。

返回类型:

google.cloud.translate_v3.types.TranslateDocumentResponse

batch_translate_document(*, project_id=PROVIDE_PROJECT_ID, source_language_code, target_language_codes=None, location=None, input_configs, output_config, customized_attribution=None, format_conversions=None, enable_shadow_removal_native_pdf=False, enable_rotation_correction=False, models=None, glossaries=None, timeout=DEFAULT, metadata=(), retry=DEFAULT)[source]

根据提供的配置批量翻译文档。

参数:
  • project_id (str) – 必需。服务所属的 Google Cloud 项目的 ID。

  • source_language_code (str) – 可选。如果已知输入文本的 ISO-639 语言代码。如果未指定源语言,API 会尝试自动识别源语言并在响应中返回源语言。

  • target_language_codes (collections.abc.MutableSequence[str] | None) – 必需。用于翻译输入文档的 ISO-639 语言代码。此处最多可指定 10 个语言代码。

  • location (str | None) – 可选。进行调用的项目或位置。必须引用调用者的项目。如果未指定,则使用“global”。使用 AutoML 模型或自定义词汇表时,需要非 global 位置。模型和词汇表必须位于同一区域(具有相同的 location-id)。

  • input_configs (collections.abc.MutableSequence[google.cloud.translate_v3.types.BatchDocumentInputConfig | dict]) – 输入配置。匹配的文件总数应 <= 100。要翻译的总内容大小应 <= 1 亿 Unicode 码点。文件必须使用 UTF-8 编码。

  • output_config (google.cloud.translate_v3.types.BatchDocumentOutputConfig | dict) – 输出配置。如果两个输入配置匹配到同一个文件(即相同的输入路径),则不会为重复输入生成输出。

  • format_conversions (collections.abc.MutableMapping[str, str] | None) –

    可选。应用于所有输入文件的文件格式转换映射。映射键是原始 mime_type。映射值是翻译文档的目标 mime_type。支持的文件格式转换包括

    • application/pdfapplication/vnd.openxmlformats-officedocument.wordprocessingml.document

    如果未指定,输出文件将与原始文件格式相同。

  • customized_attribution (str | None) – 可选。此标记用于支持用户自定义归属。如果未提供,默认值为 Machine Translated by Google。自定义归属应遵循 https://cloud.google.com/translate/attribution#attribution_and_logos 中的规则。

  • enable_shadow_removal_native_pdf (bool) – 可选。如果为 true,则使用文本移除服务器移除原生 PDF 翻译中背景图像上的阴影文本。阴影移除功能仅在 is_translate_native_pdf_onlypdf_native_only 都为 False 时启用。

  • enable_rotation_correction (bool) – 可选。如果为 true,则在 DVS 中启用自动旋转校正。

  • models (collections.abc.MutableMapping[str, str] | None) –

    可选。用于翻译的模型。映射的键是目标语言代码。映射的值是模型名称。值可以是内置通用模型,也可以是 AutoML Translation 模型。值格式取决于模型类型

    • AutoML Translation 模型: `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`

    • 通用(内置)模型:projects/{project-number-or-id}/locations/{location-id}/models/general/nmt,

    如果映射为空或未针对某个语言对请求特定模型,则使用默认的 Google 模型 (NMT)。

  • glossaries (collections.abc.MutableMapping[str, google.cloud.translate_v3.types.TranslateTextGlossaryConfig] | None) – 要应用的词汇表。以目标语言代码为键。

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault | None) – 指定哪些错误(如果有)应重试。

  • timeout (float | google.api_core.gapic_v1.method._MethodDefault) – 此请求的超时时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]) – 应随请求一起作为元数据发送的字符串。

返回:

API 响应中的批量文档翻译结果。

返回类型:

google.api_core.operation.Operation

create_glossary(project_id, location, glossary_id, input_config, language_pair=None, language_codes_set=None, retry=DEFAULT, timeout=None, metadata=())[source]

从输入源文件创建词汇表资源。

参数:
返回:

包含词汇表创建结果的 Operation 对象。

返回类型:

google.api_core.operation.Operation

get_glossary(project_id, location, glossary_id, retry=DEFAULT, timeout=None, metadata=())[source]

根据给定的 ID 获取词汇表项目数据。

glossary_id 是词汇表名称的子字符串,遵循以下格式:projects/{project-number-or-id}/locations/{location-id}/glossaries/{glossary-id}

参数:
  • project_id (str) – 数据集所在的 Google Cloud 项目 ID。如果未提供,则使用默认 project_id。

  • location (str) – 项目的位置。

  • glossary_id (str) – 用户指定的 ID,用于构建词汇表资源名称。

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用于重试请求的重试对象。如果指定了 `None`,则不会重试请求。

  • timeout (float | None) – 等待请求完成的时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供给方法的额外元数据。

返回:

获取到的词汇表项目。

返回类型:

google.cloud.translate_v3.types.translation_service.Glossary

update_glossary(glossary, new_display_name=None, new_input_config=None, retry=DEFAULT, timeout=None, metadata=())[source]

使用提供的值更新词汇表项目。

只允许更新 display_nameinput_config 字段。

参数:
返回:

包含词汇表更新结果的 Operation 对象。

返回类型:

google.api_core.operation.Operation

list_glossaries(project_id, location, page_size=None, page_token=None, filter_str=None, retry=DEFAULT, timeout=None, metadata=())[source]

获取可用词汇表列表。

参数:
  • project_id (str) – 数据集所在的 Google Cloud 项目 ID。如果未提供,则使用默认 project_id。

  • location (str) – 项目的位置。

  • page_size (int | None) – 请求的页面大小,如果未设置,则服务器使用适当的默认值。

  • page_token (str | None) – 标识服务器应返回的结果页面的令牌。如果 page_token 为空或缺失,则返回第一页。

  • filter_str (str | None) – 指定列表操作约束的过滤器。通过 “key=value” 格式指定约束,其中 key 必须是 srctgt,而 value 必须是有效的语言代码。对于多个限制,使用 “AND”(仅大写)连接它们,例如:src=en-US AND tgt=zh-CN。请注意,这里使用的是精确匹配,这意味着使用 'en-US' 和 'en' 可能会得到不同的结果,这取决于您创建词汇表时使用的语言代码。对于单向词汇表,srctgt 分别对源语言和目标语言代码添加限制。对于等效术语集词汇表,src 和/或 tgt 对术语集添加限制。例如:src=en-US AND tgt=zh-CN 将只选取源语言代码精确匹配 en-US 且目标语言代码精确匹配 zh-CN 的单向词汇表,但所有在其语言集中包含 en-USzh-CN 的等效术语集词汇表都将被选取。如果缺失,则不执行过滤。

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用于重试请求的重试对象。如果指定了 `None`,则不会重试请求。

  • timeout (float | None) – 等待请求完成的时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供给方法的额外元数据。

返回:

词汇表列表分页器对象。

返回类型:

google.cloud.translate_v3.services.translation_service.pagers.ListGlossariesPager

delete_glossary(project_id, location, glossary_id, retry=DEFAULT, timeout=None, metadata=())[source]

通过给定 ID 删除词汇表项。

参数:
  • project_id (str) – 数据集所在的 Google Cloud 项目 ID。如果未提供,则使用默认 project_id。

  • location (str) – 项目的位置。

  • glossary_id (str) – 要删除的词汇表 ID。

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – 用于重试请求的重试对象。如果指定了 `None`,则不会重试请求。

  • timeout (float | None) – 等待请求完成的时间(秒)。请注意,如果指定了 `retry`,则超时适用于每次单独的尝试。

  • metadata (collections.abc.Sequence[tuple[str, str]]]) – 提供给方法的额外元数据。

返回:

Operation 包含词汇表删除结果。

返回类型:

google.api_core.operation.Operation

此条目是否有用?