wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[livejournal] r23524: LJSUP-14752: SiteMessage show message in...

Committer: wisest-owl
LJSUP-14752: SiteMessage show message in wrong locale

U   trunk/cgi-bin/LJ/Widget/SiteMessages.pm
U   trunk/cgi-bin/ljlib.pl
Modified: trunk/cgi-bin/LJ/Widget/SiteMessages.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/SiteMessages.pm	2013-01-10 08:40:12 UTC (rev 23523)
+++ trunk/cgi-bin/LJ/Widget/SiteMessages.pm	2013-01-10 09:15:32 UTC (rev 23524)
@@ -14,12 +14,17 @@
 sub _format_one_message {
     my $class = shift;
     my $message = shift;
+    my $opts = shift;
 
     my $lang;
     my $remote = LJ::get_remote();
 
-    $lang = $remote->prop("browselang") if $remote; # exlude s2 context language from opportunities,
+    if ($remote) {
+        $lang = $remote->prop("browselang"); # exlude s2 context language from opportunities,
         # because S2 journal code executes BML::set_language($lang, \&LJ::Lang::get_text) with its own language
+    } else {
+        $lang = LJ::locale_to_lang ($opts->{'locale'});
+    }
 
     my $mid = $message->{'mid'};
     my $text = $class->ml( $class->ml_key("$mid.text"), undef, $lang );
@@ -49,7 +54,7 @@
 
     if ($opts{all}) {
         foreach my $message (LJ::SiteMessages->get_messages) {
-            $ret .= $class->_format_one_message($message);
+            $ret .= $class->_format_one_message($message, \%opts);
         }
     } else {
         my $message = LJ::SiteMessages->get_open_message;
@@ -63,7 +68,7 @@
         };
 
         if ($message) {
-            $ret .= $class->_format_one_message($message);
+            $ret .= $class->_format_one_message($message, \%opts);
         }
     }
 

Modified: trunk/cgi-bin/ljlib.pl
===================================================================
--- trunk/cgi-bin/ljlib.pl	2013-01-10 08:40:12 UTC (rev 23523)
+++ trunk/cgi-bin/ljlib.pl	2013-01-10 09:15:32 UTC (rev 23524)
@@ -3615,42 +3615,51 @@
     return ! LJ::conf_test($LJ::DISABLED{$conf}, @_);
 }
 
+%LJ::LANG_MAP = (
+    af    => "af_ZA",
+    be    => "be_BY",
+    da    => "da_DK",
+    de    => "de_DE",
+    eo    => "eo_EO",
+    es    => "es_ES",
+    fi    => "fi_FI",
+    fr    => "fr_FR",
+    gr    => "el_GR",
+    he    => "he_IL",
+    hi    => "hi_IN",
+    hu    => "hu_HU",
+    is    => "is_IS",
+    it    => "it_IT",
+    ja    => "ja_JP",
+    ms    => "ms_MY",
+    nb    => "nb_NO",
+    nl    => "nl_NL",
+    nn    => "nb_NO",
+    pl    => "pl_PL",
+    pt    => "pt_PT",
+    pt_BR => "pt_BR",
+    ru    => "ru_RU",
+    sv    => "sv_SE",
+    tr    => "tr_TR",
+    uk    => "uk_UA",
+    zh    => "zh_CN",
+    zh_TR => "zh_TW",
+);
+
+%LJ::R_LANG_MAP = reverse %LJ::LANG_MAP;
+
 sub lang_to_locale {
     my ($lang) = @_;
 
-    my %map = (
-        af    => "af_ZA",
-        be    => "be_BY",
-        da    => "da_DK",
-        de    => "de_DE",
-        eo    => "eo_EO",
-        es    => "es_ES",
-        fi    => "fi_FI",
-        fr    => "fr_FR",
-        gr    => "el_GR",
-        he    => "he_IL",
-        hi    => "hi_IN",
-        hu    => "hu_HU",
-        is    => "is_IS",
-        it    => "it_IT",
-        ja    => "ja_JP",
-        ms    => "ms_MY",
-        nb    => "nb_NO",
-        nl    => "nl_NL",
-        nn    => "nb_NO",
-        pl    => "pl_PL",
-        pt    => "pt_PT",
-        pt_BR => "pt_BR",
-        ru    => "ru_RU",
-        sv    => "sv_SE",
-        tr    => "tr_TR",
-        uk    => "uk_UA",
-        zh    => "zh_CN",
-        zh_TR => "zh_TW",
-    );
+    return 'en_US' unless $LJ::LANG_MAP{$lang};
+    return $LJ::LANG_MAP{$lang};
+}
 
-    return 'en_US' unless $map{$lang};
-    return $map{$lang};
+sub locale_to_lang {
+    my ($locale) = @_;
+
+    return $LJ::DEFAULT_LANG unless $LJ::R_LANG_MAP{$locale};
+    return $LJ::R_LANG_MAP{$locale};
 }
 
 sub compact_dumper {

Tags: livejournal, pl, pm, wisest-owl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments