Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(translate): make 'parent' argument required for all client methods; add 'labels' argument (via synth). #9354

Merged
merged 1 commit into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,12 @@ def translate_text(
self,
contents,
target_language_code,
parent,
mime_type=None,
source_language_code=None,
parent=None,
model=None,
glossary_config=None,
labels=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
Expand All @@ -236,30 +237,37 @@ def translate_text(
>>>
>>> # TODO: Initialize `target_language_code`:
>>> target_language_code = ''
>>> parent = client.location_path('[PROJECT]', '[LOCATION]')
>>>
>>> response = client.translate_text(contents, target_language_code)
>>> response = client.translate_text(contents, target_language_code, parent)

Args:
contents (list[str]): Required. The content of the input in string format.
We recommend the total content be less than 30k codepoints.
Use BatchTranslateText for larger text.
target_language_code (str): Required. The BCP-47 language code to use for translation of the input
text, set to one of the language codes listed in Language Support.
parent (str): Required. Project or location to make a call. Must refer to a caller's
project.

Format: ``projects/{project-id}`` or
``projects/{project-id}/locations/{location-id}``.

For global calls, use ``projects/{project-id}/locations/global`` or
``projects/{project-id}``.

Non-global location is required for requests using AutoML models or
custom glossaries.

Models and glossaries must be within the same region (have same
location-id), otherwise an INVALID\_ARGUMENT (400) error is returned.
mime_type (str): Optional. The format of the source text, for example, "text/html",
"text/plain". If left blank, the MIME type defaults to "text/html".
source_language_code (str): Optional. The BCP-47 language code of the input text if
known, for example, "en-US" or "sr-Latn". Supported language codes are
listed in Language Support. If the source language isn't specified, the API
attempts to identify the source language automatically and returns the
source language within the response.
parent (str): Required. Location to make a regional or global call.

Format: ``projects/{project-id}/locations/{location-id}``.

For global calls, use ``projects/{project-id}/locations/global``.

Models and glossaries must be within the same region (have same
location-id), otherwise an INVALID\_ARGUMENT (400) error is returned.
model (str): Optional. The ``model`` type requested for this translation.

The format depends on model type:
Expand All @@ -282,6 +290,14 @@ def translate_text(

If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.translate_v3beta1.types.TranslateTextGlossaryConfig`
labels (dict[str -> str]): Optional. The labels with user-defined metadata for the request.

Label keys and values can be no longer than 63 characters
(Unicode codepoints), can only contain lowercase letters, numeric
characters, underscores and dashes. International characters are allowed.
Label values are optional. Label keys must start with a letter.

See https://cloud.google.com/translate/docs/labels for more information.
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will
be retried using a default configuration.
Expand Down Expand Up @@ -315,11 +331,12 @@ def translate_text(
request = translation_service_pb2.TranslateTextRequest(
contents=contents,
target_language_code=target_language_code,
parent=parent,
mime_type=mime_type,
source_language_code=source_language_code,
parent=parent,
model=model,
glossary_config=glossary_config,
labels=labels,
)
if metadata is None:
metadata = []
Expand All @@ -340,10 +357,11 @@ def translate_text(

def detect_language(
self,
parent=None,
parent,
model=None,
content=None,
mime_type=None,
labels=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
Expand All @@ -356,14 +374,19 @@ def detect_language(
>>>
>>> client = translate_v3beta1.TranslationServiceClient()
>>>
>>> response = client.detect_language()
>>> parent = client.location_path('[PROJECT]', '[LOCATION]')
>>>
>>> response = client.detect_language(parent)

Args:
parent (str): Required. Location to make a regional or global call.
parent (str): Required. Project or location to make a call. Must refer to a caller's
project.

Format: ``projects/{project-id}/locations/{location-id}``.
Format: ``projects/{project-id}/locations/{location-id}`` or
``projects/{project-id}``.

For global calls, use ``projects/{project-id}/locations/global``.
For global calls, use ``projects/{project-id}/locations/global`` or
``projects/{project-id}``.

Only models within the same region (has same location-id) can be used.
Otherwise an INVALID\_ARGUMENT (400) error is returned.
Expand All @@ -379,6 +402,14 @@ def detect_language(
content (str): The content of the input stored as a string.
mime_type (str): Optional. The format of the source text, for example, "text/html",
"text/plain". If left blank, the MIME type defaults to "text/html".
labels (dict[str -> str]): Optional. The labels with user-defined metadata for the request.

Label keys and values can be no longer than 63 characters
(Unicode codepoints), can only contain lowercase letters, numeric
characters, underscores and dashes. International characters are allowed.
Label values are optional. Label keys must start with a letter.

See https://cloud.google.com/translate/docs/labels for more information.
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will
be retried using a default configuration.
Expand Down Expand Up @@ -414,7 +445,11 @@ def detect_language(
google.api_core.protobuf_helpers.check_oneof(content=content)

request = translation_service_pb2.DetectLanguageRequest(
parent=parent, model=model, content=content, mime_type=mime_type
parent=parent,
model=model,
content=content,
mime_type=mime_type,
labels=labels,
)
if metadata is None:
metadata = []
Expand All @@ -435,7 +470,7 @@ def detect_language(

def get_supported_languages(
self,
parent=None,
parent,
display_language_code=None,
model=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
Expand All @@ -450,14 +485,21 @@ def get_supported_languages(
>>>
>>> client = translate_v3beta1.TranslationServiceClient()
>>>
>>> response = client.get_supported_languages()
>>> parent = client.location_path('[PROJECT]', '[LOCATION]')
>>>
>>> response = client.get_supported_languages(parent)

Args:
parent (str): Required. Location to make a regional or global call.
parent (str): Required. Project or location to make a call. Must refer to a caller's
project.

Format: ``projects/{project-id}/locations/{location-id}``.
Format: ``projects/{project-id}`` or
``projects/{project-id}/locations/{location-id}``.

For global calls, use ``projects/{project-id}/locations/global``.
For global calls, use ``projects/{project-id}/locations/global`` or
``projects/{project-id}``.

Non-global location is required for AutoML models.

Only models within the same region (have same location-id) can be used,
otherwise an INVALID\_ARGUMENT (400) error is returned.
Expand Down Expand Up @@ -529,13 +571,14 @@ def get_supported_languages(

def batch_translate_text(
self,
parent,
source_language_code,
target_language_codes,
input_configs,
output_config,
parent=None,
models=None,
glossaries=None,
labels=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
Expand All @@ -554,6 +597,8 @@ def batch_translate_text(
>>>
>>> client = translate_v3beta1.TranslationServiceClient()
>>>
>>> parent = client.location_path('[PROJECT]', '[LOCATION]')
>>>
>>> # TODO: Initialize `source_language_code`:
>>> source_language_code = ''
>>>
Expand All @@ -566,7 +611,7 @@ def batch_translate_text(
>>> # TODO: Initialize `output_config`:
>>> output_config = {}
>>>
>>> response = client.batch_translate_text(source_language_code, target_language_codes, input_configs, output_config)
>>> response = client.batch_translate_text(parent, source_language_code, target_language_codes, input_configs, output_config)
>>>
>>> def callback(operation_future):
... # Handle result.
Expand All @@ -578,6 +623,15 @@ def batch_translate_text(
>>> metadata = response.metadata()

Args:
parent (str): Required. Location to make a call. Must refer to a caller's project.

Format: ``projects/{project-id}/locations/{location-id}``.

The ``global`` location is not supported for batch translation.

Only AutoML Translation models or glossaries within the same region
(have the same location-id) can be used, otherwise an INVALID\_ARGUMENT
(400) error is returned.
source_language_code (str): Required. Source language code.
target_language_codes (list[str]): Required. Specify up to 10 language codes here.
input_configs (list[Union[dict, ~google.cloud.translate_v3beta1.types.InputConfig]]): Required. Input configurations.
Expand All @@ -593,15 +647,6 @@ def batch_translate_text(

If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.translate_v3beta1.types.OutputConfig`
parent (str): Required. Location to make a regional call.

Format: ``projects/{project-id}/locations/{location-id}``.

The ``global`` location is not supported for batch translation.

Only AutoML Translation models or glossaries within the same region
(have the same location-id) can be used, otherwise an INVALID\_ARGUMENT
(400) error is returned.
models (dict[str -> str]): Optional. The models to use for translation. Map's key is target
language code. Map's value is model name. Value can be a built-in
general model, or an AutoML Translation model.
Expand All @@ -622,6 +667,14 @@ def batch_translate_text(

If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.translate_v3beta1.types.TranslateTextGlossaryConfig`
labels (dict[str -> str]): Optional. The labels with user-defined metadata for the request.

Label keys and values can be no longer than 63 characters
(Unicode codepoints), can only contain lowercase letters, numeric
characters, underscores and dashes. International characters are allowed.
Label values are optional. Label keys must start with a letter.

See https://cloud.google.com/translate/docs/labels for more information.
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will
be retried using a default configuration.
Expand Down Expand Up @@ -653,13 +706,14 @@ def batch_translate_text(
)

request = translation_service_pb2.BatchTranslateTextRequest(
parent=parent,
source_language_code=source_language_code,
target_language_codes=target_language_codes,
input_configs=input_configs,
output_config=output_config,
parent=parent,
models=models,
glossaries=glossaries,
labels=labels,
)
if metadata is None:
metadata = []
Expand Down Expand Up @@ -781,7 +835,7 @@ def create_glossary(

def list_glossaries(
self,
parent=None,
parent,
page_size=None,
filter_=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
Expand All @@ -797,16 +851,18 @@ def list_glossaries(
>>>
>>> client = translate_v3beta1.TranslationServiceClient()
>>>
>>> parent = client.location_path('[PROJECT]', '[LOCATION]')
>>>
>>> # Iterate over all results
>>> for element in client.list_glossaries():
>>> for element in client.list_glossaries(parent):
... # process element
... pass
>>>
>>>
>>> # Alternatively:
>>>
>>> # Iterate over results one page at a time
>>> for page in client.list_glossaries().pages:
>>> for page in client.list_glossaries(parent).pages:
... for element in page:
... # process element
... pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"DeleteGlossary": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
},
Expand Down