Commits

Anonymous committed 4b4c8b6

I18N: all messages are loaded from the 'WebAnnotatorMessages.json' file by the 'LoadMessages' action.

  • Participants
  • Parent commits c37eb5c

Comments (0)

Files changed (6)

File org.mandriva.annotator/org.mandriva.annotator.gwtapp/src/main/java/org/mandriva/annotator/gwtapp/client/WebAnnotatorClientApp.java

 import org.mandriva.annotator.bookmarklet.client.AbstractBookmarklet;
 import org.mandriva.annotator.bookmarklet.client.XdmSocket;
 
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
 /**
  * @author kotelnikov
  */
 
     @Override
     protected IBookmarkletApplication newApplication(final XdmSocket fetcher) {
-        WebAnnotatorDialogBox app = new WebAnnotatorDialogBox(fetcher);
+        IBookmarkletApplication app = new IBookmarkletApplication() {
+            WebAnnotatorDialogBox fDialogBox;
+
+            WebAnnotatorResources fResources;
+
+            public void onActivate() {
+                if (fResources == null) {
+                    JavaScriptObject request = JavaScriptObject
+                        .createObject()
+                        .cast();
+                    fetcher.postMessage(
+                        "LoadMessages",
+                        request,
+                        3 * 60 * 1000 /* 3 min */,
+                        new AsyncCallback<JavaScriptObject>() {
+                            public void onFailure(Throwable caught) {
+                                String msg = "Error! "
+                                    + "Can not load internationalization messages.";
+                                GWT.log(msg, caught);
+                                Window.alert(msg + caught.toString());
+                            }
+
+                            public void onSuccess(JavaScriptObject result) {
+                                fResources = WebAnnotatorResources
+                                    .create(result);
+                                showDialogBox(fResources);
+                            }
+                        });
+
+                } else {
+                    showDialogBox(fResources);
+                }
+            }
+
+            public void showDialogBox(WebAnnotatorResources resources) {
+                if (fDialogBox == null) {
+                    fDialogBox = new WebAnnotatorDialogBox(
+                        resources,
+                        resources,
+                        fetcher);
+                }
+                fDialogBox.onActivate();
+            }
+        };
         return app;
     }
 }

File org.mandriva.annotator/org.mandriva.annotator.gwtapp/src/main/java/org/mandriva/annotator/gwtapp/client/WebAnnotatorDialogBox.java

 package org.mandriva.annotator.gwtapp.client;
 
-import org.mandriva.annotator.bookmarklet.client.AbstractBookmarklet.IBookmarkletApplication;
 import org.mandriva.annotator.bookmarklet.client.XdmSocket;
 import org.mandriva.annotator.gwtapp.client.model.Annotation;
 import org.mandriva.annotator.gwtapp.client.model.AnnotationLoadRequest;
 /**
  * @author kotelnikov
  */
-public class WebAnnotatorDialogBox implements IBookmarkletApplication {
+public class WebAnnotatorDialogBox {
 
     public static abstract class Callback<R extends JavaScriptObject>
         implements
         }
     }
 
