From 9d45421ad5a28ce08d09529630cdd5952ccfb1af Mon Sep 17 00:00:00 2001
From: George Gelashvili and Sarah McAlear
 <pair+ggelashvili+smcalear@pivotal.io>
Date: Fri, 24 Mar 2017 16:59:58 -0400
Subject: [PATCH] Changed untemplated translate to be picked up with the rest

- by renaming translate.js to gettext.js
---
 docs/en_US/translations.rst                        |   6 +-
 web/babel.cfg                                      |   1 +
 web/pgadmin/about/templates/about/about.js         |   8 +-
 .../dashboard/templates/dashboard/js/dashboard.js  | 132 ++++++++++-----------
 .../templates/preferences/preferences.js           |  22 ++--
 .../settings/templates/settings/settings.js        |   8 +-
 web/pgadmin/static/js/{translate.js => gettext.js} |   2 +-
 web/pgadmin/static/js/selection/clipboard.js       |   6 +-
 .../{translate_spec.js => gettext_spec.js}         |  12 +-
 9 files changed, 99 insertions(+), 98 deletions(-)
 rename web/pgadmin/static/js/{translate.js => gettext.js} (94%)
 rename web/regression/javascript/{translate_spec.js => gettext_spec.js} (72%)

diff --git a/docs/en_US/translations.rst b/docs/en_US/translations.rst
index cdc6900c..84ecd6ec 100644
--- a/docs/en_US/translations.rst
+++ b/docs/en_US/translations.rst
@@ -30,12 +30,12 @@ Jinja:
     
 .. code-block:: javascript
 
