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

Add translate region tags - Do Not Merge #1488

Merged
merged 3 commits into from
May 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions translate/cloud-client/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


def detect_language(text):
# [START translate_detect_language]
"""Detects the text's language."""
translate_client = translate.Client()

Expand All @@ -38,19 +39,23 @@ 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()

results = translate_client.get_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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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__':
Expand Down