Permalink
Browse files

Handle localization for remaining UX elements

  • Loading branch information...
1 parent 8644339 commit 4e560699fc00f826cd4512053aff9cb48967a34b @deadprogram deadprogram committed Jun 27, 2012
Showing with 32 additions and 15 deletions.
  1. +26 −14 public/js/app.js
  2. +6 −1 public/js/i18n/en.js
View
40 public/js/app.js
@@ -78,11 +78,11 @@ function stopRun() {
}
function setRunButtonToStop() {
- $("#run").html('Stop');
+ $("#run").html(getLocalizedString('buttons', 'stop'));
}
function setStopButtonToRun() {
- $("#run").html('Run');
+ $("#run").html(getLocalizedString('buttons', 'run'));
}
function clearOutputs() {
@@ -167,7 +167,7 @@ function resizeCanvas() {
function setDefaultEditorContent() {
// set initial value and position
- getEditor().setValue("# Type in your code just below here:\n");
+ getEditor().setValue('# ' + getLocalizedString('editor', 'your-code') + '\n');
getAce().gotoLine(2);
}
@@ -222,14 +222,28 @@ function loadLanguage(lang){
}
function localizeUI(data) {
- $("#run").html(data['buttons']['run']);
- $("#clear").html(data['buttons']['clear']);
- $("#open").html(data['buttons']['open']);
- $("#save").html(data['buttons']['save']);
+ saveLocalizedStrings(data);
- $("#help-link").html(data['tabs']['help-link']);
- $("#output-link").html(data['tabs']['output-link']);
- $("#turtle-link").html(data['tabs']['turtle-link']);
+ $("#run").html(getLocalizedString('buttons', 'run'));
+ $("#clear").html(getLocalizedString('buttons', 'clear'));
+ $("#open").html(getLocalizedString('buttons', 'open'));
+ $("#save").html(getLocalizedString('buttons', 'save'));
+
+ $("#help-link").html(getLocalizedString('tabs', 'help-link'));
+ $("#output-link").html(getLocalizedString('tabs', 'output-link'));
+ $("#turtle-link").html(getLocalizedString('tabs', 'turtle-link'));
+
+ initEditor();
+}
+
+function saveLocalizedStrings(data) {
+ var localStrings = data ;
+ $("#container").data("localized", localStrings);
+}
+
+function getLocalizedString(t, i) {
+ var localStrings = $("#container").data("localized");
+ return localStrings[t][i];
}
function initUI() {
@@ -247,7 +261,7 @@ $(document).ready(function() {
$("#tabs").data("mytabs", tabs);
$("#run").click(function(e) {
- if ($("#run").html() == 'Run') {
+ if ($("#run").html() == getLocalizedString('buttons', 'run')) {
resizeCanvas();
$("#run").blur();
startRun(getEditor());
@@ -272,7 +286,7 @@ $(document).ready(function() {
});
$('#clear').click(function(e) {
- if (confirm("Are you sure you want to clear all your Ruby code from the editor?"))
+ if (confirm(getLocalizedString('editor', 'confirm-clear')))
clearCode();
return false;
@@ -285,6 +299,4 @@ $(document).ready(function() {
initTurtle();
selectTab(0); // default to help tab
-
- initEditor();
});
View
7 public/js/i18n/en.js
@@ -3,11 +3,16 @@
"run": "Run",
"clear": "Clear",
"open": "Open",
- "save": "Save"
+ "save": "Save",
+ "stop": "Stop"
},
"tabs": {
"help-link": "Help",
"output-link": "Output",
"turtle-link": "Turtle"
+ },
+ "editor": {
+ "your-code": "Type in your code just below here",
+ "confirm-clear": "Are you sure you want to clear all your Ruby code from the editor?"
}
}

0 comments on commit 4e56069

Please sign in to comment.