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

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

View File

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

View File

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

View File

@ -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);
});
}
};

View File

@ -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"
}];

View File

@ -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'
@ -333,7 +333,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>"
);
@ -359,16 +359,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
@ -383,7 +383,7 @@ define(
return;
}
if (e.button.text == t('OK')){
if (e.button.text == gettext('OK')){
preferences.updateAll();
}
},

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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");
});
});