From 52b4dae6a89f01b3d3dd612d9947c5d08adaea9f Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Sat, 25 Jul 2015 15:16:14 +0200 Subject: [PATCH] Manage localisation fallback on server side only --- public/js/vroom.js | 3 --- vroom.pl | 20 ++++++++------------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/public/js/vroom.js b/public/js/vroom.js index 17879ec..a045560 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -83,9 +83,6 @@ function localize(string){ if (locale[string]){ return locale[string]; } - else if (fallback_locale[string]){ - return fallback_locale[string]; - } return string; } diff --git a/vroom.pl b/vroom.pl index d24c1fd..62b2e28 100755 --- a/vroom.pl +++ b/vroom.pl @@ -1583,24 +1583,20 @@ get '/locales/(:lang).js' => sub { my $fallback_strings = {}; foreach my $string (keys %Vroom::I18N::fr::Lexicon){ next if $string eq ''; - $strings->{$string} = $self->l($string); - } - # If lang is not en, send also en as a fallback locale - # useful if a locale is not complete - if ($req_lang ne 'en'){ - $self->languages('en'); - foreach my $string (keys %Vroom::I18N::fr::Lexicon){ - next if $string eq ''; - $fallback_strings->{$string} = $self->l($string); + if ($self->l($string) ne ''){ + $strings->{$string} = $self->l($string); + } + else{ + $self->languages('en'); + $strings->{$string} = $self->l($string); + $self->languages($req_lang); } } # Set the user locale back $self->languages($usr_lang); - my $res = 'locale = ' . Mojo::JSON::to_json($strings) . ';'; - $res .= 'fallback_locale = ' . Mojo::JSON::to_json($fallback_strings) . ';'; # And send the response return $self->render( - text => $res, + text => 'locale = ' . Mojo::JSON::to_json($strings) . ';', format => 'application/javascript;charset=UTF-8' ); };