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

This commit is contained in:
Sarah McAlear authored and Dave Page committed 2017-03-27 13:24:47 -04:00
1 parent 633d2ad28c
commit 82bd97aed0
9 files changed
+99 -98

No files matched your search

+3 -3
View File
@@ -30,12 +30,12 @@ Jinja:
.. code-block:: javascript .. code-block:: javascript
define(['sources/translate', ...], function(t, ...){ define(['sources/gettext', ...], function(gettext, ...){
... ...
var alert = alertify.prompt( var alert = alertify.prompt(
t('Password Change'), gettext('Password Change'),
t('New password for %(userName)s', {userName: 'jsmith' }), gettext('New password for %(userName)s', {userName: 'jsmith' }),
... ...
) )
}) })
+1
View File
@@ -2,4 +2,5 @@
[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_
+4 -4
View File
@@ -1,6 +1,6 @@
define( define(
['jquery', 'alertify', 'pgadmin', 'sources/translate'], ['jquery', 'alertify', 'pgadmin', 'sources/gettext'],
function($, alertify, pgAdmin, t) { function($, alertify, pgAdmin, gettext) {
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: t("OK"), key: 27, className: "btn btn-primary" }], buttons:[{ text: gettext("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(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);
}); });
} }
}; };
@@ -1,8 +1,8 @@
define([ define([
'require', 'jquery', 'pgadmin', 'underscore', 'backbone', 'sources/translate', 'flotr2', 'wcdocker', 'require', 'jquery', 'pgadmin', 'underscore', 'backbone', 'sources/gettext', 'flotr2', 'wcdocker',
'pgadmin.browser', 'bootstrap' 'pgadmin.browser', 'bootstrap'
], ],
function(r, $, pgAdmin, _, Backbone, t) { function(r, $, pgAdmin, _, Backbone, gettext) {
var wcDocker = window.wcDocker, var wcDocker = window.wcDocker,
pgBrowser = pgAdmin.Browser; pgBrowser = pgAdmin.Browser;
@@ -41,7 +41,7 @@ function(r, $, pgAdmin, _, Backbone, t) {
}, },
error: function (xhr, status) { error: function (xhr, status) {
$(div).html( $(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) { error: function (xhr, status) {
$(div).html( $(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 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 = 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'; cls = 'info';
} else { } else {
msg = t('An error occurred whilst rendering the graph.'); msg = gettext('An error occurred whilst rendering the graph.');
cls = 'danger'; cls = 'danger';
} }
@@ -331,11 +331,11 @@ function(r, $, pgAdmin, _, Backbone, t) {
// 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 = 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'; cls = 'info';
} else { } else {
msg = t('An error occurred whilst rendering the table.'); msg = gettext('An error occurred whilst rendering the table.');
cls = 'danger'; cls = 'danger';
} }
@@ -400,37 +400,37 @@ function(r, $, pgAdmin, _, Backbone, t) {
var server_activity_columns = [{ var server_activity_columns = [{
name: "pid", name: "pid",
label: t('PID'), label: gettext('PID'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "datname", name: "datname",
label: t('Database'), label: gettext('Database'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "usename", name: "usename",
label: t('User'), label: gettext('User'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "application_name", name: "application_name",
label: t('Application'), label: gettext('Application'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "client_addr", name: "client_addr",
label: t('Client'), label: gettext('Client'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "backend_start", name: "backend_start",
label: t('Backend start'), label: gettext('Backend start'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "state", name: "state",
label: t('State'), label: gettext('State'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];
@@ -439,7 +439,7 @@ function(r, $, pgAdmin, _, Backbone, t) {
server_activity_columns = server_activity_columns.concat( server_activity_columns = server_activity_columns.concat(
[{ [{
name: "waiting", name: "waiting",
label: t('Waiting?'), label: gettext('Waiting?'),
editable: false, editable: false,
cell: "string" cell: "string"
}]); }]);
@@ -447,12 +447,12 @@ function(r, $, pgAdmin, _, Backbone, t) {
server_activity_columns = server_activity_columns.concat( server_activity_columns = server_activity_columns.concat(
[{ [{
name: "wait_event", name: "wait_event",
label: t('Wait Event'), label: gettext('Wait Event'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "blocking_pids", name: "blocking_pids",
label: t('Blocking PIDs'), label: gettext('Blocking PIDs'),
editable: false, editable: false,
cell: "string" cell: "string"
}]); }]);
@@ -460,121 +460,121 @@ function(r, $, pgAdmin, _, Backbone, t) {
var server_locks_columns = [{ var server_locks_columns = [{
name: "pid", name: "pid",
label: t('PID'), label: gettext('PID'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "datname", name: "datname",
label: t('Database'), label: gettext('Database'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "locktype", name: "locktype",
label: t('Lock type'), label: gettext('Lock type'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "relation", name: "relation",
label: t('Target relation'), label: gettext('Target relation'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "page", name: "page",
label: t('Page'), label: gettext('Page'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "tuple", name: "tuple",
label: t('Tuple'), label: gettext('Tuple'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "virtualxid", name: "virtualxid",
label: t('vXID (target)'), label: gettext('vXID (target)'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "transactionid", name: "transactionid",
label: t('XID (target)'), label: gettext('XID (target)'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "classid", name: "classid",
label: t('Class'), label: gettext('Class'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "objid", name: "objid",
label: t('Object ID'), label: gettext('Object ID'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "virtualtransaction", name: "virtualtransaction",
label: t('vXID (owner)'), label: gettext('vXID (owner)'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "mode", name: "mode",
label: t('Mode'), label: gettext('Mode'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "granted", name: "granted",
label: t('Granted?'), label: gettext('Granted?'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];
var server_prepared_columns = [{ var server_prepared_columns = [{
name: "git", name: "git",
label: t('Name'), label: gettext('Name'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "database", name: "database",
label: t('Database'), label: gettext('Database'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "Owner", name: "Owner",
label: t('Owner'), label: gettext('Owner'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "transaction", name: "transaction",
label: t('XID'), label: gettext('XID'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "prepared", name: "prepared",
label: t('Prepared at'), label: gettext('Prepared at'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];
var server_config_columns = [{ var server_config_columns = [{
name: "name", name: "name",
label: t('Name'), label: gettext('Name'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "category", name: "category",
label: t('Category'), label: gettext('Category'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "setting", name: "setting",
label: t('Setting'), label: gettext('Setting'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "unit", name: "unit",
label: t('Unit'), label: gettext('Unit'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "short_desc", name: "short_desc",
label: t('Description'), label: gettext('Description'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];
@@ -677,32 +677,32 @@ function(r, $, pgAdmin, _, Backbone, t) {
var database_activity_columns = [{ var database_activity_columns = [{
name: "pid", name: "pid",
label: t('PID'), label: gettext('PID'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "usename", name: "usename",
label: t('User'), label: gettext('User'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "application_name", name: "application_name",
label: t('Application'), label: gettext('Application'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "client_addr", name: "client_addr",
label: t('Client'), label: gettext('Client'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "backend_start", name: "backend_start",
label: t('Backend start'), label: gettext('Backend start'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "state", name: "state",
label: t('State'), label: gettext('State'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];
@@ -711,7 +711,7 @@ function(r, $, pgAdmin, _, Backbone, t) {
database_activity_columns = database_activity_columns.concat( database_activity_columns = database_activity_columns.concat(
[{ [{
name: "waiting", name: "waiting",
label: t('Waiting?'), label: gettext('Waiting?'),
editable: false, editable: false,
cell: "string" cell: "string"
}]); }]);
@@ -719,12 +719,12 @@ function(r, $, pgAdmin, _, Backbone, t) {
database_activity_columns = database_activity_columns.concat( database_activity_columns = database_activity_columns.concat(
[{ [{
name: "wait_event", name: "wait_event",
label: t('Wait Event'), label: gettext('Wait Event'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "blocking_pids", name: "blocking_pids",
label: t('Blocking PIDs'), label: gettext('Blocking PIDs'),
editable: false, editable: false,
cell: "string" cell: "string"
}]); }]);
@@ -732,84 +732,84 @@ function(r, $, pgAdmin, _, Backbone, t) {
var database_locks_columns = [{ var database_locks_columns = [{
name: "pid", name: "pid",
label: t('PID'), label: gettext('PID'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "locktype", name: "locktype",
label: t('Lock type'), label: gettext('Lock type'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "relation", name: "relation",
label: t('Target relation'), label: gettext('Target relation'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "page", name: "page",
label: t('Page'), label: gettext('Page'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "tuple", name: "tuple",
label: t('Tuple'), label: gettext('Tuple'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "virtualxid", name: "virtualxid",
label: t('vXID (target)'), label: gettext('vXID (target)'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "transactionid", name: "transactionid",
label: t('XID (target)'), label: gettext('XID (target)'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "classid", name: "classid",
label: t('Class'), label: gettext('Class'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "objid", name: "objid",
label: t('Object ID'), label: gettext('Object ID'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "virtualtransaction", name: "virtualtransaction",
label: t('vXID (owner)'), label: gettext('vXID (owner)'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "mode", name: "mode",
label: t('Mode'), label: gettext('Mode'),
editable: false, editable: false,
cell: "string" cell: "string"
},{ },{
name: "granted", name: "granted",
label: t('Granted?'), label: gettext('Granted?'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];
var database_prepared_columns = [{ var database_prepared_columns = [{
name: "git", name: "git",
label: t('Name'), label: gettext('Name'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "Owner", name: "Owner",
label: t('Owner'), label: gettext('Owner'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "transaction", name: "transaction",
label: t('XID'), label: gettext('XID'),
editable: false, editable: false,
cell: "string" cell: "string"
}, { }, {
name: "prepared", name: "prepared",
label: t('Prepared at'), label: gettext('Prepared at'),
editable: false, editable: false,
cell: "string" cell: "string"
}]; }];
@@ -1,9 +1,9 @@
define( define(
['jquery', 'alertify', 'pgadmin', 'underscore', 'backform', 'pgadmin.browser', ['jquery', 'alertify', 'pgadmin', 'underscore', 'backform', 'pgadmin.browser',
'sources/translate', 'pgadmin.backform'], 'sources/gettext', '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, t) { function($, alertify, pgAdmin, _, Backform, pgBrowser, gettext) {
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: t('True'), onText: gettext('True'),
offText: t('False'), offText: gettext('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: t('Show'), onText: gettext('Show'),
offText: t('Hide'), offText: gettext('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'>" +
t('Category is not selected.') + gettext('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: 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 }, focus: { element: 0 },
options: { options: {
padding: !1, padding: !1,
overflow: !1, overflow: !1,
title: t('Preferences'), title: gettext('Preferences'),
closableByDimmer: false, closableByDimmer: false,
modal:false, modal:false,
pinnable: false pinnable: false
@@ -383,7 +383,7 @@ define(
return; return;
} }
if (e.button.text == t('OK')){ if (e.button.text == gettext('OK')){
preferences.updateAll(); preferences.updateAll();
} }
}, },
@@ -1,8 +1,8 @@
define( 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. // This defines the Preference/Options Dialog for pgAdmin IV.
function($, alertify, pgAdmin, _, Backform, t) { function($, alertify, pgAdmin, _, Backform, gettext) {
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(t('Reset layout'), alertify.confirm(gettext('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.'), 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() { function() {
var reloadingIndicator = $('<div id="reloading-indicator"></div>'); var reloadingIndicator = $('<div id="reloading-indicator"></div>');
$('body').append(reloadingIndicator); $('body').append(reloadingIndicator);
@@ -9,7 +9,7 @@ define(["translations"], function (translations) {
* @param {String} text * @param {String} text
* @param {Object} substitutions * @param {Object} substitutions
*/ */
return function translate(text, substitutions) { return function gettext(text, substitutions) {
var rawTranslation = translations[text] ? translations[text] : text; var rawTranslation = translations[text] ? translations[text] : text;
+3 -3
View File
@@ -1,4 +1,4 @@
define(['sources/translate', 'alertify'], function (t, alertify) { define(['sources/gettext', 'alertify'], function (gettext, 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/translate', 'alertify'], function (t, alertify) {
document.execCommand('copy'); document.execCommand('copy');
} catch (err) { } catch (err) {
alertify.alert( alertify.alert(
t('Error'), gettext('Error'),
t('Oops, unable to copy to clipboard')); gettext('Oops, unable to copy to clipboard'));
} }
document.body.removeChild(textArea); document.body.removeChild(textArea);
@@ -7,20 +7,20 @@
// //
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
define(["sources/translate", "translations"], function (translate, translations) { define(["sources/gettext", "translations"], function (gettext, 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(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 () { describe("when there are substitutions", function () {
it("interpolates a substitution", 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 () { it("interpolates multiple substitutions", function () {
expect(translate("translate '%(text)s' for %(person)s", expect(gettext("translate '%(text)s' for %(person)s",
{ {
"text": "constitution", "text": "constitution",
"person": "Sarah" "person": "Sarah"
@@ -38,12 +38,12 @@ define(["sources/translate", "translations"], function (translate, translations)
}); });
it("returns the translation", function () { 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 () { describe("when there is a substitution", function () {
it("interpolates the 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"); .toEqual("eine weitere Uebersetzung fuer Sarah");
}); });
}); });