@@ -214,11 +214,12 @@ def translate_text(
214214 self ,
215215 contents ,
216216 target_language_code ,
217+ parent ,
217218 mime_type = None ,
218219 source_language_code = None ,
219- parent = None ,
220220 model = None ,
221221 glossary_config = None ,
222+ labels = None ,
222223 retry = google .api_core .gapic_v1 .method .DEFAULT ,
223224 timeout = google .api_core .gapic_v1 .method .DEFAULT ,
224225 metadata = None ,
@@ -236,30 +237,37 @@ def translate_text(
236237 >>>
237238 >>> # TODO: Initialize `target_language_code`:
238239 >>> target_language_code = ''
240+ >>> parent = client.location_path('[PROJECT]', '[LOCATION]')
239241 >>>
240- >>> response = client.translate_text(contents, target_language_code)
242+ >>> response = client.translate_text(contents, target_language_code, parent )
241243
242244 Args:
243245 contents (list[str]): Required. The content of the input in string format.
244246 We recommend the total content be less than 30k codepoints.
245247 Use BatchTranslateText for larger text.
246248 target_language_code (str): Required. The BCP-47 language code to use for translation of the input
247249 text, set to one of the language codes listed in Language Support.
250+ parent (str): Required. Project or location to make a call. Must refer to a caller's
251+ project.
252+
253+ Format: ``projects/{project-id}`` or
254+ ``projects/{project-id}/locations/{location-id}``.
255+
256+ For global calls, use ``projects/{project-id}/locations/global`` or
257+ ``projects/{project-id}``.
258+
259+ Non-global location is required for requests using AutoML models or
260+ custom glossaries.
261+
262+ Models and glossaries must be within the same region (have same
263+ location-id), otherwise an INVALID\_ARGUMENT (400) error is returned.
248264 mime_type (str): Optional. The format of the source text, for example, "text/html",
249265 "text/plain". If left blank, the MIME type defaults to "text/html".
250266 source_language_code (str): Optional. The BCP-47 language code of the input text if
251267 known, for example, "en-US" or "sr-Latn". Supported language codes are
252268 listed in Language Support. If the source language isn't specified, the API
253269 attempts to identify the source language automatically and returns the
254270 source language within the response.
255- parent (str): Required. Location to make a regional or global call.
256-
257- Format: ``projects/{project-id}/locations/{location-id}``.
258-
259- For global calls, use ``projects/{project-id}/locations/global``.
260-
261- Models and glossaries must be within the same region (have same
262- location-id), otherwise an INVALID\_ARGUMENT (400) error is returned.
263271 model (str): Optional. The ``model`` type requested for this translation.
264272
265273 The format depends on model type:
@@ -282,6 +290,14 @@ def translate_text(
282290
283291 If a dict is provided, it must be of the same form as the protobuf
284292 message :class:`~google.cloud.translate_v3beta1.types.TranslateTextGlossaryConfig`
293+ labels (dict[str -> str]): Optional. The labels with user-defined metadata for the request.
294+
295+ Label keys and values can be no longer than 63 characters
296+ (Unicode codepoints), can only contain lowercase letters, numeric
297+ characters, underscores and dashes. International characters are allowed.
298+ Label values are optional. Label keys must start with a letter.
299+
300+ See https://cloud.google.com/translate/docs/labels for more information.
285301 retry (Optional[google.api_core.retry.Retry]): A retry object used
286302 to retry requests. If ``None`` is specified, requests will
287303 be retried using a default configuration.
@@ -315,11 +331,12 @@ def translate_text(
315331 request = translation_service_pb2 .TranslateTextRequest (
316332 contents = contents ,
317333 target_language_code = target_language_code ,
334+ parent = parent ,
318335 mime_type = mime_type ,
319336 source_language_code = source_language_code ,
320- parent = parent ,
321337 model = model ,
322338 glossary_config = glossary_config ,
339+ labels = labels ,
323340 )
324341 if metadata is None :
325342 metadata = []
@@ -340,10 +357,11 @@ def translate_text(
340357
341358 def detect_language (
342359 self ,
343- parent = None ,
360+ parent ,
344361 model = None ,
345362 content = None ,
346363 mime_type = None ,
364+ labels = None ,
347365 retry = google .api_core .gapic_v1 .method .DEFAULT ,
348366 timeout = google .api_core .gapic_v1 .method .DEFAULT ,
349367 metadata = None ,
@@ -356,14 +374,19 @@ def detect_language(
356374 >>>
357375 >>> client = translate_v3beta1.TranslationServiceClient()
358376 >>>
359- >>> response = client.detect_language()
377+ >>> parent = client.location_path('[PROJECT]', '[LOCATION]')
378+ >>>
379+ >>> response = client.detect_language(parent)
360380
361381 Args:
362- parent (str): Required. Location to make a regional or global call.
382+ parent (str): Required. Project or location to make a call. Must refer to a caller's
383+ project.
363384
364- Format: ``projects/{project-id}/locations/{location-id}``.
385+ Format: ``projects/{project-id}/locations/{location-id}`` or
386+ ``projects/{project-id}``.
365387
366- For global calls, use ``projects/{project-id}/locations/global``.
388+ For global calls, use ``projects/{project-id}/locations/global`` or
389+ ``projects/{project-id}``.
367390
368391 Only models within the same region (has same location-id) can be used.
369392 Otherwise an INVALID\_ARGUMENT (400) error is returned.
@@ -379,6 +402,14 @@ def detect_language(
379402 content (str): The content of the input stored as a string.
380403 mime_type (str): Optional. The format of the source text, for example, "text/html",
381404 "text/plain". If left blank, the MIME type defaults to "text/html".
405+ labels (dict[str -> str]): Optional. The labels with user-defined metadata for the request.
406+
407+ Label keys and values can be no longer than 63 characters
408+ (Unicode codepoints), can only contain lowercase letters, numeric
409+ characters, underscores and dashes. International characters are allowed.
410+ Label values are optional. Label keys must start with a letter.
411+
412+ See https://cloud.google.com/translate/docs/labels for more information.
382413 retry (Optional[google.api_core.retry.Retry]): A retry object used
383414 to retry requests. If ``None`` is specified, requests will
384415 be retried using a default configuration.
@@ -414,7 +445,11 @@ def detect_language(
414445 google .api_core .protobuf_helpers .check_oneof (content = content )
415446
416447 request = translation_service_pb2 .DetectLanguageRequest (
417- parent = parent , model = model , content = content , mime_type = mime_type
448+ parent = parent ,
449+ model = model ,
450+ content = content ,
451+ mime_type = mime_type ,
452+ labels = labels ,
418453 )
419454 if metadata is None :
420455 metadata = []
@@ -435,7 +470,7 @@ def detect_language(
435470
436471 def get_supported_languages (
437472 self ,
438- parent = None ,
473+ parent ,
439474 display_language_code = None ,
440475 model = None ,
441476 retry = google .api_core .gapic_v1 .method .DEFAULT ,
@@ -450,14 +485,21 @@ def get_supported_languages(
450485 >>>
451486 >>> client = translate_v3beta1.TranslationServiceClient()
452487 >>>
453- >>> response = client.get_supported_languages()
488+ >>> parent = client.location_path('[PROJECT]', '[LOCATION]')
489+ >>>
490+ >>> response = client.get_supported_languages(parent)
454491
455492 Args:
456- parent (str): Required. Location to make a regional or global call.
493+ parent (str): Required. Project or location to make a call. Must refer to a caller's
494+ project.
457495
458- Format: ``projects/{project-id}/locations/{location-id}``.
496+ Format: ``projects/{project-id}`` or
497+ ``projects/{project-id}/locations/{location-id}``.
459498
460- For global calls, use ``projects/{project-id}/locations/global``.
499+ For global calls, use ``projects/{project-id}/locations/global`` or
500+ ``projects/{project-id}``.
501+
502+ Non-global location is required for AutoML models.
461503
462504 Only models within the same region (have same location-id) can be used,
463505 otherwise an INVALID\_ARGUMENT (400) error is returned.
@@ -529,13 +571,14 @@ def get_supported_languages(
529571
530572 def batch_translate_text (
531573 self ,
574+ parent ,
532575 source_language_code ,
533576 target_language_codes ,
534577 input_configs ,
535578 output_config ,
536- parent = None ,
537579 models = None ,
538580 glossaries = None ,
581+ labels = None ,
539582 retry = google .api_core .gapic_v1 .method .DEFAULT ,
540583 timeout = google .api_core .gapic_v1 .method .DEFAULT ,
541584 metadata = None ,
@@ -554,6 +597,8 @@ def batch_translate_text(
554597 >>>
555598 >>> client = translate_v3beta1.TranslationServiceClient()
556599 >>>
600+ >>> parent = client.location_path('[PROJECT]', '[LOCATION]')
601+ >>>
557602 >>> # TODO: Initialize `source_language_code`:
558603 >>> source_language_code = ''
559604 >>>
@@ -566,7 +611,7 @@ def batch_translate_text(
566611 >>> # TODO: Initialize `output_config`:
567612 >>> output_config = {}
568613 >>>
569- >>> response = client.batch_translate_text(source_language_code, target_language_codes, input_configs, output_config)
614+ >>> response = client.batch_translate_text(parent, source_language_code, target_language_codes, input_configs, output_config)
570615 >>>
571616 >>> def callback(operation_future):
572617 ... # Handle result.
@@ -578,6 +623,15 @@ def batch_translate_text(
578623 >>> metadata = response.metadata()
579624
580625 Args:
626+ parent (str): Required. Location to make a call. Must refer to a caller's project.
627+
628+ Format: ``projects/{project-id}/locations/{location-id}``.
629+
630+ The ``global`` location is not supported for batch translation.
631+
632+ Only AutoML Translation models or glossaries within the same region
633+ (have the same location-id) can be used, otherwise an INVALID\_ARGUMENT
634+ (400) error is returned.
581635 source_language_code (str): Required. Source language code.
582636 target_language_codes (list[str]): Required. Specify up to 10 language codes here.
583637 input_configs (list[Union[dict, ~google.cloud.translate_v3beta1.types.InputConfig]]): Required. Input configurations.
@@ -593,15 +647,6 @@ def batch_translate_text(
593647
594648 If a dict is provided, it must be of the same form as the protobuf
595649 message :class:`~google.cloud.translate_v3beta1.types.OutputConfig`
596- parent (str): Required. Location to make a regional call.
597-
598- Format: ``projects/{project-id}/locations/{location-id}``.
599-
600- The ``global`` location is not supported for batch translation.
601-
602- Only AutoML Translation models or glossaries within the same region
603- (have the same location-id) can be used, otherwise an INVALID\_ARGUMENT
604- (400) error is returned.
605650 models (dict[str -> str]): Optional. The models to use for translation. Map's key is target
606651 language code. Map's value is model name. Value can be a built-in
607652 general model, or an AutoML Translation model.
@@ -622,6 +667,14 @@ def batch_translate_text(
622667
623668 If a dict is provided, it must be of the same form as the protobuf
624669 message :class:`~google.cloud.translate_v3beta1.types.TranslateTextGlossaryConfig`
670+ labels (dict[str -> str]): Optional. The labels with user-defined metadata for the request.
671+
672+ Label keys and values can be no longer than 63 characters
673+ (Unicode codepoints), can only contain lowercase letters, numeric
674+ characters, underscores and dashes. International characters are allowed.
675+ Label values are optional. Label keys must start with a letter.
676+
677+ See https://cloud.google.com/translate/docs/labels for more information.
625678 retry (Optional[google.api_core.retry.Retry]): A retry object used
626679 to retry requests. If ``None`` is specified, requests will
627680 be retried using a default configuration.
@@ -653,13 +706,14 @@ def batch_translate_text(
653706 )
654707
655708 request = translation_service_pb2 .BatchTranslateTextRequest (
709+ parent = parent ,
656710 source_language_code = source_language_code ,
657711 target_language_codes = target_language_codes ,
658712 input_configs = input_configs ,
659713 output_config = output_config ,
660- parent = parent ,
661714 models = models ,
662715 glossaries = glossaries ,
716+ labels = labels ,
663717 )
664718 if metadata is None :
665719 metadata = []
@@ -781,7 +835,7 @@ def create_glossary(
781835
782836 def list_glossaries (
783837 self ,
784- parent = None ,
838+ parent ,
785839 page_size = None ,
786840 filter_ = None ,
787841 retry = google .api_core .gapic_v1 .method .DEFAULT ,
@@ -797,16 +851,18 @@ def list_glossaries(
797851 >>>
798852 >>> client = translate_v3beta1.TranslationServiceClient()
799853 >>>
854+ >>> parent = client.location_path('[PROJECT]', '[LOCATION]')
855+ >>>
800856 >>> # Iterate over all results
801- >>> for element in client.list_glossaries():
857+ >>> for element in client.list_glossaries(parent ):
802858 ... # process element
803859 ... pass
804860 >>>
805861 >>>
806862 >>> # Alternatively:
807863 >>>
808864 >>> # Iterate over results one page at a time
809- >>> for page in client.list_glossaries().pages:
865+ >>> for page in client.list_glossaries(parent ).pages:
810866 ... for element in page:
811867 ... # process element
812868 ... pass
0 commit comments