Revert "Ensure client-side translations are correctly extracted into the message templates."

This reverts commit 82bd97aed0.

There are still issues extracting with these changes.
This commit is contained in:
Dave Page 2017-03-27 13:53:40 -04:00
parent 82bd97aed0
commit 95f43d59b8
9 changed files with 98 additions and 99 deletions

View File

@ -30,12 +30,12 @@ Jinja:
.. code-block:: javascript .. code-block:: javascript
define(['sources/gettext', ...], function(gettext, ...){ define(['sources/translate', ...], function(t, ...){
... ...
var alert = alertify.prompt( var alert = alertify.prompt(
gettext('Password Change'), t('Password Change'),
gettext('New password for %(userName)s', {userName: 'jsmith' }), t('New password for %(userName)s', {userName: 'jsmith' }),
... ...
) )
}) })

View File

@ -2,5 +2,4 @@
[jinja2: **/templates/**.html] [jinja2: **/templates/**.html]
[jinja2: **/templates/**.js] [jinja2: **/templates/**.js]
[jinja2: **/templates/**.sql] [jinja2: **/templates/**.sql]
[python: **/static/**.js]
extensions=jinja2.ext.autoescape,jinja2.ext.with_ extensions=jinja2.ext.autoescape,jinja2.ext.with_

View File

@ -1,6 +1,6 @@
define( define(
['jquery', 'alertify', 'pgadmin', 'sources/gettext'], ['jquery', 'alertify', 'pgadmin', 'sources/translate'],
function($, alertify, pgAdmin, gettext) { function($, alertify, pgAdmin, t) {
pgAdmin = pgAdmin || window.pgAdmin || {}; pgAdmin = pgAdmin || window.pgAdmin || {};
/* Return back, this has been called more than once */ /* Return back, this has been called more than once */
@ -18,7 +18,7 @@ define(
}, },
setup: function() { setup: function() {
return { return {
buttons:[{ text: gettext("OK"), key: 27, className: "btn btn-primary" }], buttons:[{ text: t("OK"), key: 27, className: "btn btn-primary" }],
options: { options: {
modal: false, modal: false,
resizable: true, resizable: true,
@ -41,7 +41,7 @@ define(
var content = ''; var content = '';
$.get("{{ url_for('about.index') }}", $.get("{{ url_for('about.index') }}",
function(data) { function(data) {
alertify.aboutDialog(gettext("About %(appname)s", {appname: "{{ config.APP_NAME }}"}), data).resizeTo(800, 450); alertify.aboutDialog(t("About %(appname)s", {appname: "{{ config.APP_NAME }}"}), data).resizeTo(800, 450);
}); });
} }
}; };

View File

@ -1,8 +1,8 @@
define([ define([
'require', 'jquery', 'pgadmin', 'underscore', 'backbone', 'sources/gettext', 'flotr2', 'wcdocker', 'require', 'jquery', 'pgadmin', 'underscore', 'backbone', 'sources/translate', 'flotr2', 'wcdocker',
'pgadmin.browser', 'bootstrap' 'pgadmin.browser', 'bootstrap'
], ],
function(r, $, pgAdmin, _, Backbone, gettext) { function(r, $, pgAdmin, _, Backbone, t) {
var wcDocker = window.wcDocker, var wcDocker = window.wcDocker,
pgBrowser = pgAdmin.Browser; pgBrowser = pgAdmin.Browser;
@ -41,7 +41,7 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
}, },
error: function (xhr, status) { error: function (xhr, status) {
$(div).html( $(div).html(
'<div class="alert alert-danger pg-panel-message" role="alert">' + gettext('An error occurred whilst loading the dashboard.') + '</div>' '<div class="alert alert-danger pg-panel-message" role="alert">' + t('An error occurred whilst loading the dashboard.') + '</div>'
); );
} }
}); });
@ -101,7 +101,7 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
}, },
error: function (xhr, status) { error: function (xhr, status) {
$(div).html( $(div).html(
'<div class="alert alert-danger pg-panel-message" role="alert">' + gettext('An error occurred whilst loading the dashboard.') + '</div>' '<div class="alert alert-danger pg-panel-message" role="alert">' + t('An error occurred whilst loading the dashboard.') + '</div>'
); );
} }
}); });
@ -209,11 +209,11 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
// If we get a 428, it means the server isn't connected // If we get a 428, it means the server isn't connected
if (xhr.status == 428) { if (xhr.status == 428) {
if (_.isUndefined(msg) || _.isNull(msg)) { if (_.isUndefined(msg) || _.isNull(msg)) {
msg = gettext('Please connect to the selected server to view the graph.'); msg = t('Please connect to the selected server to view the graph.');
} }
cls = 'info'; cls = 'info';
} else { } else {
msg = gettext('An error occurred whilst rendering the graph.'); msg = t('An error occurred whilst rendering the graph.');
cls = 'danger'; cls = 'danger';
} }
@ -331,11 +331,11 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
// If we get a 428, it means the server isn't connected // If we get a 428, it means the server isn't connected
if (xhr.status == 428) { if (xhr.status == 428) {
if (_.isUndefined(msg) || _.isNull(msg)) { if (_.isUndefined(msg) || _.isNull(msg)) {
msg = gettext('Please connect to the selected server to view the table.'); msg = t('Please connect to the selected server to view the table.');
} }
cls = 'info'; cls = 'info';
} else { } else {
msg = gettext('An error occurred whilst rendering the table.'); msg = t('An error occurred whilst rendering the table.');
cls = 'danger'; cls = 'danger';
} }
@ -400,37 +400,37 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
var server_activity_columns = [{ var server_activity_columns = [{
name: "pid", name: "pid",
label: gettext('PID'), label: t('PID'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "datname", name: "datname",
label: gettext('Database'), label: t('Database'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "usename", name: "usename",
label: gettext('User'), label: t('User'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "application_name", name: "application_name",
label: gettext('Application'), label: t('Application'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "client_addr", name: "client_addr",
label: gettext('Client'), label: t('Client'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "backend_start", name: "backend_start",
label: gettext('Backend start'), label: t('Backend start'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "state", name: "state",
label: gettext('State'), label: t('State'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];
@ -439,7 +439,7 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
server_activity_columns = server_activity_columns.concat( server_activity_columns = server_activity_columns.concat(
[{ [{
name: "waiting", name: "waiting",
label: gettext('Waiting?'), label: t('Waiting?'),
editable: false, editable: false,
cell: "string" cell: "string"
}]); }]);
@ -447,12 +447,12 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
server_activity_columns = server_activity_columns.concat( server_activity_columns = server_activity_columns.concat(
[{ [{
name: "wait_event", name: "wait_event",
label: gettext('Wait Event'), label: t('Wait Event'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "blocking_pids", name: "blocking_pids",
label: gettext('Blocking PIDs'), label: t('Blocking PIDs'),
editable: false, editable: false,
cell: "string" cell: "string"
}]); }]);
@ -460,121 +460,121 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
var server_locks_columns = [{ var server_locks_columns = [{
name: "pid", name: "pid",
label: gettext('PID'), label: t('PID'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "datname", name: "datname",
label: gettext('Database'), label: t('Database'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "locktype", name: "locktype",
label: gettext('Lock type'), label: t('Lock type'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "relation", name: "relation",
label: gettext('Target relation'), label: t('Target relation'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "page", name: "page",
label: gettext('Page'), label: t('Page'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "tuple", name: "tuple",
label: gettext('Tuple'), label: t('Tuple'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "virtualxid", name: "virtualxid",
label: gettext('vXID (target)'), label: t('vXID (target)'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "transactionid", name: "transactionid",
label: gettext('XID (target)'), label: t('XID (target)'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "classid", name: "classid",
label: gettext('Class'), label: t('Class'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "objid", name: "objid",
label: gettext('Object ID'), label: t('Object ID'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "virtualtransaction", name: "virtualtransaction",
label: gettext('vXID (owner)'), label: t('vXID (owner)'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "mode", name: "mode",
label: gettext('Mode'), label: t('Mode'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "granted", name: "granted",
label: gettext('Granted?'), label: t('Granted?'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];
var server_prepared_columns = [{ var server_prepared_columns = [{
name: "git", name: "git",
label: gettext('Name'), label: t('Name'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "database", name: "database",
label: gettext('Database'), label: t('Database'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "Owner", name: "Owner",
label: gettext('Owner'), label: t('Owner'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "transaction", name: "transaction",
label: gettext('XID'), label: t('XID'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "prepared", name: "prepared",
label: gettext('Prepared at'), label: t('Prepared at'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];
var server_config_columns = [{ var server_config_columns = [{
name: "name", name: "name",
label: gettext('Name'), label: t('Name'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "category", name: "category",
label: gettext('Category'), label: t('Category'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "setting", name: "setting",
label: gettext('Setting'), label: t('Setting'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "unit", name: "unit",
label: gettext('Unit'), label: t('Unit'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "short_desc", name: "short_desc",
label: gettext('Description'), label: t('Description'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];
@ -677,32 +677,32 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
var database_activity_columns = [{ var database_activity_columns = [{
name: "pid", name: "pid",
label: gettext('PID'), label: t('PID'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "usename", name: "usename",
label: gettext('User'), label: t('User'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "application_name", name: "application_name",
label: gettext('Application'), label: t('Application'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "client_addr", name: "client_addr",
label: gettext('Client'), label: t('Client'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "backend_start", name: "backend_start",
label: gettext('Backend start'), label: t('Backend start'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "state", name: "state",
label: gettext('State'), label: t('State'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];
@ -711,7 +711,7 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
database_activity_columns = database_activity_columns.concat( database_activity_columns = database_activity_columns.concat(
[{ [{
name: "waiting", name: "waiting",
label: gettext('Waiting?'), label: t('Waiting?'),
editable: false, editable: false,
cell: "string" cell: "string"
}]); }]);
@ -719,12 +719,12 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
database_activity_columns = database_activity_columns.concat( database_activity_columns = database_activity_columns.concat(
[{ [{
name: "wait_event", name: "wait_event",
label: gettext('Wait Event'), label: t('Wait Event'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "blocking_pids", name: "blocking_pids",
label: gettext('Blocking PIDs'), label: t('Blocking PIDs'),
editable: false, editable: false,
cell: "string" cell: "string"
}]); }]);
@ -732,84 +732,84 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
var database_locks_columns = [{ var database_locks_columns = [{
name: "pid", name: "pid",
label: gettext('PID'), label: t('PID'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "locktype", name: "locktype",
label: gettext('Lock type'), label: t('Lock type'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "relation", name: "relation",
label: gettext('Target relation'), label: t('Target relation'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "page", name: "page",
label: gettext('Page'), label: t('Page'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "tuple", name: "tuple",
label: gettext('Tuple'), label: t('Tuple'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "virtualxid", name: "virtualxid",
label: gettext('vXID (target)'), label: t('vXID (target)'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "transactionid", name: "transactionid",
label: gettext('XID (target)'), label: t('XID (target)'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "classid", name: "classid",
label: gettext('Class'), label: t('Class'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "objid", name: "objid",
label: gettext('Object ID'), label: t('Object ID'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "virtualtransaction", name: "virtualtransaction",
label: gettext('vXID (owner)'), label: t('vXID (owner)'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "mode", name: "mode",
label: gettext('Mode'), label: t('Mode'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "granted", name: "granted",
label: gettext('Granted?'), label: t('Granted?'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];
var database_prepared_columns = [{ var database_prepared_columns = [{
name: "git", name: "git",
label: gettext('Name'), label: t('Name'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "Owner", name: "Owner",
label: gettext('Owner'), label: t('Owner'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "transaction", name: "transaction",
label: gettext('XID'), label: t('XID'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "prepared", name: "prepared",
label: gettext('Prepared at'), label: t('Prepared at'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];

View File

@ -1,9 +1,9 @@
define( define(
['jquery', 'alertify', 'pgadmin', 'underscore', 'backform', 'pgadmin.browser', ['jquery', 'alertify', 'pgadmin', 'underscore', 'backform', 'pgadmin.browser',
'sources/gettext', 'pgadmin.backform'], 'sources/translate', 'pgadmin.backform'],
// This defines the Preference/Options Dialog for pgAdmin IV. // This defines the Preference/Options Dialog for pgAdmin IV.
function($, alertify, pgAdmin, _, Backform, pgBrowser, gettext) { function($, alertify, pgAdmin, _, Backform, pgBrowser, t) {
pgAdmin = pgAdmin || window.pgAdmin || {}; pgAdmin = pgAdmin || window.pgAdmin || {};
/* /*
@ -191,8 +191,8 @@ define(
return 'input'; return 'input';
case 'boolean': case 'boolean':
p.options = { p.options = {
onText: gettext('True'), onText: t('True'),
offText: gettext('False'), offText: t('False'),
onColor: 'success', onColor: 'success',
offColor: 'default', offColor: 'default',
size: 'mini' size: 'mini'
@ -200,8 +200,8 @@ define(
return 'switch'; return 'switch';
case 'node': case 'node':
p.options = { p.options = {
onText: gettext('Show'), onText: t('Show'),
offText: gettext('Hide'), offText: t('Hide'),
onColor: 'success', onColor: 'success',
offColor: 'default', offColor: 'default',
size: 'mini' size: 'mini'
@ -333,7 +333,7 @@ define(
"<div class='pg-el-xs-3 preferences_tree aciTree'></div>" "<div class='pg-el-xs-3 preferences_tree aciTree'></div>"
).append( ).append(
"<div class='pg-el-xs-9 preferences_content'>" + "<div class='pg-el-xs-9 preferences_content'>" +
gettext('Category is not selected.') + t('Category is not selected.') +
"</div>" "</div>"
); );
@ -359,16 +359,16 @@ define(
attrs:{name:'dialog_help', type:'button', label: '{{ _('Preferences') }}', attrs:{name:'dialog_help', type:'button', label: '{{ _('Preferences') }}',
url: '{{ url_for('help.static', filename='preferences.html') }}'} url: '{{ url_for('help.static', filename='preferences.html') }}'}
},{ },{
text: gettext('OK'), key: 13, className: "btn btn-primary fa fa-lg fa-save pg-alertify-button" text: t('OK'), key: 13, className: "btn btn-primary fa fa-lg fa-save pg-alertify-button"
},{ },{
text: gettext('Cancel'), className: "btn btn-danger fa fa-lg fa-times pg-alertify-button" text: t('Cancel'), className: "btn btn-danger fa fa-lg fa-times pg-alertify-button"
} }
], ],
focus: { element: 0 }, focus: { element: 0 },
options: { options: {
padding: !1, padding: !1,
overflow: !1, overflow: !1,
title: gettext('Preferences'), title: t('Preferences'),
closableByDimmer: false, closableByDimmer: false,
modal:false, modal:false,
pinnable: false pinnable: false
@ -383,7 +383,7 @@ define(
return; return;
} }
if (e.button.text == gettext('OK')){ if (e.button.text == t('OK')){
preferences.updateAll(); preferences.updateAll();
} }
}, },

View File

@ -1,8 +1,8 @@
define( define(
['jquery', 'alertify', 'pgadmin', 'underscore', 'backform', 'sources/gettext', 'pgadmin.backform'], ['jquery', 'alertify', 'pgadmin', 'underscore', 'backform', 'sources/translate', 'pgadmin.backform'],
// This defines the Preference/Options Dialog for pgAdmin IV. // This defines the Preference/Options Dialog for pgAdmin IV.
function($, alertify, pgAdmin, _, Backform, gettext) { function($, alertify, pgAdmin, _, Backform, t) {
pgAdmin = pgAdmin || window.pgAdmin || {}; pgAdmin = pgAdmin || window.pgAdmin || {};
/* /*
@ -23,8 +23,8 @@ define(
// and reload the window // and reload the window
show: function() { show: function() {
var obj = this; var obj = this;
alertify.confirm(gettext('Reset layout'), alertify.confirm(t('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.'), 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.'),
function() { function() {
var reloadingIndicator = $('<div id="reloading-indicator"></div>'); var reloadingIndicator = $('<div id="reloading-indicator"></div>');
$('body').append(reloadingIndicator); $('body').append(reloadingIndicator);

View File

@ -1,4 +1,4 @@
define(['sources/gettext', 'alertify'], function (gettext, alertify) { define(['sources/translate', 'alertify'], function (t, alertify) {
var clipboard = { var clipboard = {
copyTextToClipboard: function (text) { copyTextToClipboard: function (text) {
var textArea = document.createElement("textarea"); var textArea = document.createElement("textarea");
@ -50,8 +50,8 @@ define(['sources/gettext', 'alertify'], function (gettext, alertify) {
document.execCommand('copy'); document.execCommand('copy');
} catch (err) { } catch (err) {
alertify.alert( alertify.alert(
gettext('Error'), t('Error'),
gettext('Oops, unable to copy to clipboard')); t('Oops, unable to copy to clipboard'));
} }
document.body.removeChild(textArea); document.body.removeChild(textArea);

View File

@ -9,7 +9,7 @@ define(["translations"], function (translations) {
* @param {String} text * @param {String} text
* @param {Object} substitutions * @param {Object} substitutions
*/ */
return function gettext(text, substitutions) { return function translate(text, substitutions) {
var rawTranslation = translations[text] ? translations[text] : text; var rawTranslation = translations[text] ? translations[text] : text;

View File

@ -7,20 +7,20 @@
// //
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
define(["sources/gettext", "translations"], function (gettext, translations) { define(["sources/translate", "translations"], function (translate, translations) {
describe("translate", function () { describe("translate", function () {
describe("when there is no translation", function () { describe("when there is no translation", function () {
it("returns the original string", function () { it("returns the original string", function () {
expect(gettext("something to be translated")).toEqual("something to be translated"); expect(translate("something to be translated")).toEqual("something to be translated");
}); });
describe("when there are substitutions", function () { describe("when there are substitutions", function () {
it("interpolates a substitution", function () { it("interpolates a substitution", function () {
expect(gettext("translate text for %(person)s", {"person": "Sarah"})).toEqual("translate text for Sarah") expect(translate("translate text for %(person)s", {"person": "Sarah"})).toEqual("translate text for Sarah")
}); });
it("interpolates multiple substitutions", function () { it("interpolates multiple substitutions", function () {
expect(gettext("translate '%(text)s' for %(person)s", expect(translate("translate '%(text)s' for %(person)s",
{ {
"text": "constitution", "text": "constitution",
"person": "Sarah" "person": "Sarah"
@ -38,12 +38,12 @@ define(["sources/gettext", "translations"], function (gettext, translations) {
}); });
it("returns the translation", function () { it("returns the translation", function () {
expect(gettext("something to be translated")).toEqual("etwas zum uebersetzen"); expect(translate("something to be translated")).toEqual("etwas zum uebersetzen");
}); });
describe("when there is a substitution", function () { describe("when there is a substitution", function () {
it("interpolates the substitution", function () { it("interpolates the substitution", function () {
expect(gettext("another translation for %(person)s", {"person": "Sarah"})) expect(translate("another translation for %(person)s", {"person": "Sarah"}))
.toEqual("eine weitere Uebersetzung fuer Sarah"); .toEqual("eine weitere Uebersetzung fuer Sarah");
}); });
}); });