Commit 378d6c0a authored by Xavier Guimard's avatar Xavier Guimard

Launch translation (#595)

parent 1be53614
......@@ -10,12 +10,17 @@ Used variables:
###
# Translation mechanism
translationFields = {}
translatePage = (lang) ->
$("[trspan]").each ->
this.text translate this.attr 'trspan'
$.getJSON "#{window.staticPrefix}languages/#{lang}.json", (data) ->
translationFields = data
$("[trspan]").each ->
$(this).text translate $(this).attr 'trspan'
translate = (str) ->
# TODO
return if translationFields[str] then translationFields[str] else str
# Set default values
newwindow = if window.newwindow.match('1') then true else false
......@@ -165,5 +170,21 @@ $(document).ready ->
link = $("p.removeOther a").attr("href") + "&method=" + method + "&url=" + btoa(back_url)
$("p.removeOther a").attr "href", link
# Language detection
if navigator
langs = []
langs2 = []
nlangs = [ navigator.language ]
if navigator.languages
nlangs = navigator.languages
for nl in nlangs
for al in window.availableLanguages
if al == nl
langs.push al
else if al.substring(0, 1) == nl.substring(0, 1)
langs2.push al
lang = if langs[0] then langs[0] else if langs2[0] then langs2[0] else 'en';
else
lang = 'en'
translatePage(lang)
......@@ -12,16 +12,27 @@ Used variables:
*/
(function() {
var activeTimer, antiframe, getOrder, isHiddenFormValueSet, newwindow, ping, restoreOrder, setSelector, translate, translatePage,
var activeTimer, antiframe, getOrder, isHiddenFormValueSet, newwindow, ping, restoreOrder, setSelector, translate, translatePage, translationFields,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
translationFields = {};
translatePage = function(lang) {
return $("[trspan]").each(function() {
return this.text(translate(this.attr('trspan')));
return $.getJSON(window.staticPrefix + "languages/" + lang + ".json", function(data) {
translationFields = data;
return $("[trspan]").each(function() {
return $(this).text(translate($(this).attr('trspan')));
});
});
};
translate = function(str) {};
translate = function(str) {
if (translationFields[str]) {
return translationFields[str];
} else {
return str;
}
};
newwindow = window.newwindow.match('1') ? true : false;
......@@ -93,7 +104,7 @@ Used variables:
window.ping = ping;
$(document).ready(function() {
var action, authMenuTabs, back_url, link, menuIndex, menuTabs, method;
var action, al, authMenuTabs, back_url, i, j, lang, langs, langs2, len, len1, link, menuIndex, menuTabs, method, nl, nlangs, ref;
if (antiframe && top !== self) {
top.location.href = location.href;
}
......@@ -147,6 +158,29 @@ Used variables:
link = $("p.removeOther a").attr("href") + "&method=" + method + "&url=" + btoa(back_url);
$("p.removeOther a").attr("href", link);
}
if (navigator) {
langs = [];
langs2 = [];
nlangs = [navigator.language];
if (navigator.languages) {
nlangs = navigator.languages;
}
for (i = 0, len = nlangs.length; i < len; i++) {
nl = nlangs[i];
ref = window.availableLanguages;
for (j = 0, len1 = ref.length; j < len1; j++) {
al = ref[j];
if (al === nl) {
langs.push(al);
} else if (al.substring(0, 1) === nl.substring(0, 1)) {
langs2.push(al);
}
}
}
lang = langs[0] ? langs[0] : langs2[0] ? langs2[0] : 'en';
} else {
lang = 'en';
}
return translatePage(lang);
});
......
(function(){var c,d,i,a,g,j,h,e,b,k,f=[].indexOf||function(o){for(var n=0,m=this.length;n<m;n++){if(n in this&&this[n]===o){return n}}return -1};k=function(l){return $("[trspan]").each(function(){return this.text(b(this.attr("trspan")))})};b=function(l){};g=window.newwindow.match("1")?true:false;d=window.antiframe.match("0")?false:true;c=window.activeTimer.match("0")?false:true;e="#appslist";i=function(){return $.ajax({type:"POST",url:scriptname,data:{storeAppsListOrder:$(e).sortable("toArray").join()},dataType:"json"})};h=function(){var n,m,q,y,l,u,p,r,o,t,w,s,x;t=$(e);if(!((t!=null)&&appslistorder)){return null}n=appslistorder.split(",");u=t.sortable("toArray");w=[];for(q=0,r=u.length;q<r;q++){x=u[q];w[x]=x}for(p=0,o=n.length;p<o;p++){l=n[p];if(f.call(w,l)>=0){y=w[l];m=$(e+".ui-sortable").children("#"+y);s=$(e+".ui-sortable").children("#"+l);m.remove();$(e+".ui-sortable").filter(":first").append(s)}}return 1};a=function(l){return $("#lmhidden_"+l).length};j=function(){return $.ajax({type:"POST",url:scriptname,data:{ping:1},dataType:"json",success:function(l){if(l.auth){return setTimeout("ping();",pingInterval)}else{return location.reload(true)}}})};window.ping=j;$(document).ready(function(){var q,m,n,p,o,l,r;if(d&&top!==self){top.location.href=location.href}$("#appslist").sortable({axis:"y",cursor:"move",opacity:0.5,revert:true,items:"> div.category",update:function(){return i()}});h();$("div.message").fadeIn("slow");$("input[name=timezone]").val(-(new Date().getTimezoneOffset()/60));l=$("#menu").tabs({active:0});o=$('#menu a[href="#'+displaytab+'"]').parent().index();if(o<0){o=0}l.tabs("option","active",o);m=$("#authMenu").tabs({active:0});if(choicetab){m.tabs("option","active",$('#authMenu a[href="#'+choicetab+'"]').parent().index())}if(login){$("input[type=password]:first").focus()}else{$("input[type!=hidden]:first").focus()}if(g){$("#appslist a").attr("target","_blank")}if($("p.removeOther").length){q=$("form.login").attr("action");r=$("form.login").attr("method");n="";if(q.indexOf("?")!==-1){q.substring(0,q.indexOf("?"))+"?"}else{n=q+"?"}$("form.login input[type=hidden]").each(function(s){return n+="&"+$(this).attr("name")+"="+$(this).val()});p=$("p.removeOther a").attr("href")+"&method="+r+"&url="+btoa(n);$("p.removeOther a").attr("href",p)}return k(lang)})}).call(this);
\ No newline at end of file
(function(){var d,e,j,a,h,k,i,f,b,l,c,g=[].indexOf||function(o){for(var n=0,m=this.length;n<m;n++){if(n in this&&this[n]===o){return n}}return -1};c={};l=function(m){return $.getJSON(window.staticPrefix+"languages/"+m+".json",function(n){c=n;return $("[trspan]").each(function(){return $(this).text(b($(this).attr("trspan")))})})};b=function(m){if(c[m]){return c[m]}else{return m}};h=window.newwindow.match("1")?true:false;e=window.antiframe.match("0")?false:true;d=window.activeTimer.match("0")?false:true;f="#appslist";j=function(){return $.ajax({type:"POST",url:scriptname,data:{storeAppsListOrder:$(f).sortable("toArray").join()},dataType:"json"})};i=function(){var o,n,r,z,m,w,q,s,p,u,x,t,y;u=$(f);if(!((u!=null)&&appslistorder)){return null}o=appslistorder.split(",");w=u.sortable("toArray");x=[];for(r=0,s=w.length;r<s;r++){y=w[r];x[y]=y}for(q=0,p=o.length;q<p;q++){m=o[q];if(g.call(x,m)>=0){z=x[m];n=$(f+".ui-sortable").children("#"+z);t=$(f+".ui-sortable").children("#"+m);n.remove();$(f+".ui-sortable").filter(":first").append(t)}}return 1};a=function(m){return $("#lmhidden_"+m).length};k=function(){return $.ajax({type:"POST",url:scriptname,data:{ping:1},dataType:"json",success:function(m){if(m.auth){return setTimeout("ping();",pingInterval)}else{return location.reload(true)}}})};window.ping=k;$(document).ready(function(){var y,x,A,w,B,z,D,u,t,C,s,r,v,p,n,o,m,q;if(e&&top!==self){top.location.href=location.href}$("#appslist").sortable({axis:"y",cursor:"move",opacity:0.5,revert:true,items:"> div.category",update:function(){return j()}});i();$("div.message").fadeIn("slow");$("input[name=timezone]").val(-(new Date().getTimezoneOffset()/60));p=$("#menu").tabs({active:0});v=$('#menu a[href="#'+displaytab+'"]').parent().index();if(v<0){v=0}p.tabs("option","active",v);A=$("#authMenu").tabs({active:0});if(choicetab){A.tabs("option","active",$('#authMenu a[href="#'+choicetab+'"]').parent().index())}if(login){$("input[type=password]:first").focus()}else{$("input[type!=hidden]:first").focus()}if(h){$("#appslist a").attr("target","_blank")}if($("p.removeOther").length){y=$("form.login").attr("action");n=$("form.login").attr("method");w="";if(y.indexOf("?")!==-1){y.substring(0,y.indexOf("?"))+"?"}else{w=y+"?"}$("form.login input[type=hidden]").each(function(E){return w+="&"+$(this).attr("name")+"="+$(this).val()});r=$("p.removeOther a").attr("href")+"&method="+n+"&url="+btoa(w);$("p.removeOther a").attr("href",r)}if(navigator){u=[];t=[];m=[navigator.language];if(navigator.languages){m=navigator.languages}for(B=0,C=m.length;B<C;B++){o=m[B];q=window.availableLanguages;for(z=0,s=q.length;z<s;z++){x=q[z];if(x===o){u.push(x)}else{if(x.substring(0,1)===o.substring(0,1)){t.push(x)}}}}D=u[0]?u[0]:t[0]?t[0]:"en"}else{D="en"}return l(D)})}).call(this);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment