bug 985: move binding to a gettext domain into a separate method and
authorMichael Tänzer <neo@nhng.de>
Sun, 16 Oct 2011 20:47:02 +0000 (22:47 +0200)
committerMichael Tänzer <neo@nhng.de>
Sun, 16 Oct 2011 20:47:02 +0000 (22:47 +0200)
update some more legacy language handling

removed screenshot() as it's never used and language dependent

still open: translation in PDFs

Signed-off-by: Michael Tänzer <neo@nhng.de>
CommModule/client.pl
includes/general.php
includes/lib/l10n.php
includes/loggedin.php
pages/wot/5.php
scripts/removedead.php
www/capnew.php
www/coapnew.php
www/index.php
www/wot.php

index 44be6f2..bf92b27 100755 (executable)
@@ -595,7 +595,7 @@ sub OpenPGPextractExpiryDate ($)
 # Sets the locale according to the users preferred language
 sub setUsersLanguage($)
 {
-  my $lang="de_DE"; 
+  my $lang="en_US";
   print "Searching for the language of the user $_[0]\n";
   my @a=$dbh->selectrow_array("select language from users where id='".int($_[0])."'");
   $lang = $1 if($a[0]=~m/(\w+_[\w.@]+)/);
index d608d2d..8687ee6 100644 (file)
@@ -72,6 +72,7 @@
        }
 
        L10n::detect_language();
+       L10n::init_gettext();
 
         if(array_key_exists('profile',$_SESSION) && is_array($_SESSION['profile']) && array_key_exists('id',$_SESSION['profile']) && $_SESSION['profile']['id'] > 0)
        {
                return(utf8_decode($data));
        }
 
