diff --git a/samples/snippets/snippets.py b/samples/snippets/snippets.py index 91aef63d..b5719d23 100644 --- a/samples/snippets/snippets.py +++ b/samples/snippets/snippets.py @@ -28,6 +28,7 @@ def detect_language(text): + # [START translate_detect_language] """Detects the text's language.""" translate_client = translate.Client() @@ -38,9 +39,11 @@ def detect_language(text): print('Text: {}'.format(text)) print('Confidence: {}'.format(result['confidence'])) print('Language: {}'.format(result['language'])) + # [END translate_detect_language] def list_languages(): + # [START translate_list_codes] """Lists all available languages.""" translate_client = translate.Client() @@ -48,9 +51,11 @@ def list_languages(): for language in results: print(u'{name} ({language})'.format(**language)) + # [END translate_list_codes] def list_languages_with_target(target): + # [START translate_list_language_names] """Lists all available languages and localizes them to the target language. Target must be an ISO 639-1 language code. @@ -62,9 +67,11 @@ def list_languages_with_target(target): for language in results: print(u'{name} ({language})'.format(**language)) + # [END translate_list_language_names] def translate_text_with_model(target, text, model=translate.NMT): + # [START translate_text_with_model] """Translates text into the target language. Make sure your project is whitelisted. @@ -86,9 +93,11 @@ def translate_text_with_model(target, text, model=translate.NMT): print(u'Translation: {}'.format(result['translatedText'])) print(u'Detected source language: {}'.format( result['detectedSourceLanguage'])) + # [END translate_text_with_model] def translate_text(target, text): + # [START translate_translate_text] """Translates text into the target language. Target must be an ISO 639-1 language code. @@ -108,6 +117,7 @@ def translate_text(target, text): print(u'Translation: {}'.format(result['translatedText'])) print(u'Detected source language: {}'.format( result['detectedSourceLanguage'])) + # [END translate_translate_text] if __name__ == '__main__':