-    define(['translate', ...], function(translate, ...){
+    define(['gettext', ...], function(gettext, ...){
         ...
 
         var alert = alertify.prompt(
-            translate('Password Change'),
-            translate('New password for %(userName)s', {userName: 'jsmith' }),
+            gettext('Password Change'),
+            gettext('New password for %(userName)s', {userName: 'jsmith' }),
             ...
         )
     })
diff --git a/web/babel.cfg b/web/babel.cfg
index c2980839..8d093c09 100644
--- a/web/babel.cfg
+++ b/web/babel.cfg
@@ -2,4 +2,5 @@
 [jinja2: **/templates/**.html]
 [jinja2: **/templates/**.js]
 [jinja2: **/templates/**.sql]
+[python: **/static/**.js]
 extensions=jinja2.ext.autoescape,jinja2.ext.with_
diff --git a/web/pgadmin/about/templates/about/about.js b/web/pgadmin/about/templates/about/about.js
index 489018aa..662469a1 100644
--- a/web/pgadmin/about/templates/about/about.js
+++ b/web/pgadmin/about/templates/about/about.js
@@ -1,6 +1,6 @@
 define(
-  ['jquery', 'alertify', 'pgadmin', 'sources/translate'],
-  function($, alertify, pgAdmin, t) {
+  ['jquery', 'alertify', 'pgadmin', 'sources/gettext'],
+  function($, alertify, pgAdmin, gettext) {
     pgAdmin = pgAdmin || window.pgAdmin || {};
 
     /* Return back, this has been called more than once */
@@ -18,7 +18,7 @@ define(
               },
               setup: function() {
                 return {
-                  buttons:[{ text: t("OK"), key: 27, className: "btn btn-primary" }],
+                  buttons:[{ text: gettext("OK"), key: 27, className: "btn btn-primary" }],
                   options: {
                     modal: false,
                     resizable: true,
@@ -41,7 +41,7 @@ define(
         var content = '';
         $.get("{{ url_for('about.index') }}",
             function(data) {
-              alertify.aboutDialog(t("About %(appname)s", {appname: "{{ config.APP_NAME }}"}), data).resizeTo(800, 450);
+              alertify.aboutDialog(gettext("About %(appname)s", {appname: "{{ config.APP_NAME }}"}), data).resizeTo(800, 450);
             });
       }
     };
diff --git a/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js b/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js
index 1f8585f2..35ed1021 100644
--- a/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js
+++ b/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js
@@ -1,8 +1,8 @@
 define([
-    'require', 'jquery', 'pgadmin', 'underscore', 'backbone', 'sources/translate', 'flotr2', 'wcdocker',
+    'require', 'jquery', 'pgadmin', 'underscore', 'backbone', 'sources/gettext', 'flotr2', 'wcdocker',
     'pgadmin.browser', 'bootstrap'
     ],
-function(r, $, pgAdmin, _, Backbone, t) {
+function(r, $, pgAdmin, _, Backbone, gettext) {
 
   var wcDocker = window.wcDocker,
   pgBrowser = pgAdmin.Browser;
@@ -41,7 +41,7 @@ function(r, $, pgAdmin, _, Backbone, t) {
                         },
                         error: function (xhr, status) {
                             $(div).html(
-                                '<div class="alert alert-danger pg-panel-message" role="alert">' + t('An error occurred whilst loading the dashboard.') + '</div>'
+                                '<div class="alert alert-danger pg-panel-message" role="alert">' + gettext('An error occurred whilst loading the dashboard.') + '</div>'
                             );
                         }
                     });
@@ -101,7 +101,7 @@ function(r, $, pgAdmin, _, Backbone, t) {
                                 },
                                 error: function (xhr, status) {
                                     $(div).html(
-                                        '<div class="alert alert-danger pg-panel-message" role="alert">' + t('An error occurred whilst loading the dashboard.') + '</div>'
+                                        '<div class="alert alert-danger pg-panel-message" role="alert">' + gettext('An error occurred whilst loading the dashboard.') + '</div>'
                                     );
                                 }
                             });
@@ -209,11 +209,11 @@ function(r, $, pgAdmin, _, Backbone, t) {
                         // If we get a 428, it means the server isn't connected
                         if (xhr.status == 428) {
                             if (_.isUndefined(msg) || _.isNull(msg)) {
-                              msg = t('Please connect to the selected server to view the graph.');
+                              msg = gettext('Please connect to the selected server to view the graph.');
                             }
                             cls = 'info';
                         } else {
-                            msg = t('An error occurred whilst rendering the graph.');
+                            msg = gettext('An error occurred whilst rendering the graph.');
                             cls = 'danger';
                         }
 
@@ -331,11 +331,11 @@ function(r, $, pgAdmin, _, Backbone, t) {
                     // If we get a 428, it means the server isn't connected
                     if (xhr.status == 428) {
                         if (_.isUndefined(msg) || _.isNull(msg)) {
-                            msg = t('Please connect to the selected server to view the table.');
+                            msg = gettext('Please connect to the selected server to view the table.');
                         }
                         cls = 'info';
                     } else {
-                        msg = t('An error occurred whilst rendering the table.');
+                        msg = gettext('An error occurred whilst rendering the table.');
                         cls = 'danger';
                     }
 
@@ -400,37 +400,37 @@ function(r, $, pgAdmin, _, Backbone, t) {
 
             var server_activity_columns = [{
                 name: "pid",
-                label: t('PID'),
+                label: gettext('PID'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "datname",
-                label: t('Database'),
+                label: gettext('Database'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "usename",
-                label: t('User'),
+                label: gettext('User'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "application_name",
-                label: t('Application'),
+                label: gettext('Application'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "client_addr",
-                label: t('Client'),
+                label: gettext('Client'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "backend_start",
-                label: t('Backend start'),
+                label: gettext('Backend start'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "state",
-                label: t('State'),
+                label: gettext('State'),
                 editable: false,
                 cell: "string"
             }];
@@ -439,7 +439,7 @@ function(r, $, pgAdmin, _, Backbone, t) {
                 server_activity_columns = server_activity_columns.concat(
                 [{
                     name: "waiting",
-                    label: t('Waiting?'),
+                    label: gettext('Waiting?'),
                     editable: false,
                     cell: "string"
                 }]);
@@ -447,12 +447,12 @@ function(r, $, pgAdmin, _, Backbone, t) {
                 server_activity_columns = server_activity_columns.concat(
                 [{
                     name: "wait_event",
-                    label: t('Wait Event'),
+                    label: gettext('Wait Event'),
                     editable: false,
                     cell: "string"
                 },{
                     name: "blocking_pids",
-                    label: t('Blocking PIDs'),
+                    label: gettext('Blocking PIDs'),
                     editable: false,
                     cell: "string"
                 }]);
@@ -460,121 +460,121 @@ function(r, $, pgAdmin, _, Backbone, t) {
 
             var server_locks_columns = [{
                 name: "pid",
-                label: t('PID'),
+                label: gettext('PID'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "datname",
-                label: t('Database'),
+                label: gettext('Database'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "locktype",
-                label: t('Lock type'),
+                label: gettext('Lock type'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "relation",
-                label: t('Target relation'),
+                label: gettext('Target relation'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "page",
-                label: t('Page'),
+                label: gettext('Page'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "tuple",
-                label: t('Tuple'),
+                label: gettext('Tuple'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "virtualxid",
-                label: t('vXID (target)'),
+                label: gettext('vXID (target)'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "transactionid",
-                label: t('XID (target)'),
+                label: gettext('XID (target)'),
                 editable: false,
                 cell: "string"
             },{
                 name: "classid",
-                label: t('Class'),
+                label: gettext('Class'),
                 editable: false,
                 cell: "string"
             },{
                 name: "objid",
-                label: t('Object ID'),
+                label: gettext('Object ID'),
                 editable: false,
                 cell: "string"
             },{
                 name: "virtualtransaction",
-                label: t('vXID (owner)'),
+                label: gettext('vXID (owner)'),
                 editable: false,
                 cell: "string"
             },{
                 name: "mode",
-                label: t('Mode'),
+                label: gettext('Mode'),
                 editable: false,
                 cell: "string"
             },{
                 name: "granted",
-                label: t('Granted?'),
+                label: gettext('Granted?'),
                 editable: false,
                 cell: "string"
             }];
 
             var server_prepared_columns = [{
                 name: "git",
-                label: t('Name'),
+                label: gettext('Name'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "database",
-                label: t('Database'),
+                label: gettext('Database'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "Owner",
-                label: t('Owner'),
+                label: gettext('Owner'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "transaction",
-                label: t('XID'),
+                label: gettext('XID'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "prepared",
-                label: t('Prepared at'),
+                label: gettext('Prepared at'),
                 editable: false,
                 cell: "string"
             }];
 
             var server_config_columns = [{
                 name: "name",
-                label: t('Name'),
+                label: gettext('Name'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "category",
-                label: t('Category'),
+                label: gettext('Category'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "setting",
-                label: t('Setting'),
+                label: gettext('Setting'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "unit",
-                label: t('Unit'),
+                label: gettext('Unit'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "short_desc",
-                label: t('Description'),
+                label: gettext('Description'),
                 editable: false,
                 cell: "string"
             }];
@@ -677,32 +677,32 @@ function(r, $, pgAdmin, _, Backbone, t) {
 
             var database_activity_columns = [{
                 name: "pid",
-                label: t('PID'),
+                label: gettext('PID'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "usename",
-                label: t('User'),
+                label: gettext('User'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "application_name",
-                label: t('Application'),
+                label: gettext('Application'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "client_addr",
-                label: t('Client'),
+                label: gettext('Client'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "backend_start",
-                label: t('Backend start'),
+                label: gettext('Backend start'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "state",
-                label: t('State'),
+                label: gettext('State'),
                 editable: false,
                 cell: "string"
             }];
@@ -711,7 +711,7 @@ function(r, $, pgAdmin, _, Backbone, t) {
                 database_activity_columns = database_activity_columns.concat(
                 [{
                     name: "waiting",
-                    label: t('Waiting?'),
+                    label: gettext('Waiting?'),
                     editable: false,
                     cell: "string"
                 }]);
@@ -719,12 +719,12 @@ function(r, $, pgAdmin, _, Backbone, t) {
                 database_activity_columns = database_activity_columns.concat(
                 [{
                     name: "wait_event",
-                    label: t('Wait Event'),
+                    label: gettext('Wait Event'),
                     editable: false,
                     cell: "string"
                 },{
                     name: "blocking_pids",
-                    label: t('Blocking PIDs'),
+                    label: gettext('Blocking PIDs'),
                     editable: false,
                     cell: "string"
                 }]);
@@ -732,84 +732,84 @@ function(r, $, pgAdmin, _, Backbone, t) {
 
             var database_locks_columns = [{
                 name: "pid",
-                label: t('PID'),
+                label: gettext('PID'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "locktype",
-                label: t('Lock type'),
+                label: gettext('Lock type'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "relation",
-                label: t('Target relation'),
+                label: gettext('Target relation'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "page",
-                label: t('Page'),
+                label: gettext('Page'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "tuple",
-                label: t('Tuple'),
+                label: gettext('Tuple'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "virtualxid",
-                label: t('vXID (target)'),
+                label: gettext('vXID (target)'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "transactionid",
-                label: t('XID (target)'),
+                label: gettext('XID (target)'),
                 editable: false,
                 cell: "string"
             },{
                 name: "classid",
-                label: t('Class'),
+                label: gettext('Class'),
                 editable: false,
                 cell: "string"
             },{
                 name: "objid",
-                label: t('Object ID'),
+                label: gettext('Object ID'),
                 editable: false,
                 cell: "string"
             },{
                 name: "virtualtransaction",
-                label: t('vXID (owner)'),
+                label: gettext('vXID (owner)'),
                 editable: false,
                 cell: "string"
             },{
                 name: "mode",
-                label: t('Mode'),
+                label: gettext('Mode'),
                 editable: false,
                 cell: "string"
             },{
                 name: "granted",
-                label: t('Granted?'),
+                label: gettext('Granted?'),
                 editable: false,
                 cell: "string"
             }];
 
             var database_prepared_columns = [{
                 name: "git",
-                label: t('Name'),
+                label: gettext('Name'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "Owner",
-                label: t('Owner'),
+                label: gettext('Owner'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "transaction",
-                label: t('XID'),
+                label: gettext('XID'),
                 editable: false,
                 cell: "string"
             }, {
                 name: "prepared",
-                label: t('Prepared at'),
+                label: gettext('Prepared at'),
                 editable: false,
                 cell: "string"
             }];
diff --git a/web/pgadmin/preferences/templates/preferences/preferences.js b/web/pgadmin/preferences/templates/preferences/preferences.js
index 399ab015..9c741e04 100644
--- a/web/pgadmin/preferences/templates/preferences/preferences.js
+++ b/web/pgadmin/preferences/templates/preferences/preferences.js
@@ -1,9 +1,9 @@
 define(
   ['jquery', 'alertify', 'pgadmin', 'underscore', 'backform', 'pgadmin.browser',
-   'sources/translate', 'pgadmin.backform'],
+   'sources/gettext', 'pgadmin.backform'],
 
   // This defines the Preference/Options Dialog for pgAdmin IV.
-  function($, alertify, pgAdmin, _, Backform, pgBrowser, t) {
+  function($, alertify, pgAdmin, _, Backform, pgBrowser, gettext) {
     pgAdmin = pgAdmin || window.pgAdmin || {};
 
     /*
@@ -191,8 +191,8 @@ define(
                     return 'input';
                 case 'boolean':
                   p.options = {
-                      onText: t('True'),
-                      offText: t('False'),
+                      onText: gettext('True'),
+                      offText: gettext('False'),
                       onColor: 'success',
                       offColor: 'default',
                       size: 'mini'
@@ -200,8 +200,8 @@ define(
                   return 'switch';
                 case 'node':
                     p.options = {
-                      onText: t('Show'),
-                      offText: t('Hide'),
+                      onText: gettext('Show'),
+                      offText: gettext('Hide'),
                       onColor: 'success',
                       offColor: 'default',
                       size: 'mini'
@@ -329,7 +329,7 @@ define(
                 "<div class='pg-el-xs-3 preferences_tree aciTree'></div>"
               ).append(
                 "<div class='pg-el-xs-9 preferences_content'>" +
-                t('Category is not selected.') +
+                gettext('Category is not selected.') +
                 "</div>"
               );
 
@@ -355,16 +355,16 @@ define(
                     attrs:{name:'dialog_help', type:'button', label: '{{ _('Preferences') }}',
                     url: '{{ url_for('help.static', filename='preferences.html') }}'}
                   },{
-                    text: t('OK'), key: 13, className: "btn btn-primary fa fa-lg fa-save pg-alertify-button"
+                    text: gettext('OK'), key: 13, className: "btn btn-primary fa fa-lg fa-save pg-alertify-button"
                   },{
-                    text: t('Cancel'), className: "btn btn-danger fa fa-lg fa-times pg-alertify-button"
+                    text: gettext('Cancel'), className: "btn btn-danger fa fa-lg fa-times pg-alertify-button"
                   }
                 ],
                 focus: { element: 0 },
                 options: {
                   padding: !1,
                   overflow: !1,
-                  title: t('Preferences'),
+                  title: gettext('Preferences'),
                   closableByDimmer: false,
                   modal:false,
                   pinnable: false
@@ -379,7 +379,7 @@ define(
                   return;
                }
 
-              if (e.button.text == t('OK')){
+              if (e.button.text == gettext('OK')){
                 preferences.updateAll();
               }
             },
diff --git a/web/pgadmin/settings/templates/settings/settings.js b/web/pgadmin/settings/templates/settings/settings.js
index 1c70b90d..50a6391d 100644
--- a/web/pgadmin/settings/templates/settings/settings.js
+++ b/web/pgadmin/settings/templates/settings/settings.js
@@ -1,8 +1,8 @@
 define(
-  ['jquery', 'alertify', 'pgadmin', 'underscore', 'backform', 'sources/translate', 'pgadmin.backform'],
+  ['jquery', 'alertify', 'pgadmin', 'underscore', 'backform', 'sources/gettext', 'pgadmin.backform'],
 
   // This defines the Preference/Options Dialog for pgAdmin IV.
-  function($, alertify, pgAdmin, _, Backform, t) {
+  function($, alertify, pgAdmin, _, Backform, gettext) {
     pgAdmin = pgAdmin || window.pgAdmin || {};
 
     /*
@@ -23,8 +23,8 @@ define(
       // and reload the window
       show: function() {
         var obj = this;
-        alertify.confirm(t('Reset layout'),
-          t('Are you sure you want to reset the current layout? This will cause the application to reload and any un-saved data will be lost.'),
+        alertify.confirm(gettext('Reset layout'),
+          gettext('Are you sure you want to reset the current layout? This will cause the application to reload and any un-saved data will be lost.'),
           function() {
             var reloadingIndicator = $('<div id="reloading-indicator"></div>');
             $('body').append(reloadingIndicator);
diff --git a/web/pgadmin/static/js/translate.js b/web/pgadmin/static/js/gettext.js
similarity index 94%
rename from web/pgadmin/static/js/translate.js
rename to web/pgadmin/static/js/gettext.js
index ac1164ee..780b60f3 100644
--- a/web/pgadmin/static/js/translate.js
+++ b/web/pgadmin/static/js/gettext.js
@@ -9,7 +9,7 @@ define(["translations"], function (translations) {
    * @param {String} text
    * @param {Object} substitutions
    */
-  return function translate(text, substitutions) {
+  return function gettext(text, substitutions) {
 
     var rawTranslation = translations[text] ? translations[text] : text;
 
diff --git a/web/pgadmin/static/js/selection/clipboard.js b/web/pgadmin/static/js/selection/clipboard.js
index 386ca0be..9e20da7e 100644
--- a/web/pgadmin/static/js/selection/clipboard.js
+++ b/web/pgadmin/static/js/selection/clipboard.js
@@ -1,4 +1,4 @@
-define(['sources/translate', 'alertify'], function (t, alertify) {
+define(['sources/gettext', 'alertify'], function (gettext, alertify) {
   var clipboard = {
     copyTextToClipboard: function (text) {
       var textArea = document.createElement("textarea");
@@ -50,8 +50,8 @@ define(['sources/translate', 'alertify'], function (t, alertify) {
         document.execCommand('copy');
       } catch (err) {
         alertify.alert(
-          t('Error'),
-          t('Oops, unable to copy to clipboard'));
+          gettext('Error'),
+          gettext('Oops, unable to copy to clipboard'));
       }
 
       document.body.removeChild(textArea);
diff --git a/web/regression/javascript/translate_spec.js b/web/regression/javascript/gettext_spec.js
similarity index 72%
rename from web/regression/javascript/translate_spec.js
rename to web/regression/javascript/gettext_spec.js
index 6b223c81..2ce98a23 100644
--- a/web/regression/javascript/translate_spec.js
+++ b/web/regression/javascript/gettext_spec.js
@@ -7,20 +7,20 @@
 //
 //////////////////////////////////////////////////////////////////////////
 
-define(["sources/translate", "translations"], function (translate, translations) {
+define(["sources/gettext", "translations"], function (gettext, translations) {
   describe("translate", function () {
     describe("when there is no translation", function () {
       it("returns the original string", function () {
-        expect(translate("something to be translated")).toEqual("something to be translated");
+        expect(gettext("something to be translated")).toEqual("something to be translated");
       });
 
       describe("when there are substitutions", function () {
         it("interpolates a substitution", function () {
-          expect(translate("translate text for %(person)s", {"person": "Sarah"})).toEqual("translate text for Sarah")
+          expect(gettext("translate text for %(person)s", {"person": "Sarah"})).toEqual("translate text for Sarah")
         });
 
         it("interpolates multiple substitutions", function () {
-          expect(translate("translate '%(text)s' for %(person)s",
+          expect(gettext("translate '%(text)s' for %(person)s",
             {
               "text": "constitution",
               "person": "Sarah"
@@ -38,12 +38,12 @@ define(["sources/translate", "translations"], function (translate, translations)
       });
 
       it("returns the translation", function () {
-        expect(translate("something to be translated")).toEqual("etwas zum uebersetzen");
+        expect(gettext("something to be translated")).toEqual("etwas zum uebersetzen");
       });
 
       describe("when there is a substitution", function () {
         it("interpolates the substitution", function () {
-          expect(translate("another translation for %(person)s", {"person": "Sarah"}))
+          expect(gettext("another translation for %(person)s", {"person": "Sarah"}))
             .toEqual("eine weitere Uebersetzung fuer Sarah");
         });
       });
-- 
2.12.0

