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

Translation preprocessors #600

Open
vkosuri opened this issue Jan 21, 2017 · 2 comments
Open

Translation preprocessors #600

vkosuri opened this issue Jan 21, 2017 · 2 comments
Labels

Comments

@vkosuri
Copy link
Collaborator

vkosuri commented Jan 21, 2017

@gunthercox how about adding this feature to Chatterbot?

More information https://cloud.google.com/translate/docs/translating-text#translate-translate-text-python

Any comments?

@gunthercox
Copy link
Owner

This sounds like is might work well as a preprocessor.

@vkosuri
Copy link
Collaborator Author

vkosuri commented Jan 22, 2017

If it is feasible to add preprocesser i will make PR, otherwise i will add this to chatterbot-tricks

def translate_text(chatbot, statement, target):
    """Translates text into the target language.

    Target must be an ISO 639-1 language code.
    See https://g.co/cloud/translate/v2/translate-reference#supported_languages
    """
    from google.cloud import translate
    
    translate_client = translate.Client()

    # Text can also be a sequence of strings, in which case this method
    # will return a sequence of results for each text.
    result = translate_client.translate(
        statement.text,
        target_language=target)
    
    # Input language: result['input']
    # Translated language: result['translatedText']
    # Detected source language: result['detectedSourceLanguage']
    statement.text = str(result['translatedText'])
    return statement

@gunthercox gunthercox changed the title Translate Text adapters Translation preprocessors Jan 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants