Jelajahi Sumber

[assist] Pass i18n strings to js modules where needed

Johan Ahlen 10 tahun lalu
induk
melakukan
7eaa3f0

+ 5 - 1
apps/beeswax/src/beeswax/templates/execute.mako

@@ -1138,7 +1138,11 @@ editorViewModelOptions.languages.push({
   name: snippetType
 });
 
-var editorViewModel = new EditorViewModel([], editorViewModelOptions);
+var i18n = {
+  errorLoadingDatabases: "${ _('There was a problem loading the databases') }"
+}
+
+var editorViewModel = new EditorViewModel([], editorViewModelOptions, i18n);
 var notebook = editorViewModel.newNotebook();
 var snippet = notebook.newSnippet(snippetType);
 var assistHelper = snippet.getAssistHelper();

+ 3 - 2
desktop/core/src/desktop/static/desktop/js/assist/assistEntry.js

@@ -22,8 +22,9 @@
   }
 }(this, function (ko, TableStats) {
 
-  function AssistEntry (definition, parent, assistSource, filter) {
+  function AssistEntry (definition, parent, assistSource, filter, i18n) {
     var self = this;
+    self.i18n = i18n;
     self.definition = definition;
 
     self.assistSource = assistSource;
@@ -234,7 +235,7 @@
       $assistQuickLook.find(".sample").html(data);
     }, function(e) {
       if (e.status == 500) {
-        $(document).trigger("error", "${ _('There was a problem loading the table preview.') }");
+        $(document).trigger("error", self.i18n.errorLoadingTablePreview);
         $("#assistQuickLook").modal("hide");
       }
     });

+ 4 - 3
desktop/core/src/desktop/static/desktop/js/assist/assistHelper.js

@@ -33,8 +33,9 @@
    *
    * @constructor
    */
-  function AssistHelper (options) {
+  function AssistHelper (options, i18n) {
     var self = this;
+    self.i18n = i18n;
     self.activeDatabase = ko.observable();
     self.initialDatabase = options.activeDatabase;
     self.notebook = options.notebook;
@@ -92,11 +93,11 @@
       if (message.status == 401) {
         $(document).trigger("showAuthModal", {'type': self.type, 'callback': function() { self.load(snippet, callback) }});
       } else if (message.statusText) {
-        $(document).trigger("error", "There was a problem loading the databases:" + message.statusText);
+        $(document).trigger("error", self.i18n.errorLoadingDatabases + ":" + message.statusText);
       } else if (message) {
         $(document).trigger("error", message);
       } else {
-        $(document).trigger("error", "There was a problem loading the databases");
+        $(document).trigger("error", self.i18n.errorLoadingDatabases + ".");
       }
       if (callback) {
         callback();

+ 4 - 3
desktop/core/src/desktop/static/desktop/js/assist/assistSource.js

@@ -18,12 +18,13 @@
   if(typeof define === "function" && define.amd) {
     define(['knockout', 'desktop/js/assist/assistEntry'], factory);
   } else {
-    root.AssistHelper = factory(ko, AssistEntry);
+    root.AssistSource = factory(ko, AssistEntry);
   }
 }(this, function (ko, AssistEntry) {
 
-  function AssistSource(snippet) {
+  function AssistSource(snippet, i18n) {
     var self = this;
+    self.i18n = i18n;
     self.snippet = snippet;
     self.assistHelper = snippet.getAssistHelper();
 
@@ -70,7 +71,7 @@
           displayName: name,
           title: name,
           isDatabase: true
-        }, null, self, self.filter);
+        }, null, self, self.filter, self.i18n);
       }));
 
       self.setDatabase(self.assistHelper.activeDatabase());

+ 7 - 7
desktop/core/src/desktop/static/desktop/js/assist/tableStats.js

@@ -22,9 +22,9 @@
   }
 }(this, function (ko) {
 
-  function TableStats (assistSource, database, table, column, type) {
+  function TableStats (assistSource, database, table, column, type, i18n) {
     var self = this;
-
+    self.i18n = i18n;
     self.snippet = assistSource.snippet;
     self.database = database;
     self.table = table;
@@ -75,14 +75,14 @@
             $(document).trigger("error", data.message);
             self.hasError(true);
           } else {
-            $(document).trigger("error", "${ _('There was a problem loading the stats.') }");
+            $(document).trigger("error", self.i18n.errorLoadingStats);
             self.hasError(true);
           }
           self.loading(false);
         },
         function (e) {
           if (e.status == 500) {
-            $(document).trigger("error", "${ _('There was a problem loading the stats.') }");
+            $(document).trigger("error", self.i18n.errorLoadingStats);
           }
           self.hasError(true);
           self.loading(false);
@@ -105,7 +105,7 @@
       }
     }, function(message) {
       self.refreshing(false);
-      $(document).trigger("error", message || "${ _('There was a problem refreshing the stats.') }");
+      $(document).trigger("error", message || self.i18n.errorRefreshingStats);
     });
   };
 