+    public static interface IDialogBoxResources {
+
+        // "Close"
+        String btnClose();
+
+        // "Revert"
+        String btnRevert();
+
+        // "Save"
+        String btnSave();
+
+        // "25em"
+        String dialogScrollHeight();
+
+        // "35em"
+        String dialogScrollWidth();
+
+        // "Web Page Annotator"
+        String dialogTitle();
+
+        // "Annotation loading..."
+        String msgAnnotationLoading();
+
+        // "The annotation was successfully saved."
+        String msgAnnotationSaved();
+
+        // "Save annotation..."
+        String msgAnnotationSaving();
+
+        // "Loading data types..."
+        String msgLoadDataTypes();
+
+        // "Loading suggestions..."
+        String msgLoadSuggestions();
+
+    }
+
     static {
         SelectionTracker.setElementFilter(new IElementFilter() {
             public boolean accept(Element e) {
         }
     };
 
-    private WebAnnotatorPanel fPanel = new WebAnnotatorPanel();
+    private WebAnnotatorPanel fPanel;
+
+    private IDialogBoxResources fResources;
 
     private Button fRevertButton;
 
     private Button fSaveButton;
 
-    public WebAnnotatorDialogBox(XdmSocket fetcher) {
+    public WebAnnotatorDialogBox(
+        WebAnnotatorPanel.IResources editorResources,
+        IDialogBoxResources dialogBoxResources,
+        XdmSocket fetcher) {
+        fPanel = new WebAnnotatorPanel(editorResources);
+        fResources = dialogBoxResources;
         fFetcher = fetcher;
-        fDialogBox.setTitle("Web Page Annotator");
-        fDialogBox.setScrollerWidth("35em");
-        fDialogBox.setScrollerHeight("25em");
+        fDialogBox.setTitle(fResources.dialogTitle());
+        fDialogBox.setScrollerWidth(fResources.dialogScrollWidth());
+        fDialogBox.setScrollerHeight(fResources.dialogScrollHeight());
         fDialogBox.addTool(fMessageBox);
         fDialogBox.addWidget1(fPanel);
-        fSaveButton = fDialogBox.addButton("Save", new ClickHandler() {
-            public void onClick(ClickEvent event) {
-                save();
-            }
-        });
-        fRevertButton = fDialogBox.addButton("Revert", new ClickHandler() {
-            public void onClick(ClickEvent event) {
-                revert();
-            }
-        });
-        fDialogBox.addButton("Close", new ClickHandler() {
+
+        fSaveButton = fDialogBox.addButton(
+            fResources.btnSave(),
+            new ClickHandler() {
+                public void onClick(ClickEvent event) {
+                    save();
+                }
+            });
+        fRevertButton = fDialogBox.addButton(
+            fResources.btnRevert(),
+            new ClickHandler() {
+                public void onClick(ClickEvent event) {
+                    revert();
+                }
+            });
+        fDialogBox.addButton(fResources.btnClose(), new ClickHandler() {
             public void onClick(ClickEvent event) {
                 fDialogBox.hide();
             }
             String url = getPageUrl();
             AnnotationLoadRequest data = AnnotationLoadRequest.create(url);
             call(
-                "Annotation loading...",
+                fResources.msgAnnotationLoading(),
                 "LoadAnnotation",
                 data,
                 new Callback<Annotation>() {
     private void loadSuggestions(String text) {
         SuggestionsRequest o = SuggestionsRequest.create(text);
         call(
-            "Loading suggestions...",
+            fResources.msgLoadSuggestions(),
             "LoadSuggestions",
             o,
             new Callback<SuggestionsResult>() {
         if (!fActivated) {
             LoadTypesRequest o = LoadTypesRequest.create();
             call(
-                "Loading data types...",
+                fResources.msgLoadDataTypes(),
                 "LoadTypes",
                 o,
                 new Callback<LoadTypesResult>() {
     public void save() {
         Annotation data = getAnnotation();
         call(
-            "Save annotation...",
+            fResources.msgAnnotationSaving(),
             "SaveAnnotation",
             data,
             new Callback<Annotation>() {
                 public void onSuccess(Annotation result) {
                     setAnnotation(result);
                     fMessageBox.showTmpMessage(
-                        "The annotation was successfully saved.",
+                        fResources.msgAnnotationSaved(),
                         2000);
                 }
             });

File org.mandriva.annotator/org.mandriva.annotator.gwtapp/src/main/java/org/mandriva/annotator/gwtapp/client/WebAnnotatorPanel.java

     implements
     HasValueChangeHandlers<WebAnnotatorPanel> {
 
+    public interface IResources {
+
+        // "Append selected text"
+        String labelAppendSelectedText();
+
+        // "Description:"
+        String labelDescription();
+
+        // "Relations:"
+        String labelRelations();
+
+        // "Suggested relations:"
+        String labelSuggestedRelations();
+
+        // "Title:"
+        String labelTitle();
+
+        // "Type:"
+        String labelType();
+
+        // "URL:"
+        String labelUrl();
+
+        // "Nothing was found."
+        String msgNoSuggestions();
+
+    }
+
     private HTML fAddDescription = new HTML();
 
     private boolean fAddDescriptionEnabled;
 
     private Set<Entity> fRelatedEntitiesSet = new HashSet<Entity>();
 
+    private IResources fResources;
+
     private String fSelection;
 
     private EntitiesPanel fSuggestedEntities = new EntitiesPanel(false);
 
     private TextBox fUrl = new TextBox();
 
-    public WebAnnotatorPanel() {
+    public WebAnnotatorPanel(IResources resources) {
         initWidget(fPanel);
+        fResources = resources;
         ChangeHandler changeHandler = new ChangeHandler() {
             public void onChange(ChangeEvent event) {
                 firePanelChangedEvent();
         fUrl.addChangeHandler(changeHandler);
         fDescriptionPanel.addChangeHandler(changeHandler);
 
-        addField("Type:", fType);
-        addField("Title:", fTitle);
-        addField("URL:", fUrl);
+        addField(fResources.labelType(), fType);
+        addField(fResources.labelTitle(), fTitle);
+        addField(fResources.labelUrl(), fUrl);
         {
             FlowPanel row = addRowContainer();
             HTML titleWidget = new HTML();
-            formatLabelField(titleWidget, "Description:");
+            formatLabelField(titleWidget, fResources.labelDescription());
             row.add(titleWidget);
             row.add(fDescriptionPanel);
             fDescriptionPanel.setHeight("7em");
         {
             FlowPanel panel = new FlowPanel();
             panel.add(fRelatedEntities);
-            addField("Relations:", panel);
-
+            addField(fResources.labelRelations(), panel);
             // Button addRelatedEntity = getNewRelatedEntityButton();
             // panel.add(addRelatedEntity);
         }
             row.add(fSuggestedEntitiesTitle);
             formatLabelField(fSuggestedEntitiesTitle, "");
             row.add(fSuggestedEntities);
-            fSuggestedEntities.setEmptyListMessage("Nothing was found.");
+
+            fSuggestedEntities.setEmptyListMessage(fResources
+                .msgNoSuggestions());
             fSuggestedEntities.setWidth("100%");
             fSuggestedEntities
                 .addSelectionHandler(new SelectionHandler<Entity>() {
                 });
         }
 
-        formatLabelField(fSuggestedEntitiesTitle, "Suggested relations:");
+        formatLabelField(
+            fSuggestedEntitiesTitle,
+            fResources.labelSuggestedRelations());
         SelectionTracker.INSTANCE.addListener(new ISelectionListener() {
 
             public void onSelectionChanged(String selection) {
     }
 
     protected void setAddDescriptionButtonEnabled(boolean enabled) {
-        String message = "Append selected text";
+        String message = fResources.labelAppendSelectedText();
         if (enabled) {
             fAddDescription.setHTML("<a href='javascript:void(0);'>"
                 + message

File org.mandriva.annotator/org.mandriva.annotator.gwtapp/src/main/java/org/mandriva/annotator/gwtapp/client/WebAnnotatorResources.java

+/**
+ * 
+ */
+package org.mandriva.annotator.gwtapp.client;
+
+import org.mandriva.annotator.gwtapp.client.model.DataObject;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+/**
+ * @author kotelnikov
+ */
+
+// From: public final String (\w+)\(\)\s*\{\n\s+.*\n\s+return null;
+// To: public final String $1() {\n return get("$1", "$1");
+public final class WebAnnotatorResources extends DataObject
+    implements
+    WebAnnotatorPanel.IResources,
+    WebAnnotatorDialogBox.IDialogBoxResources {
+
+    public final static WebAnnotatorResources create(JavaScriptObject obj) {
+        return obj.cast();
+    }
+
+    /**
+     * 
+     */
+    protected WebAnnotatorResources() {
+    }
+
+    public final String btnClose() {
+        return get("btnClose", "Close");
+    }
+
+    public final String btnRevert() {
+        return get("btnRevert", "Revert");
+    }
+
+    public final String btnSave() {
+        return get("btnSave", "Save");
+    }
+
+    public final String dialogScrollHeight() {
+        return get("dialogScrollHeight", "25em");
+    }
+
+    public final String dialogScrollWidth() {
+        return get("dialogScrollWidth", "35em");
+    }
+
+    public final String dialogTitle() {
+        return get("dialogTitle", "Web Page Annotator");
+    }
+
+    private final native String get(String key, String defaultValue) /*-{
+        var val = this[key];
+        if (!val) {
+        val = defaultValue;
+        }
+        return val;
+    }-*/;
+
+    public final String labelAppendSelectedText() {
+        return get("labelAppendSelectedText", "Append selected text");
+    }
+
+    public final String labelDescription() {
+        return get("labelDescription", "Description:");
+    }
+
+    public final String labelRelations() {
+        return get("labelRelations", "Relations:");
+    }
+
+    public final String labelSuggestedRelations() {
+        return get("labelSuggestedRelations", "Suggested relations:");
+    }
+
+    public final String labelTitle() {
+        return get("labelTitle", "Title:");
+    }
+
+    public final String labelType() {
+        return get("labelType", "Type:");
+    }
+
+    public final String labelUrl() {
+        return get("labelUrl", "Page URL:");
+    }
+
+    public final String msgAnnotationLoading() {
+        return get("msgAnnotationLoading", "Annotation loading...");
+    }
+
+    public final String msgAnnotationSaved() {
+        return get(
+            "msgAnnotationSaved",
+            "The annotation was successfully saved.");
+    }
+
+    public final String msgAnnotationSaving() {
+        return get("msgAnnotationSaving", "Save annotation...");
+    }
+
+    public final String msgLoadDataTypes() {
+        return get("msgLoadDataTypes", "Loading data types...");
+    }
+
+    public final String msgLoadSuggestions() {
+        return get("msgLoadSuggestions", "Loading suggestions...");
+    }
+
+    public final String msgNoSuggestions() {
+        return get("msgNoSuggestions", "Nothing was found.");
+    }
+
+}

File org.mandriva.annotator/org.mandriva.annotator.gwtapp/src/main/java/org/mandriva/annotator/gwtapp/server/SimpleServlet.java

     }
 
     public JSONObject handleAction(String action, JSONObject request)
-        throws JSONException {
+        throws JSONException,
+        IOException {
         JSONObject response;
-        if ("LoadTypes".equals(action)) {
+        if ("LoadMessages".equals(action)) {
+            String resource = "/WebAnnotatorMessages.json";
+            InputStream input = getClass().getResourceAsStream(resource);
+            String messages = readString(input);
+            response = new JSONObject(messages);
+        } else if ("LoadTypes".equals(action)) {
             response = newEntitiesObject();
             addEntity(response, "Web Document", "uri:nepomuk:webresource");
             addEntity(response, "Documentation", "uri:nepomuk:documenation");

File org.mandriva.annotator/org.mandriva.annotator.gwtapp/src/main/resources/WebAnnotatorMessages.json

+{ 
+    "btnClose" : "Close",
+    "btnRevert" : "Revert",
+    "btnSave" : "Save",
+    "dialogScrollHeight" : "25em",
+    "dialogScrollWidth" : "45em",
+    "dialogTitle" : "Web Page Annotator",
+    "labelAppendSelectedText" : "Append selected text",
+    "labelDescription" : "Description:",
+    "labelRelations" : "Relations:",
+    "labelSuggestedRelations" : "Suggested relations:",
+    "labelTitle" : "Title:",
+    "labelType" : "Type:", "labelUrl" : "Page URL:",
+    "msgAnnotationLoading" : "Annotation loading...",
+    "msgAnnotationSaved" : "The annotation was successfully saved.",
+    "msgAnnotationSaving" : "Save annotation...",
+    "msgLoadDataTypes" : "Loading data types...",
+    "msgLoadSuggestions" : "Loading suggestions...",
+    "msgNoSuggestions" : "Nothing was found."
+}