Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

language support

By default this will check the browser's local and try to
include a js file for that locale.  English is the fallback
language.

Also, on init the page will post a message to its parent
window if one exists asking for a locale update.  The parent
window can post a message back that will update the frame's
locale.
  • Loading branch information...
commit 2a982352f1f2565d2eb326f129a34748cc8bc6ce 1 parent a8ac11e
@whitmer whitmer authored
Showing with 93 additions and 18 deletions.
  1. +16 −0 langs/en-piglatin.js
  2. +16 −0 langs/en-us.js
  3. +26 −3 main.js
  4. +35 −15 ui.js
View
16 langs/en-piglatin.js
@@ -0,0 +1,16 @@
+app.ui.messages={
+ "standalone":"Oo-Tay Un-Ray Is-Thay App-Ay In-Ay Ullscreen-Fay Ode-May, Add-Ay It-Ay Oo-Tay Our-Yay Ome-Hay Een-Scray.",
+ "excanvasfail":"Explorer-Ay Anvas-Cay Ailed-Fay: Itting-Quay.",
+ "badbrowser":"Owser-Bray Ot-Nay Upported-Say",
+ "example":"Example-Ay",
+ "version":"ersion-vay",
+ "type":"Ype-Tay",
+ "add":"Add-Ay A-Ay Ew-Nay Aph-Gray",
+ "console":"Ow-Shay Onsole-Cay",
+ "help":"Elp-Hay Age-Pay",
+ "png":"Ake-Tay Eenshot-Scray Image-Ay",
+ "showhide":"Ow-Shay/Id-Hay Aph-Gray",
+ "config":"Configure-Cay",
+ "reload":"Eset-Ray Aph-Gray"
+};
+app.ui.update_locale();
View
16 langs/en-us.js
@@ -0,0 +1,16 @@
+app.ui.messages={
+ "standalone":"To run this app in fullscreen mode, add it to your home screen.",
+ "excanvasfail":"Explorer Canvas failed: quitting.",
+ "badbrowser":"Browser not supported",
+ "example":"Example",
+ "version":"version",
+ "type":"Type",
+ "add":"Add a new equation/graph",
+ "console":"Show Console",
+ "help":"Help Page",
+ "png":"Take Screenshot Image",
+ "showhide":"Show/Hide Graph",
+ "config":"Configure",
+ "reload":"Reset Graph"
+};
+app.ui.update_locale();
View
29 main.js
@@ -683,6 +683,9 @@ function message(m){
case "translate":
app.ui.translate(s[1],s[2],s[3]);
break;
+ case "locale":
+ app.locale = s[1];
+ app.locale_updated();
case "empty":
app.empty();
break;
@@ -708,6 +711,7 @@ if(window.addEventListener){
}else{
window.attachEvent("onmessage", message);
}
+
function hashDidChange(){
app.empty();
if((location.hash || location.search).match(/^#json=/)) {
@@ -717,6 +721,9 @@ function hashDidChange(){
app.add(idx, !data.graphs[idx]);
}
}
+ if(data.locale) {
+ app.locale = data.locale;
+ }
if(data.scale) {
app.ui.set_scale.apply(this, data.scale);
}
@@ -747,10 +754,24 @@ app.translate=function(x,y,z){
app.scale=function(x,y,z){
app.ui.scale(Number(x),Number(y),Number(z));
};
+app.locale_updated = function(locale) {
+ if(locale) { app.locale = locale; }
+ if(!app.locale) { return; };
+ var script = document.createElement('script');
+ script.src = 'langs/' + app.locale.toLowerCase() + '.js';
+ document.getElementsByTagName('head')[0].appendChild(script);
+};
app.init=function (){
var fullscreen=!window.parent.length;
+
+ if(window && window.parent != window) {
+ window.parent.postMessage('locale check');
+ }
+ app.locale = $.map(['language', 'browserLanguage', 'systemLanguage', 'userLanguage'], function(key) { return window.navigator && window.navigator[key] })[0];
+
app.view_configured = (location.hash || location.search).match(/^#json=/);
- app.ui.init(fullscreen);
+ app.ui.init(fullscreen);
+ app.locale_updated();
if((location.hash || location.search).length>1){
hashDidChange();
@@ -773,11 +794,13 @@ app.init=function (){
logo.style.float="left";
div.appendChild(logo);
- div.appendChild(document.createTextNode("graph.tk - "+messages.version+" "+app.version));
+ var elem = document.createElement('span');
+ elem.innerHTML = "graph.tk - <span id='version_text'>"+app.ui.messages.version+"</span> "+app.version;
+ div.appendChild(elem);
//div.style.height="4em";
var span=document.createElement("span");
span.className="mathquill-rendered-math mathquill-editable";
- span.innerHTML='<br />'+messages.example+': '+messages.type+' <span class="textarea"><textarea></textarea></span><span class="fraction"><span class="numerator"><var>d</var></span><span class="denominator"><var>d</var><var>x</var></span><span style="width:0">&nbsp;</span></span><span><span class="paren" style="font-size: 1.89542em; ">(</span><span class=""><span class="fraction"><span class="numerator"><span>1</span></span><span class="denominator"><var>x</var></span><span style="width:0">&nbsp;</span></span></span><span class="paren" style="font-size: 1.89542em; ">)</span></span>';
+ span.innerHTML='<br /><span id="example_text">'+app.ui.messages.example+'</span>: <span id="type_text">'+app.ui.messages.type+'</span> <span class="textarea"><textarea></textarea></span><span class="fraction"><span class="numerator"><var>d</var></span><span class="denominator"><var>d</var><var>x</var></span><span style="width:0">&nbsp;</span></span><span><span class="paren" style="font-size: 1.89542em; ">(</span><span class=""><span class="fraction"><span class="numerator"><span>1</span></span><span class="denominator"><var>x</var></span><span style="width:0">&nbsp;</span></span></span><span class="paren" style="font-size: 1.89542em; ">)</span></span>';
div.appendChild(span);
app.ui.console.log(div,true);
View
50 ui.js
@@ -21,7 +21,7 @@ var overleft,overtop,overbottom,overright;
var width,height;
var gittest=1;
-var messages={
+var default_messages={
"standalone":"To run this app in fullscreen mode, add it to your home screen.",
"excanvasfail":"Explorer Canvas failed: quitting.",
"badbrowser":"Browser not supported",
@@ -59,7 +59,7 @@ app.ui=(function(){
var webkit=/[Ww]eb[kK]it/.test(navigator.userAgent);
if(/(iPhone)/i.test(navigator.userAgent)){
if(!navigator.standalone){
- alert(messages.standalone);
+ alert(app.ui.messages.standalone);
}
}
var draw;
@@ -599,11 +599,23 @@ app.ui=(function(){
}
var ui={
+ "messages":default_messages,
+ "buttons": {},
+ "update_locale": function() {
+ for(var key in app.ui.buttons) {
+ if(app.ui.buttons[key] && app.ui.messages[key]) {
+ app.ui.buttons[key].title=app.ui.messages[key];
+ }
+ }
+ $("#example_text").text(app.ui.messages['example']);
+ $("#type_text").text(app.ui.messages['type']);
+ $("#version_text").text(app.ui.messages['version']);
+ },
"remove":function(n){
- if(!ul){
- ul=document.getElementById("graphs");
- }
- ul.removeChild(n);
+ if(!ul){
+ ul=document.getElementById("graphs");
+ }
+ ul.removeChild(n);
},"png":function(render){
if(render === false) {
return canvas.toDataURL("image/png");
@@ -664,7 +676,7 @@ app.ui=(function(){
var c=compile(l__);
}catch(ex){
- warn_.firstChild.nodeValue=messages.error+": "+JSON.stringify(ex).toString();
+ warn_.firstChild.nodeValue=app.ui.messages.error+": "+JSON.stringify(ex).toString();
warn_.style.display="block";
return;
}
@@ -790,10 +802,10 @@ app.ui=(function(){
if(canvas.getContext){
ctx = canvas.getContext("2d");
}else{
- alert(messages.excanvasfail);
+ alert(app.ui.messages.excanvasfail);
}
}else if(!ctx){
- alert(messages.badbrowser);
+ alert(app.ui.messages.badbrowser);
return;
}
}
@@ -892,7 +904,7 @@ app.ui=(function(){
var _proto_input=document.createElement("input");
_proto_input.type="checkbox";
_proto_input.checked="checked";
- _proto_input.title=messages.showhide;
+ _proto_input.title=app.ui.messages.showhide;
_proto_div.appendChild(_proto_input);
@@ -909,38 +921,43 @@ app.ui=(function(){
var newfuncbtn=document.createElement("input");
newfuncbtn.value="+";
newfuncbtn.type="button";
- newfuncbtn.title=messages.add;
+ newfuncbtn.title=app.ui.messages.add;
newfuncbtn.onclick=function(){app.add()};
+ app.ui.buttons.add = newfuncbtn;
buttons.appendChild(newfuncbtn);
var newfuncbtn=document.createElement("input");
newfuncbtn.value=">_";
newfuncbtn.type="button";
- newfuncbtn.title=messages.console;
+ newfuncbtn.title=app.ui.messages.console;
newfuncbtn.onclick=function(){app.console()};
+ app.ui.buttons.console = newfuncbtn;
buttons.appendChild(newfuncbtn);
var newfuncbtn=document.createElement("input");
newfuncbtn.value=".png";
newfuncbtn.type="button";
- newfuncbtn.title=messages.png;
+ newfuncbtn.title=app.ui.messages.png;
newfuncbtn.onclick=function(){app.png()};
+ app.ui.buttons.png = newfuncbtn;
buttons.appendChild(newfuncbtn);
var newfuncbtn=document.createElement("input");
newfuncbtn.value="reload";
newfuncbtn.type="button";
- newfuncbtn.title=messages.reload;
+ newfuncbtn.title=app.ui.messages.reload;
newfuncbtn.style.display='none';
newfuncbtn.onclick=function(){location.reload()};
+ app.ui.buttons.reload = newfuncbtn;
buttons.appendChild(newfuncbtn);
if(app.view_configured==undefined && false) {
var newfuncbtn=document.createElement("input");
newfuncbtn.value="config";
newfuncbtn.type="button";
- newfuncbtn.title=messages.config;
+ newfuncbtn.title=app.ui.messages.config;
newfuncbtn.onclick=function(){app.ui.modalConfig()};
+ app.ui.buttons.config = newfuncbtn;
buttons.appendChild(newfuncbtn);
}
@@ -949,6 +966,9 @@ app.ui=(function(){
alink.innerHTML = "&nbsp;";
alink.className = 'help_button';
alink.target="_blank";
+ alink.title=app.ui.messages.help;
+ app.ui.buttons.help = alink;
+
buttons.appendChild(alink);
Please sign in to comment.
Something went wrong with that request. Please try again.