Fallback to en if current locale is not complete

master
Daniel Berteaud 10 years ago
parent c9495df2c9
commit 75238a2631
  1. 18
      public/js/vroom.js
  2. 3
      vroom.pl

@ -23,7 +23,8 @@ $('.modal').on('show.bs.modal', function(){
$('.bs-switch').bootstrapSwitch();
// Strings we need translated
var locale = {};
var locale = {},
def_locale = {};
// When pagination is done, how many item per page
var itemPerPage = 20;
@ -41,6 +42,18 @@ $.ajax({
}
});
// If current locale isn't EN, retrieve EN locale as a fallback
if (currentLang !== 'en'){
$.ajax({
url: rootUrl + 'localize/en',
type: 'GET',
dataType: 'json',
success: function(data) {
def_locale = data;
}
});
}
// Default ajax setup
$.ajaxSetup({
url: rootUrl + 'api',
@ -56,6 +69,9 @@ function localize(string){
if (locale[string]){
return locale[string];
}
else if (def_locale[string]){
return def_locale[string];
}
return string;
}

@ -1253,9 +1253,12 @@ any [qw(GET POST)] => '/invitation/:token' => { token => '' } => sub {
get '/localize/:lang' => { lang => 'en' } => sub {
my $self = shift;
my $strings = {};
my $l = $self->languages;
$self->languages($self->stash('lang'));
foreach my $string (keys %Vroom::I18N::en::Lexicon){
$strings->{$string} = $self->l($string);
}
$self->languages($l);
# Tell the client to cache it
$self->res->headers->cache_control('private,max-age=3600');
return $self->render(json => $strings);

Loading…
Cancel
Save