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

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

Introduction

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

Prototype

public final native Error getError() ;

Source Link

Usage

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

License:Apache License

/**
 * Creates a "Translate" button.// ww  w. ja  v  a 2 s .com
 *
 * @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;
}