@@ -128,12 +128,12 @@
       } else if (data && data.message) {
         $(document).trigger("error", data.message);
       } else {
-        $(document).trigger("error", "${ _('There was a problem loading the terms.') }");
+        $(document).trigger("error", self.i18n.errorLoadingTerms);
       }
       self.loadingTerms(false);
     }, function (e) {
       if (e.status == 500) {
-        $(document).trigger("error", "${ _('There was a problem loading the terms.') }");
+        $(document).trigger("error", self.i18n.errorLoadingTerms);
       }
       self.loadingTerms(false);
     });

+ 7 - 1
desktop/core/src/desktop/templates/ko_components.mako

@@ -284,6 +284,12 @@ from desktop.views import _ko
     }(function (ko, AssistSource) {
 
       function AssistPanel(params) {
+        var i18n = {
+          errorLoadingTablePreview: "${ _('There was a problem loading the table preview.') }",
+          errorLoadingStats: "${ _('There was a problem loading the stats.') }",
+          errorRefreshingStats: "${ _('There was a problem refreshing the stats.') }",
+          errorLoadingTerms: "${ _('There was a problem loading the terms.') }"
+        }
         var notebookViewModel = params.notebookViewModel;
         var notebook = notebookViewModel.selectedNotebook();
 
@@ -304,7 +310,7 @@ from desktop.views import _ko
           };
 
           if (settings.sqlDialect) {
-            self.sourceIndex[snippet.name()] = new AssistSource(fakeSnippet);
+            self.sourceIndex[snippet.name()] = new AssistSource(fakeSnippet, i18n);
           }
         });
 

+ 3 - 3
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -696,7 +696,7 @@
           notebook: self,
           user: vm.user,
           activeDatabase: self.selectedDatabases[snippetType]
-        });
+        }, vm.i18n);
 
         self.assistHelpers[snippetType].activeDatabase.subscribe(function (newActiveDatabase) {
           self.selectedDatabases[snippetType] = newActiveDatabase;
@@ -993,9 +993,9 @@
   };
 
 
-  function EditorViewModel(notebooks, options) {
+  function EditorViewModel(notebooks, options, i18n) {
     var self = this;
-
+    self.i18n = i18n;
     self.user = options.user;
     self.notebooks = ko.observableArray();
     self.selectedNotebook = ko.observable();

+ 4 - 1
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1806,7 +1806,10 @@ ${ require.config() }
 
 
     $(document).ready(function () {
-      viewModel = new EditorViewModel(${ notebooks_json | n,unicode }, VIEW_MODEL_OPTIONS);
+      var i18n = {
+        errorLoadingDatabases: "${ _('There was a problem loading the databases') }"
+      }
+      viewModel = new EditorViewModel(${ notebooks_json | n,unicode }, VIEW_MODEL_OPTIONS, i18n);
       ko.applyBindings(viewModel);
       viewModel.init();