Skip to content

Commit

Permalink
Make more strings translatable (#685)
Browse files Browse the repository at this point in the history
* Making more strings translatable

* Pass msg in to audio

* Translate the messages better, add in tests

* Splitting on the full strings
  • Loading branch information
pamelafox committed Sep 21, 2018
1 parent b7081a2 commit 676d0f3
Show file tree
Hide file tree
Showing 15 changed files with 308 additions and 227 deletions.
110 changes: 78 additions & 32 deletions build/js/live-editor.output_sql.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
this["Handlebars"] = this["Handlebars"] || {};
this["Handlebars"]["templates"] = this["Handlebars"]["templates"] || {};
this["Handlebars"]["templates"]["sql-results"] = Handlebars.template({"1":function(container,depth0,helpers,partials,data) {
return " <h1>Database Schema</h1>\n";
var helper;

return " <h1>"
+ container.escapeExpression(((helper = (helper = helpers.databaseMsg || (depth0 != null ? depth0.databaseMsg : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"databaseMsg","hash":{},"data":data}) : helper)))
+ "</h1>\n";
},"3":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {});

Expand Down Expand Up @@ -41,7 +45,11 @@ this["Handlebars"]["templates"]["sql-results"] = Handlebars.template({"1":functi
},"9":function(container,depth0,helpers,partials,data) {
return "<span class=\"schema-pk\">(PK)</span>";
},"11":function(container,depth0,helpers,partials,data) {
return " <h1>Results</h1>\n";
var helper;

return " <h1>"
+ container.escapeExpression(((helper = (helper = helpers.resultsMsg || (depth0 != null ? depth0.resultsMsg : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"resultsMsg","hash":{},"data":data}) : helper)))
+ "</h1>\n";
},"13":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {});

Expand Down Expand Up @@ -797,55 +805,91 @@ window.SQLOutput = Backbone.View.extend({
* error message. SQLlite error messages aren't always very descriptive,
* this should make common syntax errors easier to understand.
*/
getErrorMessage: function getErrorMessage(errorMessage, statement) {
errorMessage = errorMessage || "";
getErrorMessage: function getErrorMessage(sqliteError, statement) {
sqliteError = sqliteError || "";
statement = statement || "";
statement = statement.toUpperCase();

var isSyntaxError = errorMessage.indexOf(": syntax error") > -1;
var errorMessage = sqliteError;

// First, we translate SQLite errors into friendly i18n-able messages

var colTypesError = sqliteError.indexOf("valid column types") > -1;
if (colTypesError) {
errorMessage = i18n._("Please use one of the valid column types " + "when creating a table: ") + "\"TEXT\", \"NUMERIC\", \"INTEGER\", \"REAL\", \"NONE\".";
}
var uniqStr = "UNIQUE constraint failed:";
var uniqError = sqliteError.indexOf(uniqStr) > -1;
if (uniqError) {
var colName = sqliteError.split(uniqStr)[1].trim();
errorMessage = i18n._("\"UNIQUE\" constraint failed on column \"%(colName)s\".", { colName: colName });
}
var notNullStr = "NOT NULL constraint failed:";
var notNullError = sqliteError.indexOf(notNullStr) > -1;
if (notNullError) {
var colName = sqliteError.split(notNullStr)[1].trim();
errorMessage = i18n._("\"NOT NULL\" constraint failed on column \"%(colName)s\".", { colName: colName });
}
var dupColStr = "duplicate column name:";
var dupColError = sqliteError.indexOf(dupColStr) > -1;
if (dupColError) {
var colName = errorMessage.split(dupColStr)[1].trim();
errorMessage = i18n._("You have multiple columns named \"%(colName)s\" - " + "column names must be unique.", { colName: colName });
}
var unknownColStr = "no such column:";
var unknownColError = sqliteError.indexOf(unknownColStr) > -1;
if (unknownColError) {
var colName = sqliteError.split(unknownColStr)[1].trim();
errorMessage = i18n._("We can't find the column named \"%(colName)s\".", { colName: colName });
}
var noTablesError = sqliteError.indexOf("no tables specified") > -1;
if (noTablesError) {
errorMessage = i18n._("You didn't specify any tables for your \"SELECT\".");
}
// Generic syntax error messages take form: 'near \"%T\": syntax error'
var syntaxErrStr = ": syntax error";
var isSyntaxError = sqliteError.indexOf(syntaxErrStr) > -1;
if (isSyntaxError) {
errorMessage = i18n._("There's a syntax error " + errorMessage.split(":")[0]);
var nearPhrase = errorMessage.split(syntaxErrStr)[0];
errorMessage = i18n._("There's a syntax error near %(nearThing)s.", { nearThing: nearPhrase.substr(5) });
}

// Possible SELECT with missing FROM
if (errorMessage.indexOf("no such column:") !== -1 && statement.indexOf("SELECT") !== -1 && statement.indexOf("FROM") === -1) {
errorMessage += ". " + i18n._("Are you missing a FROM clause?");
// Possible INSERT with missing INTO
// Now that we've translated the base error messages,
// we add on additional helper messages for common mistakes
if (unknownColError && statement.indexOf("SELECT") !== -1 && statement.indexOf("FROM") === -1) {
errorMessage += " " + i18n._("Are you perhaps missing a \"FROM\" clause?");
} else if (isSyntaxError && statement.indexOf("INSERT") !== -1 && statement.indexOf("VALUES") !== -1 && statement.indexOf("INTO") === -1) {
errorMessage += ". " + i18n._("Are you missing the INTO keyword?");
// Possible INSERT INTO with missing VALUES
errorMessage += " " + i18n._("Are you missing the \"INTO\" keyword?");
} else if (isSyntaxError && statement.indexOf("INSERT") !== -1 && statement.indexOf("INTO") !== -1 && statement.indexOf("VALUES") === -1) {
errorMessage += ". " + i18n._("Are you missing the VALUES keyword?");
errorMessage += " " + i18n._("Are you missing the \"VALUES\" keyword?");
} else if (statement.indexOf("INTERGER") !== -1) {
errorMessage += ". " + i18n._(" Is INTEGER spelled correctly?");
errorMessage += " " + i18n._("Is \"INTEGER\" spelled correctly?");
} else if (isSyntaxError && statement.indexOf("CREATE") !== -1 && statement.search(/CREATE TABLE \w+\s\w+/) > -1) {
errorMessage += ". " + i18n._("You can't have a space in your table name.");
errorMessage += " " + i18n._("You can't have a space in your table name.");
} else if (isSyntaxError && statement.indexOf("CREATE TABLE (") > -1) {
errorMessage += ". " + i18n._("Are you missing the table name?");
errorMessage += " " + i18n._("Are you missing the table name?");
} else if (isSyntaxError && statement.indexOf("PRIMARY KEY INTEGER") !== -1) {
errorMessage += ". " + i18n._("Did you mean to put PRIMARY KEY after INTEGER?");
errorMessage += " " + i18n._("Perhaps you meant to put \"PRIMARY KEY\" after \"INTEGER\"?");
} else if (isSyntaxError && statement.indexOf("(") !== -1 && statement.indexOf(")") === -1) {
errorMessage += ". " + i18n._("Are you missing a parenthesis?");
errorMessage += " " + i18n._("Are you missing a parenthesis?");
} else if (isSyntaxError && statement.indexOf("CREATE") !== -1 && statement.indexOf("TABLE") === -1 && (statement.indexOf("INDEX") === -1 || statement.indexOf("TRIGGER") === -1 || statement.indexOf("VIEW") === -1)) {
errorMessage += ". " + i18n._("You may be missing what to create. For " + "example, CREATE TABLE...");
errorMessage += " " + i18n._("You may be missing what to create. For " + "example, \"CREATE TABLE...\"");
} else if (isSyntaxError && statement.indexOf("UPDATE") !== -1 && statement.indexOf("SET") === -1) {
errorMessage += ". " + i18n._("Are you missing the SET keyword?");
errorMessage += " " + i18n._("Are you missing the \"SET\" keyword?");
} else if (isSyntaxError && statement.search(/[^SUM]\s*\(.*\)\n*\s*\w+/) > -1 || statement.search(/\n+\s*SELECT/) > -1 || statement.search(/\)\n+\s*INSERT/) > -1) {
errorMessage += ". " + i18n._("Do you have a semi-colon after each statement?");
errorMessage += " " + i18n._("Do you have a semi-colon after each statement?");
} else if (isSyntaxError && statement.indexOf("INSERT") !== -1 && statement.search(/[^INSERT],\d*\s*[a-zA-Z]+/) > -1) {
errorMessage += ". " + i18n._("Are you missing quotes around text values?");
errorMessage += " " + i18n._("Are you missing quotes around text values?");
} else if (isSyntaxError && statement.search(/,\s*\)/) > -1) {
errorMessage += ". " + i18n._("Do you have an extra comma?");
errorMessage += " " + i18n._("Do you have an extra comma?");
} else if (isSyntaxError && statement.indexOf("INSERT,") > -1) {
errorMessage += ". " + i18n._("There shouldn't be a comma after INSERT.");
} else if (errorMessage.indexOf("column types") > -1 && statement.search(/(\w+\s*,\s*((TEXT)|(INTEGER))+)/) > -1) {
errorMessage += ". " + i18n._("Do you have an extra comma between the name and type?");
} else if (errorMessage.indexOf("column types") > -1 && statement.search(/(\w+\s+\w+\s*((TEXT)|(INTEGER)|(REAL))+)/) > -1) {
errorMessage += " " + i18n._("There shouldn't be a comma after \"INSERT\".");
} else if (colTypesError && statement.search(/(\w+\s*,\s*((TEXT)|(INTEGER))+)/) > -1) {
errorMessage += " " + i18n._("Do you have an extra comma between the name and type?");
} else if (colTypesError && statement.search(/(\w+\s+\w+\s*((TEXT)|(INTEGER)|(REAL))+)/) > -1) {
errorMessage = i18n._("You can't have a space in your column name.");
} else if (errorMessage.indexOf("UNIQUE constraint failed") !== -1) {
errorMessage += ". " + i18n._("Are you specifying a different value for each row?");
} else if (errorMessage.indexOf("duplicate column name:") !== -1) {
errorMessage = i18n._("You have multiple columns named `%(name)s` - " + "column names must be unique.", { name: errorMessage.split(":")[1].trim() });
} else if (uniqError) {
errorMessage += " " + i18n._("Are you specifying a different value for each row?");
}
return errorMessage;
},
Expand Down Expand Up @@ -1022,7 +1066,9 @@ window.SQLOutput = Backbone.View.extend({

var output = Handlebars.templates["sql-results"]({
tables: tables,
results: results
results: results,
databaseMsg: i18n._("Database Schema"),
resultsMsg: i18n._("Query results")
});

var doc = this.getDocument();
Expand Down
50 changes: 21 additions & 29 deletions build/js/live-editor.tooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,9 @@ TooltipEngine.classes.colorPicker = TooltipBase.extend({
this.$el = $(Handlebars.templates["mediapicker-modal"]({
imagesDir: this.options.imagesDir,
soundsDir: this.options.soundsDir,
classes: this.options.files
classes: this.options.files,
closeMsg: i18n._("Close"),
okMsg: i18n._("Ok")
}));
this.$el.appendTo("body").hide();
},
Expand Down Expand Up @@ -2125,7 +2127,7 @@ TooltipEngine.classes.colorPicker = TooltipBase.extend({

render: function render() {
var self = this;
this.$el = $(Handlebars.templates["mediapicker-preview"]({ isAudio: false })).appendTo("body").hide();
this.$el = $(Handlebars.templates["mediapicker-preview"]({ isAudio: false, pickMsg: i18n._("Pick file:") })).appendTo("body").hide();

this.$(".thumb").on("load", function () {
$(this).closest(".thumb-shell").find(".thumb-error").hide();
Expand Down Expand Up @@ -2226,7 +2228,7 @@ TooltipEngine.classes.colorPicker = TooltipBase.extend({

render: function render() {
var self = this;
this.$el = $(Handlebars.templates["mediapicker-preview"]({ isAudio: true })).appendTo("body").hide();
this.$el = $(Handlebars.templates["mediapicker-preview"]({ isAudio: true, pickMsg: i18n._("Pick file:") })).appendTo("body").hide();

this.$("button").on("click", function () {
self.modal.show();
Expand Down Expand Up @@ -2789,20 +2791,17 @@ this["Handlebars"]["templates"]["mediapicker-preview"] = Handlebars.template({"1
},"5":function(container,depth0,helpers,partials,data) {
return " <audio controls class=\"mediapicker-preview-file\"></audio>\n <div class=\"thumb-error\"></div>\n";
},"7":function(container,depth0,helpers,partials,data) {
return " <img src=\"/images/spinner.gif\" class=\"thumb-throbber\" />\n <div class=\"thumb-shell\">\n <img class=\"thumb\" />\n <div class=\"thumb-error\"></div>\n </div> \n";
},"9":function(container,depth0,helpers,partials,data) {
return "Pick file:";
return " <img src=\"/images/spinner.gif\" class=\"thumb-throbber\" />\n <div class=\"thumb-shell\">\n <img class=\"thumb\" />\n <div class=\"thumb-error\"></div>\n </div>\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, alias1=depth0 != null ? depth0 : (container.nullContext || {}), buffer =
"<div class=\"tooltip mediapicker-preview "
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {});

return "<div class=\"tooltip mediapicker-preview "
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.isAudio : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.program(3, data, 0),"data":data})) != null ? stack1 : "")
+ "\">\n <div class=\"mediapicker-preview-content\">\n \n"
+ "\">\n <div class=\"mediapicker-preview-content\">\n\n"
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.isAudio : depth0),{"name":"if","hash":{},"fn":container.program(5, data, 0),"inverse":container.program(7, data, 0),"data":data})) != null ? stack1 : "")
+ "\n <button class=\"kui-button kui-button-submit kui-button-primary\" style=\"padding: 5px; width: 100%; margin: 0 auto;\" >\n ";
stack1 = ((helper = (helper = helpers._ || (depth0 != null ? depth0._ : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"_","hash":{},"fn":container.program(9, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(alias1,options) : helper));
if (!helpers._) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; }
return buffer + "\n </button> \n </div>\n <div class=\"arrow\"></div>\n</div>";
+ "\n <button class=\"kui-button kui-button-submit kui-button-primary\" style=\"padding: 5px; width: 100%; margin: 0 auto;\" >\n "
+ container.escapeExpression(((helper = (helper = helpers.pickMsg || (depth0 != null ? depth0.pickMsg : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"pickMsg","hash":{},"data":data}) : helper)))
+ "\n </button>\n </div>\n <div class=\"arrow\"></div>\n</div>";
},"useData":true});;
this["Handlebars"] = this["Handlebars"] || {};
this["Handlebars"]["templates"] = this["Handlebars"]["templates"] || {};
Expand Down Expand Up @@ -2925,25 +2924,18 @@ this["Handlebars"]["templates"]["mediapicker-modal"] = Handlebars.template({"1":
+ "\">"
+ alias3(((helper = (helper = helpers.groupName || (depth0 != null ? depth0.groupName : depth0)) != null ? helper : alias2),(typeof helper === "function" ? helper.call(alias1,{"name":"groupName","hash":{},"data":data}) : helper)))
+ "</a></li>\n";
},"19":function(container,depth0,helpers,partials,data) {
return "Close";
},"21":function(container,depth0,helpers,partials,data) {
return "Ok";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1, helper, options, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=helpers.blockHelperMissing, buffer =
"<div class=\"modal mediapicker-modal\">\n <ul class=\"nav nav-tabs\" role=\"tablist\">\n"
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;

return "<div class=\"modal mediapicker-modal\">\n <ul class=\"nav nav-tabs\" role=\"tablist\">\n"
+ ((stack1 = (helpers.patchedEach || (depth0 && depth0.patchedEach) || alias2).call(alias1,(depth0 != null ? depth0.classes : depth0),{"name":"patchedEach","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </ul>\n\n <div class=\"tab-content\">\n"
+ ((stack1 = (helpers.patchedEach || (depth0 && depth0.patchedEach) || alias2).call(alias1,(depth0 != null ? depth0.classes : depth0),{"name":"patchedEach","hash":{},"fn":container.program(4, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </div>\n\n <div class=\"mediapicker-modal-footer\">\n <button type=\"button\" class=\"simple-button\" data-dismiss=\"modal\">";
stack1 = ((helper = (helper = helpers._ || (depth0 != null ? depth0._ : depth0)) != null ? helper : alias2),(options={"name":"_","hash":{},"fn":container.program(19, data, 0, blockParams, depths),"inverse":container.noop,"data":data}),(typeof helper === alias3 ? helper.call(alias1,options) : helper));
if (!helpers._) { stack1 = alias4.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; }
buffer += "</button>\n <button type=\"button\" class=\"simple-button green mediapicker-modal-submit\" data-dismiss=\"modal\">";
stack1 = ((helper = (helper = helpers._ || (depth0 != null ? depth0._ : depth0)) != null ? helper : alias2),(options={"name":"_","hash":{},"fn":container.program(21, data, 0, blockParams, depths),"inverse":container.noop,"data":data}),(typeof helper === alias3 ? helper.call(alias1,options) : helper));
if (!helpers._) { stack1 = alias4.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; }
return buffer + "</button>\n </div>\n</div>";
+ " </div>\n\n <div class=\"mediapicker-modal-footer\">\n <button type=\"button\" class=\"simple-button\" data-dismiss=\"modal\">"
+ alias4(((helper = (helper = helpers.closeMsg || (depth0 != null ? depth0.closeMsg : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"closeMsg","hash":{},"data":data}) : helper)))
+ "</button>\n <button type=\"button\" class=\"simple-button green mediapicker-modal-submit\" data-dismiss=\"modal\">"
+ alias4(((helper = (helper = helpers.okMsg || (depth0 != null ? depth0.okMsg : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"okMsg","hash":{},"data":data}) : helper)))
+ "</button>\n </div>\n</div>";
},"useData":true,"useDepths":true});;
(function () {
var ESC = 27;
Expand Down
Loading

0 comments on commit 676d0f3

Please sign in to comment.