Implement waiter ordering and improvements
This commit is contained in:
+4
@@ -18,6 +18,7 @@
|
||||
// require bootstrap-typeahead
|
||||
//= require bootstrap
|
||||
//= require js-routes
|
||||
//= require translations
|
||||
//= require qwaiter
|
||||
//= require ./qsupplier
|
||||
//= require handlebars
|
||||
@@ -28,6 +29,9 @@
|
||||
//= require_self
|
||||
//= require moment
|
||||
var Qstorage = localStorage;
|
||||
|
||||
$.extend($translations.en, <%= I18n.t('supplier', locale: :en).to_json %>);
|
||||
$.extend($translations.nl, <%= I18n.t('supplier', locale: :nl).to_json %>);
|
||||
String.prototype.capitalize = function() {
|
||||
return this.charAt(0).toUpperCase() + this.slice(1);
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
var $translations = {
|
||||
en: {
|
||||
models: <%= I18n.t('activemodel.models', locale: :en).to_json %>,
|
||||
attributes: <%= I18n.t('activemodel.attributes', locale: :en).to_json %>,
|
||||
helpers: <%= I18n.t('helpers', locale: :en).to_json %>,
|
||||
pagination: <%= I18n.t('views.pagination', locale: :en).to_json %>,
|
||||
<%= I18n.t('supplier', locale: :en).to_json[1..-2] %>
|
||||
},
|
||||
nl: {
|
||||
models: <%= I18n.t('activemodel.models', locale: :nl).to_json %>,
|
||||
attributes: <%= I18n.t('activemodel.attributes', locale: :nl).to_json %>,
|
||||
helpers: <%= I18n.t('helpers', locale: :nl).to_json %>,
|
||||
pagination: <%= I18n.t('views.pagination', locale: :nl).to_json %>,
|
||||
<%= I18n.t('supplier', locale: :nl).to_json[1..-2] %>
|
||||
}
|
||||
}
|
||||
|
||||
$transformation_mappings = {
|
||||
downcase: 'toLowerCase',
|
||||
upcase: 'toUpperCase'
|
||||
}
|
||||
|
||||
function t(path, vars){
|
||||
vars || (vars = {});
|
||||
var result, m, translatable, isafety,replacable;
|
||||
var parts = path.split('.');
|
||||
var accessor = '$translations.'+$locale+'["' + parts.join('"]["')+ '"]';
|
||||
try{
|
||||
result = eval(accessor);
|
||||
} catch(err){
|
||||
result = parts[parts.length - 1].capitalize();
|
||||
}
|
||||
if(result == '') return '';
|
||||
if(!result) return parts[parts.length - 1].capitalize();
|
||||
$.each(vars, function(v, value){ result = result.replace('%{'+v+'}', value)});
|
||||
isafety = 0;
|
||||
while(result.indexOf('${') > -1){
|
||||
m = result.match(/\${([\w\.]+(\|\w+)?)}/);
|
||||
if(m[2]){
|
||||
translatable = m[1].replace(m[2], '');
|
||||
operation = $transformation_mappings[m[2].substr(1) || m[2].substr(1)];
|
||||
}else{
|
||||
translatable = m[1];
|
||||
operation = null;
|
||||
}
|
||||
replacable = t(translatable);
|
||||
if(operation) replacable = replacable[operation]();
|
||||
result = result.replace(m[0], replacable);
|
||||
if(isafety > 10) break;
|
||||
isafety += 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function setLocale(locale){
|
||||
Qstorage.setItem('locale', locale);
|
||||
$locale = locale;
|
||||
setTranslations();
|
||||
}
|
||||
function setTranslations(selector){
|
||||
var list = $('#top-navigation-list');
|
||||
list.find('.locale').show();
|
||||
list.find('.locale-'+$locale).hide();
|
||||
if(selector){
|
||||
$(selector).find('[data-t]').each(function(){$(this).html(t($(this).data('t'), $(this).data('tAttributes')))})
|
||||
}else{
|
||||
$('[data-t]').each(function(){$(this).html(t($(this).data('t'),$(this).data('tAttributes')))})
|
||||
}
|
||||
moment.lang($locale);
|
||||
$('[data-time]').each(function(){
|
||||
$(this).text(moment($(this).data('time')).format($(this).data('timeFormat') || 'dd D MMM HH:MM'))
|
||||
})
|
||||
|
||||
$('.datepicker').datepicker("option", $.datepicker.regional[$locale])
|
||||
}
|
||||
Reference in New Issue
Block a user