javascript translations and default format html

This commit is contained in:
2012-09-17 18:35:16 +02:00
parent 29848bb3cf
commit 2b2b81c23b
7 changed files with 75 additions and 15 deletions
+11 -3
View File
@@ -53,6 +53,12 @@ var translations = {
selected_products: {
order: 'Order',
clear: 'Clear'
},
join_request: {
title: 'Join request',
body: '%{email} wants to join the table',
reject: 'Reject',
approve: 'Approve'
}
}
function redirect_to(mapping, variables){
@@ -61,7 +67,7 @@ function redirect_to(mapping, variables){
for(var name in variables){
vars.push(name + '=' +variables[name])
}
window.location = path_mapping[mapping] + '?' + vars.join('&')
window.location = path_mapping[mapping] + '.html?' + vars.join('&')
}
function currency(num) {
return Qwaiter.currency(num);
@@ -69,8 +75,9 @@ function currency(num) {
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
function t(path){
var parts = path.split('.')
function t(path, vars){
vars || (vars = {});
var parts = path.split('.');
var accessor = 'translations["' + parts.join('"]["')+ '"]';
var result;
try{
@@ -78,5 +85,6 @@ function t(path){
} catch(err){
result = parts[parts.length - 1].capitalize();
}
$.each(vars, function(v, value){ result = result.replace('%{'+v+'}', value)});
return result;
}