Example usage for com.google.gwt.language.client.translation TranslationResult getTranslatedText

List of usage examples for com.google.gwt.language.client.translation TranslationResult getTranslatedText

Introduction

In this page you can find the example usage for com.google.gwt.language.client.translation TranslationResult getTranslatedText.

Prototype

public final native String getTranslatedText() ;

Source Link

Usage

From source file:com.google.gwt.language.sample.hellolanguage.client.TranslationDemo.java

License:Apache License

/**
 * Creates a "Translate" button./*from  ww  w . j  ava2 s.co  m*/
 *
 * @return button
 */
private Button createTranslateButton() {
    Button translateButton = new Button("Translate");
    translateButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            Language src = Language.valueOf(sourceLanguages.getItemText(sourceLanguages.getSelectedIndex()));
            Language dest = Language
                    .valueOf(destinationLanguages.getItemText(destinationLanguages.getSelectedIndex()));

            // Translation API call to translate text
            Translation.translate(inputTextArea.getText(), src, dest, new TranslationCallback() {
                @Override
                protected void onCallback(TranslationResult result) {
                    if (result.getError() == null) {
                        outputDiv.setText(result.getTranslatedText());
                    } else {
                        outputDiv.setText(result.getError().getMessage());
                    }
                }
            });
        }
    });
    return translateButton;
}