diff --git a/public/js/vroom.js b/public/js/vroom.js index 6cfd177..5a3c803 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -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; } diff --git a/vroom.pl b/vroom.pl index a96b7b1..9ca4f45 100755 --- a/vroom.pl +++ b/vroom.pl @@ -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);