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(); $('.bs-switch').bootstrapSwitch();
// Strings we need translated // Strings we need translated
var locale = {}; var locale = {},
def_locale = {};
// When pagination is done, how many item per page // When pagination is done, how many item per page
var itemPerPage = 20; 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 // Default ajax setup
$.ajaxSetup({ $.ajaxSetup({
url: rootUrl + 'api', url: rootUrl + 'api',
@ -56,6 +69,9 @@ function localize(string){
if (locale[string]){ if (locale[string]){
return locale[string]; return locale[string];
} }
else if (def_locale[string]){
return def_locale[string];
}
return string; return string;
} }

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

Loading…
Cancel
Save