-       function screenshot($img)
-       {
-               if(file_exists("../screenshots/".$_SESSION['_config']['language']."/$img"))
-                       return("/screenshots/".$_SESSION['_config']['language']."/$img");
-               else
-                       return("/screenshots/en/$img");
-       }
-
        function signmail($to, $subject, $message, $from, $replyto = "")
        {
                if($replyto == "")
index 58b6859..1a8109b 100644 (file)
@@ -228,7 +228,8 @@ class L10n {
        /**
         * Get the set translation
         * 
-        * @return string a translation code or the empty string if not set
+        * @return string
+        *              a translation code or the empty string if not set
         */
        public static function get_translation() {
                if (array_key_exists('language', $_SESSION['_config'])) {
@@ -241,8 +242,8 @@ class L10n {
        /**
         * Set the translation to use.
         * 
-        * @param string $translation_code    the translation code as specified in
-        *              the keys of {@link translations}
+        * @param string $translation_code
+        *              the translation code as specified in the keys of {@link $translations}
         * 
         * @return bool
         *              <ul>
@@ -297,37 +298,46 @@ class L10n {
                        return false;
                }
                
-               // configure gettext
-               $domain = 'messages';
-               bindtextdomain($domain, $_SESSION['_config']['filepath']."/locale");
-               textdomain($domain);
-               
-               
-               // save the setting
-               $_SESSION['_config']['language'] = $translation_code;
                
-               
-               // Set up the recode settings needed e.g. in PDF creation
-               $_SESSION['_config']['recode'] = "html..latin-1";
-               
-               if($translation_code === "zh-cn" || $translation_code === "zh-tw")
-               {
-                       $_SESSION['_config']['recode'] = "html..gb2312";
+               // only set if we're running in a server not in a script
+               if (isset($_SESSION)) {
+                       // save the setting
+                       $_SESSION['_config']['language'] = $translation_code;
                        
-               } else if($translation_code === "pl" || $translation_code === "hu") {
-                       $_SESSION['_config']['recode'] = "html..ISO-8859-2";
                        
-               } else if($translation_code === "ja") {
-                       $_SESSION['_config']['recode'] = "html..SHIFT-JIS";
-                       
-               } else if($translation_code === "ru") {
-                       $_SESSION['_config']['recode'] = "html..ISO-8859-5";
-                       
-               } else if($translation_code == "lt") { // legacy, keep for reference
-                       $_SESSION['_config']['recode'] = "html..ISO-8859-13";
+                       // Set up the recode settings needed e.g. in PDF creation
+                       $_SESSION['_config']['recode'] = "html..latin-1";
                        
+                       if($translation_code === "zh-cn" || $translation_code === "zh-tw")
+                       {
+                               $_SESSION['_config']['recode'] = "html..gb2312";
+                               
+                       } else if($translation_code === "pl" || $translation_code === "hu") {
+                               $_SESSION['_config']['recode'] = "html..ISO-8859-2";
+                               
+                       } else if($translation_code === "ja") {
+                               $_SESSION['_config']['recode'] = "html..SHIFT-JIS";
+                               
+                       } else if($translation_code === "ru") {
+                               $_SESSION['_config']['recode'] = "html..ISO-8859-5";
+                               
+                       } else if($translation_code == "lt") { // legacy, keep for reference
+                               $_SESSION['_config']['recode'] = "html..ISO-8859-13";
+                               
+                       }
                }
                
                return true;
        }
+       
+       /**
+        * Sets up the text domain used by gettext
+        * 
+        * @param string $domain
+        *              the gettext domain that should be used, defaults to "messages"
+        */
+       public static function init_gettext($domain = 'messages') {
+               bindtextdomain($domain, $_SESSION['_config']['filepath'].'/locale');
+               textdomain($domain);
+       }
 }
\ No newline at end of file
index bf6b455..5734fad 100644 (file)
@@ -17,6 +17,7 @@
 */
 
        include_once("../includes/lib/general.php");
+       require_once("../includes/lib/l10n.php");
 
        if($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] && $_SESSION['profile']['id'] > 0 && $_SESSION['profile']['loggedin'] != 0)
        {
 
                if($_SESSION['profile']['language'] == "")
                {
-                       $query = "update `users` set `language`='".$_SESSION['_config']['language']."'
+                       $query = "update `users` set `language`='".L10n::get_translation()."'
                                                        where `id`='".$_SESSION['profile']['id']."'";
                        mysql_query($query);
                } else {
-                       $_SESSION['_config']['language'] = $_SESSION['profile']['language'];
-
-                       putenv("LANG=".$_SESSION['_config']['language']);
-                       setlocale(LC_ALL, $_SESSION['_config']['language']);
-
-                       $domain = 'messages';
-                       bindtextdomain("$domain", $_SESSION['_config']['filepath']."/locale");
-                       textdomain("$domain");
+                       L10n::set_translation($_SESSION['profile']['language']);
+                       L10n::init_gettext();
                }
        }
 
index 4b574af..8b56fa5 100644 (file)
@@ -39,7 +39,7 @@
 <select name="reminder-lang">
 <?
        if($_SESSION['_config']['reminder-lang'] == "")
-               $_SESSION['_config']['reminder-lang'] = $_SESSION['profile']['language'];
+               $_SESSION['_config']['reminder-lang'] = L10n::get_translation();
         foreach(L10n::$translations as $key => $val)
         {
                 echo "<option value='$key'";
index 7e47c7f..23c4cd9 100755 (executable)
@@ -18,6 +18,7 @@
 */
 
        include_once("/home/cacert/www/includes/mysql.php");
+       require_once('/home/cacert/www/includes/lib/l10n.php');
 
        $query = "select * from `users` where `users`.`verified`=0 and
                        (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(`users`.`created`)) >= 172800";
@@ -67,9 +68,7 @@
 
                 if($data['language'] != "")
                 {
-                        $userlang = $data['language'];
-                        putenv("LANG=".$userlang);
-                        setlocale(LC_ALL, $userlang);
+                        L10n::set_translation($data['language']);
                 }
 
                 $body  = _("You are receiving this email because you had a temporary increase to 200 points. This has since expired and you have been reduced to 150 points.")."\n\n";
index 3136993..abcc855 100644 (file)
@@ -168,7 +168,7 @@ define('REV', '$Revision: 1.3 $');
 **     $_GET['format'] paper format required A0-A6,Letter, Folio, B0-B6 (dflt A4)
 **     $_GET['watermark'] watermark on the page
 **     $_GET['orientation'] paper orientation default 'portrait'
-**     $_SESSION['_config']['language'] for 'ja_JP' japanese default != ja_JP
+**     $_SESSION['_config']['language'] for 'ja' japanese default != ja
 **     $_SESSION['_config']['recode'] = 'format' recode() uses it: needed ?
 **     recode() is aliased to php lib function recode_string()
 **     $_REQUEST['bw'] if exists use black/white, default use colour
@@ -336,7 +336,7 @@ define('DFL_FORMAT', 'html..utf-8');
 // Japanese is not supported?
 if( array_key_exists('_config', $_SESSION) ) {
     if( isset($_SESSION['_config']['language']) ) {
-        if($_SESSION['_config']['language'] == 'ja_JP')
+        if($_SESSION['_config']['language'] == 'ja')
             define('FONT','SJIS');
         else define( 'FONT', 'freesans');
     }
index c9e4e47..1fe8610 100644 (file)
@@ -179,7 +179,7 @@ define('REV', '$Revision: 1.3 $');
 **     $_GET['format'] paper format required A0-A6,Letter, Folio, B0-B6 (dflt A4)
 **     $_GET['watermark'] watermark on the page
 **     $_GET['orientation'] paper orientation default "landscape" default 2-up (new)
-**     $_SESSION['_config']['language'] for "ja_JP" japanese default != ja_JP
+**     $_SESSION['_config']['language'] for "ja" japanese default != ja
 **     $_SESSION['_config']['recode'] = "format" recode() uses it: needed ?
 **     recode() is aliased to php lib function recode_string()
 **     $_REQUEST[bw] if exists use black/white, default use colour
@@ -371,7 +371,7 @@ define('DFL_FORMAT', 'html..utf-8');
 // Japanese is not supported?
 if( array_key_exists('_config', $_SESSION) ) {
     if( isset($_SESSION['_config']['language']) ) {
-        if($_SESSION['_config']['language'] == "ja_JP")
+        if($_SESSION['_config']['language'] == "ja")
             define('FONT','SJIS');
         else define( 'FONT', 'freesans');
     }
index a139c4a..b8cfbf3 100644 (file)
@@ -14,8 +14,9 @@
     You should have received a copy of the GNU General Public License
     along with this program; if not, write to the Free Software
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-*/ ?>
-<?
+*/
+
+require_once('../includes/lib/l10n.php');
 
         $id = 0; if(array_key_exists("id",$_REQUEST)) $id=intval($_REQUEST['id']);
         $oldid = 0; if(array_key_exists("oldid",$_REQUEST)) $oldid=intval($_REQUEST['oldid']);
 
                        if($_SESSION['profile']['language'] == "")
                        {
-                               $query = "update `users` set `language`='".$_SESSION['_config']['language']."'
+                               $query = "update `users` set `language`='".L10n::get_translation()."'
                                                where `id`='".$_SESSION['profile']['id']."'";
                                mysql_query($query);
                        } else {
-                               $_SESSION['_config']['language'] = $_SESSION['profile']['language'];
-
-                               putenv("LANG=".$_SESSION['_config']['language']);
-                               setlocale(LC_ALL, $_SESSION['_config']['language']);
-
-                               $domain = 'messages';
-                               bindtextdomain("$domain", $_SESSION['_config']['filepath']."/locale");
-                               textdomain("$domain");
+                               L10n::set_translation($_SESSION['profile']['language']);
+                               L10n::init_gettext();
                        }
                        $query = "select sum(`points`) as `total` from `notary` where `to`='".$_SESSION['profile']['id']."' group by `to`";
                        $res = mysql_query($query);
                        mysql_query($query);
 
                        $body = _("Thanks for signing up with CAcert.org, below is the link you need to open to verify your account. Once your account is verified you will be able to start issuing certificates till your hearts' content!")."\n\n";
-                       $body .= "http://".$_SESSION['_config']['normalhostname']."/verify.php?type=email&emailid=$emailid&hash=$hash\n\n"; //."&"."lang=".$_SESSION['_config']['language']."\n\n";
+                       $body .= "http://".$_SESSION['_config']['normalhostname']."/verify.php?type=email&emailid=$emailid&hash=$hash\n\n";
                        $body .= _("Best regards")."\n"._("CAcert.org Support!");
 
                        sendmail($_SESSION['signup']['email'], "[CAcert.org] "._("Mail Probe"), $body, "support@cacert.org", "", "", "CAcert Support");
index 33ce4bb..904046e 100644 (file)
                        $_SESSION['profile']['points'] += $addpoints;
                }
 
-               if($_SESSION['_config']['notarise']['language'] != "")
-               {
-                       $userlang = $_SESSION['_config']['notarise']['language'];
-                       putenv("LANG=".$userlang);
-                       setlocale(LC_ALL, $userlang);
-               }
-
+               $my_translation = L10n::get_translation();
+               L10n::set_translation($_SESSION['_config']['notarise']['language']);
+               
                $body  = sprintf(_("You are receiving this email because you have been assured by %s %s (%s)."), $_SESSION['profile']['fname'], $_SESSION['profile']['lname'], $_SESSION['profile']['email'])."\n\n";
                if($_POST['points'] != $newpoints)
                        $body .= sprintf(_("You were issued %s points however the system has rounded this down to %s and you now have %s points in total."), $_POST['points'], $newpoints, ($newpoints + $drow['total']))."\n\n";
 
                sendmail($_SESSION['_config']['notarise']['email'], "[CAcert.org] "._("You've been Assured."), $body, "support@cacert.org", "", "", "CAcert Website");
 
-               putenv("LANG=".$_SESSION['profile']['language']);
-               setlocale(LC_ALL, $_SESSION['profile']['language']);
+               L10n::set_translation($my_translation);
 
                $body  = sprintf(_("You are receiving this email because you have assured %s %s (%s)."), $_SESSION['_config']['notarise']['fname'], $_SESSION['_config']['notarise']['lname'], $_SESSION['_config']['notarise']['email'])."\n\n";
                if($_POST['points'] != $newpoints)