From: Dan Scott Date: Fri, 17 Aug 2012 19:06:59 +0000 (-0400) Subject: TPAC i18n: Turn UA locales into Evergreen locales X-Git-Url: http://git.equinoxoli.org/?p=transitory.git;a=commitdiff_plain;h=44f601f85bd37095fa986ac43e13d851c243ba42 TPAC i18n: Turn UA locales into Evergreen locales We need to convert the likes of fr_ca into fr-CA to be able to pull the appropriate localized values from the database via CStoreEditor. Signed-off-by: Dan Scott Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm index 02cf017..44c6018 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm @@ -170,9 +170,8 @@ sub load_context { $cgi->cookie(OILS_HTTP_COOKIE_LOCALE) || parse_accept_lang($r->headers_in->get('Accept-Language')) || 'en_us'; - # set the editor default locale for each page load - $OpenILS::Utils::CStoreEditor::default_locale = $ctx->{locale}; + $OpenILS::Utils::CStoreEditor::default_locale = parse_eg_locale($ctx->{locale}); my $mprefix = $ctx->{media_prefix}; if($mprefix and $mprefix !~ /^http/ and $mprefix !~ /^\//) { @@ -183,7 +182,7 @@ sub load_context { return $ctx; } -# turn Accept-Language into sometihng EG can understand +# turn Accept-Language into something EG can understand # TODO: try all langs, not just the first sub parse_accept_lang { my $al = shift; @@ -195,6 +194,18 @@ sub parse_accept_lang { return $locale; } +# Accept-Language uses locales like 'en', 'fr', 'fr_fr', while Evergreen +# internally uses 'en-US', 'fr-CA', 'fr-FR' (always with the 2 lowercase, +# hyphen, 2 uppercase convention) +sub parse_eg_locale { + my $ua_locale = shift || 'en_us'; + + $ua_locale =~ m/^(..).?(..)?$/; + my $lang_code = lc($1); + my $region_code = $2 ? uc($2) : uc($1); + return "$lang_code-$region_code"; +} + # Given a URI, finds the configured template and any extra page # arguments (trailing path info). Any extra data is returned # as page arguments, in the form of an array, one item per