Example usage for com.google.gwt.language.client.translation TranslationCallback TranslationCallback

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

Introduction

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

Prototype

TranslationCallback

Source Link

Usage

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

License:Apache License

/**
 * Creates a "Translate" button./*from w  w w.  ja v a  2 s  . c  o 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;
}