Source code taken from cacert-20120125.tar.bz2
authorMichael Tänzer <neo@nhng.de>
Thu, 26 Jan 2012 19:46:40 +0000 (20:46 +0100)
committerMichael Tänzer <neo@nhng.de>
Thu, 26 Jan 2012 19:46:40 +0000 (20:46 +0100)
21 files changed:
CommModule/client.pl
Makefile [deleted file]
cacertupload.pl [deleted file]
includes/account.php
includes/general.php
includes/general_stuff.php
includes/lib/l10n.php [new file with mode: 0644]
includes/loggedin.php
locale/Makefile [new file with mode: 0644]
locale/make.php [deleted file]
pages/account/41.php
pages/wot/5.php
pages/wot/9.php
password.dat.sample [deleted file]
scripts/removedead.php
www/cap.php
www/capnew.php
www/coapnew.php
www/index.php
www/ttp.php
www/wot.php

index 323ee27..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.@]+)/);
@@ -887,7 +887,7 @@ sub HandleCerts($$)
       my $body = _("Hi")." $user{fname},\n\n";
       $body .= sprintf(_("You can collect your certificate for %s by going to the following location:")."\n\n", $row{'email'}.$row{'CN'});
       $body .= "https://www.cacert.org/account.php?id=".($server?"15":"6")."&cert=$row{id}\n\n";
-      $body .= _("If you have not imported CAcert´s root certificate, please go to:")."\n";
+      $body .= _("If you have not imported CAcert's root certificate, please go to:")."\n";
       $body .= "https://www.cacert.org/index.php?id=3\n";
       $body .= "Root cert fingerprint = A6:1B:37:5E:39:0D:9C:36:54:EE:BD:20:31:46:1F:6B\n";
       $body .= "Root cert fingerprint = 135C EC36 F49C B8E9 3B1A B270 CD80 8846 76CE 8F33\n\n";
diff --git a/Makefile b/Makefile
deleted file mode 100644 (file)
index 914d979..0000000
--- a/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-all:
-       xgettext -s -o messages.po --no-wrap --foreign-user includes/*.php www/*.php pages/account/*.php pages/index/*.php pages/wot/*.php pages/gpg/*.php pages/disputes/*.php pages/help/*.php pages/disputes/*.php scripts/removedead.php
-       perl cacertupload.pl
-       cd locale; php make.php
-
-other: all
-       cat messages.po|sed "s/CHARSET/iso-8859-1/"|sed "s/PACKAGE VERSION/CAcert/"|sed "s/This file is put in the public domain./This file is distributed under the same license as the CAcert package./"|sed "s/# SOME DESCRIPTIVE TITLE.//" > messages.po
diff --git a/cacertupload.pl b/cacertupload.pl
deleted file mode 100644 (file)
index 991570b..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/usr/bin/perl
-
-#LibreSSL - CAcert web application
-#Copyright (C) 2004-2008  CAcert Inc.
-#
-#This program is free software; you can redistribute it and/or modify
-#it under the terms of the GNU General Public License as published by
-#the Free Software Foundation; version 2 of the License.
-#
-#This program is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#GNU General Public License for more details.
-#
-#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
-
-use LWP::UserAgent;
-$ua = LWP::UserAgent->new(agent => 'Translingo Client 1.0');
-use HTTP::Request::Common qw(POST);
-
-my $translingo_password;
-my $translingo_account;
-
-# Read Account&Password from file
-eval `cat password.dat`;
-
-$ua->cookie_jar({});
-$ua->timeout(10000);
-
-my $req = POST 'http://translingo.cacert.org/login.php',
-[
-];
-# ggf. Referer faken
-$req->referer('http://translingo.cacert.org/');
- $ua->request($req)->as_string;
-
-# 1.Test - Umgebung
-my $req = POST 'http://translingo.cacert.org/login.php',
-[
- username => $translingo_account,
- password => $translingo_password,
- submit => 'Login',
-];
-# ggf. Referer faken
-$req->referer('http://translingo.cacert.org/');
-$ua->request($req)->as_string;
-
-# 2.Test - FileUpload
-my $req = POST 'http://translingo.cacert.org/upload.php',
-Content_Type => 'form-data',
-Content => [
- project => '1',
- fileformat => '1',
- pofile   => ["messages.po" => "messages.po", 'Content_Type' => "application/x-gettext"],
-];
-print $ua->request($req)->as_string;
-
index 55c9f7a..554713e 100644 (file)
@@ -16,6 +16,7 @@
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
        require_once("../includes/loggedin.php");
+       require_once("../includes/lib/l10n.php");
 
        loadem("account");
 
        {
                csrf_check("mainlang");
                $lang = mysql_real_escape_string($_REQUEST['lang']);
-               foreach($_SESSION['_config']['translations'] as $key => $val)
+               foreach(L10n::$translations as $key => $val)
                {
                        if($key == $lang)
                        {
index 8481018..4919c84 100644 (file)
@@ -39,6 +39,7 @@
 
        require_once($_SESSION['_config']['filepath']."/includes/mysql.php");
        require_once($_SESSION['_config']['filepath'].'/includes/lib/account.php');
+       require_once($_SESSION['_config']['filepath'].'/includes/lib/l10n.php');
 
        if(array_key_exists('HTTP_HOST',$_SERVER) &&
                        $_SERVER['HTTP_HOST'] != $_SESSION['_config']['normalhostname'] &&
                }
        }
 
-       $lang = "";
-       if(array_key_exists("lang",$_REQUEST))
-         $lang=mysql_escape_string(substr(trim($_REQUEST['lang']), 0, 5));
-       if($lang != "")
-               $_SESSION['_config']['language'] = $lang;
-
-       //if($_SESSION['profile']['id'] == 1 && 1 == 2)
-       //      echo $_SESSION['_config']['language'];
-
-       $_SESSION['_config']['translations'] = array(
-                               "ar_JO" => "&#1575;&#1604;&#1593;&#1585;&#1576;&#1610;&#1577;",
-                               "bg_BG" => "&#1041;&#1098;&#1083;&#1075;&#1072;&#1088;&#1089;&#1082;&#1080;",
-                               "cs_CZ" => "&#268;e&scaron;tina",
-                               "da_DK" => "Dansk",
-                               "de_DE" => "Deutsch",
-                               "el_GR" => "&Epsilon;&lambda;&lambda;&eta;&nu;&iota;&kappa;&#940;",
-                               "en_AU" => "English",
-                               "eo_EO" => "Esperanto",
-                               "es_ES" => "Espa&#xf1;ol",
-                               "fa_IR" => "Farsi",
-                               "fi_FI" => "Suomi",
-                               "fr_FR" => "Fran&#xe7;ais",
-                               "he_IL" => "&#1506;&#1489;&#1512;&#1497;&#1514;",
-                               "hr_HR" => "Hrvatski",
-                               "hu_HU" => "Magyar",
-                               "is_IS" => "&Iacute;slenska",
-                               "it_IT" => "Italiano",
-                               "ja_JP" => "&#26085;&#26412;&#35486;",
-                               "ka_GE" => "Georgian",
-                               "nl_NL" => "Nederlands",
-                               "pl_PL" => "Polski",
-                               "pt_PT" => "Portugu&#xea;s",
-                               "pt_BR" => "Portugu&#xea;s Brasileiro",
-                               "ru_RU" => "&#x420;&#x443;&#x441;&#x441;&#x43a;&#x438;&#x439;",
-                               "ro_RO" => "Rom&acirc;n&#259;",
-                               "sv_SE" => "Svenska",
-                               "tr_TR" => "T&#xfc;rk&#xe7;e",
-                               "zh_CN" => "&#x4e2d;&#x6587;(&#x7b80;&#x4f53;)");
-
-        $value=array();
-
-       if(!(array_key_exists('language',$_SESSION['_config']) && $_SESSION['_config']['language'] != ""))
-       {
-               $bits = explode(",", strtolower(str_replace(" ", "", mysql_real_escape_string(array_key_exists('HTTP_ACCEPT_LANGUAGE',$_SERVER)?$_SERVER['HTTP_ACCEPT_LANGUAGE']:""))));
-               foreach($bits as $lang)
-               {
-                       $b = explode(";", $lang);
-                       if(count($b)>1 && substr($b[1], 0, 2) == "q=")
-                               $c = floatval(substr($b[1], 2));
-                       else
-                               $c = 1;
-                       $value["$c"] = trim($b[0]);
-               }
-
-               krsort($value);
-
-               reset($value);
-
-               foreach($value as $key => $val)
-               {
-                       $val = substr(escapeshellarg($val), 1, -1);
-                       $short = substr($val, 0, 2);
-                       if($val == "en" || $short == "en")
-                       {
-                               $_SESSION['_config']['language'] = "en";
-                               break;
-                       }
-                       if(file_exists($_SESSION['_config']['filepath']."/locale/$val/LC_MESSAGES/messages.mo"))
-                       {
-                               $_SESSION['_config']['language'] = $val;
-                               break;
-                       }
-                       if(file_exists($_SESSION['_config']['filepath']."/locale/$short/LC_MESSAGES/messages.mo"))
-                       {
-                               $_SESSION['_config']['language'] = $short;
-                               break;
-                       }
-               }
-       }
-       if(!array_key_exists('_config',$_SESSION) || !array_key_exists('language',$_SESSION['_config']) || strlen($_SESSION['_config']['language']) != 5)
-       {
-               $lang = array_key_exists('language',$_SESSION['_config'])?$_SESSION['_config']['language']:"";
-               $_SESSION['_config']['language'] = "en_AU";
-               foreach($_SESSION['_config']['translations'] as $key => $val)
-               {
-                       if(substr($lang, 0, 2) == substr($key, 0, 2))
-                       {
-                               $_SESSION['_config']['language'] = $val;
-                               break;
-                       }
-               }
-       }
-
-       $_SESSION['_config']['recode'] = "html..latin-1";
-       if($_SESSION['_config']['language'] == "zh_CN")
-       {
-               $_SESSION['_config']['recode'] = "html..gb2312";
-       } else if($_SESSION['_config']['language'] == "pl_PL" || $_SESSION['_config']['language'] == "hu_HU") {
-               $_SESSION['_config']['recode'] = "html..ISO-8859-2";
-       } else if($_SESSION['_config']['language'] == "ja_JP") {
-               $_SESSION['_config']['recode'] = "html..SHIFT-JIS";
-       } else if($_SESSION['_config']['language'] == "ru_RU") {
-               $_SESSION['_config']['recode'] = "html..ISO-8859-5";
-       } else if($_SESSION['_config']['language'] == "lt_LT") {
-               $_SESSION['_config']['recode'] = "html..ISO-8859-13";
-       }
-
-       putenv("LANG=".$_SESSION['_config']['language']);
-       setlocale(LC_ALL, $_SESSION['_config']['language']);
-       $domain = 'messages';
-       bindtextdomain($domain, $_SESSION['_config']['filepath']."/locale");
-       textdomain($domain);
-
-       //if($_SESSION['profile']['id'] == -1)
-       //      echo $_SESSION['_config']['language']." - ".$_SESSION['_config']['filepath']."/locale";
-
+       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 80cd8a7..4c1bd30 100644 (file)
@@ -16,6 +16,8 @@
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
+require_once($_SESSION['_config']['filepath'].'/includes/lib/l10n.php');
+
 if(!function_exists("showheader"))
 {
        function showbodycontent($title = "CAcert.org", $title2 = "")
@@ -60,7 +62,7 @@ google_color_border = "FFFFFF";
     <? include("about_menu.php"); ?>
     <div class="relatedLinks">
       <h3 class="pointer" onclick="explode('trans')">+ <?=_("Translations")?></h3>
-      <ul class="menu" id="trans"><? foreach($_SESSION['_config']['translations'] as $key => $val) { ?><li><a href="<?=$_SERVER['SCRIPT_NAME']?>?id=<?=intval(array_key_exists('id',$_REQUEST)?$_REQUEST['id']:0)?>&amp;lang=<?=$key?>"><?=$val?></a></li><? } ?></ul>
+      <ul class="menu" id="trans"><? foreach(L10n::$translations as $key => $val) { ?><li><a href="<?=$_SERVER['SCRIPT_NAME']?>?id=<?=intval(array_key_exists('id',$_REQUEST)?$_REQUEST['id']:0)?>&amp;lang=<?=$key?>"><?=$val?></a></li><? } ?></ul>
     </div>
     <? if(array_key_exists('mconn',$_SESSION) && $_SESSION['mconn']) { ?>
     <div class="relatedLinks">
diff --git a/includes/lib/l10n.php b/includes/lib/l10n.php
new file mode 100644 (file)
index 0000000..85b7aff
--- /dev/null
@@ -0,0 +1,343 @@
+<?php /*
+    LibreSSL - CAcert web application
+    Copyright (C) 2004-2011  CAcert Inc.
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; version 2 of the License.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    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
+*/
+
+/**
+ * This class provides some functions for language handling
+ */
+class L10n {
+       /**
+        * These are tranlations we currently support.
+        * 
+        * If another translation is added, it doesn't suffice to have gettext set
+        * up, you also need to add it here, because it acts as a white list.
+        * 
+        * @var array("ISO-language code" => "native name of the language")
+        */
+       public static $translations = array(
+                               "ar" => "&#1575;&#1604;&#1593;&#1585;&#1576;&#1610;&#1577;",
+                               "bg" => "&#1041;&#1098;&#1083;&#1075;&#1072;&#1088;&#1089;&#1082;&#1080;",
+                               "cs" => "&#268;e&scaron;tina",
+                               "da" => "Dansk",
+                               "de" => "Deutsch",
+                               "el" => "&Epsilon;&lambda;&lambda;&eta;&nu;&iota;&kappa;&#940;",
+                               "en" => "English",
+                               "es" => "Espa&#xf1;ol",
+                               "fi" => "Suomi",
+                               "fr" => "Fran&#xe7;ais",
+                               "hu" => "Magyar",
+                               "it" => "Italiano",
+                               "ja" => "&#26085;&#26412;&#35486;",
+                               "lv" => "Latvie&scaron;u",
+                               "nl" => "Nederlands",
+                               "pl" => "Polski",
+                               "pt" => "Portugu&#xea;s",
+                               "pt-br" => "Portugu&#xea;s Brasileiro",
+                               "ru" => "&#x420;&#x443;&#x441;&#x441;&#x43a;&#x438;&#x439;",
+                               "sv" => "Svenska",
+                               "tr" => "T&#xfc;rk&#xe7;e",
+                               "zh-cn" => "&#x4e2d;&#x6587;(&#x7b80;&#x4f53;)",
+                               "zh-tw" => "&#x4e2d;&#x6587;(&#33274;&#28771;)",
+                       );
+       
+       /**
+        * setlocale needs a language + region code for whatever reason so here's
+        * the mapping from a translation code to locales with the region that
+        * seemed the most common for this language
+        * 
+        * You probably never need this. Use {@link set_translation()} to change the
+        * language instead of manually calling setlocale().
+        * 
+        * @var array(string => string)
+        */
+       private static $locales = array(
+                               "ar" => "ar_JO",
+                               "bg" => "bg_BG",
+                               "cs" => "cs_CZ",
+                               "da" => "da_DK",
+                               "de" => "de_DE",
+                               "el" => "el_GR",
+                               "en" => "en_US",
+                               "es" => "es_ES",
+                               "fa" => "fa_IR",
+                               "fi" => "fi_FI",
+                               "fr" => "fr_FR",
+                               "he" => "he_IL",
+                               "hr" => "hr_HR",
+                               "hu" => "hu_HU",
+                               "id" => "id_ID",
+                               "is" => "is_IS",
+                               "it" => "it_IT",
+                               "ja" => "ja_JP",
+                               "ka" => "ka_GE",
+                               "ko" => "ko_KR",
+                               "lv" => "lv_LV",
+                               "nb" => "nb_NO",
+                               "nl" => "nl_NL",
+                               "pl" => "pl_PL",
+                               "pt" => "pt_PT",
+                               "pt-br" => "pt_BR",
+                               "ro" => "ro_RO",
+                               "ru" => "ru_RU",
+                               "sl" => "sl_SI",
+                               "sv" => "sv_SE",
+                               "th" => "th_TH",
+                               "tr" => "tr_TR",
+                               "uk" => "uk_UA",
+                               "zh-cn" => "zh_CN",
+                               "zh-tw" => "zh_TW",
+                       );
+       
+       /**
+        * Auto-detects the language that should be used and sets it. Only works for
+        * HTTP, not in a command line script.
+        * 
+        * Priority:
+        * <ol>
+        *      <li>explicit parameter "lang" passed in HTTP (e.g. via GET)</li>
+        *      <li>existing setting in the session (stick to the setting we had before)
+        *              </li>
+        *      <li>auto-detect via the HTTP Accept-Language header sent by the user
+        *              agent</li>
+        * </ol>
+        */
+       public static function detect_language() {
+               if (    (self::get_translation() != "")
+                           // already set in the session?
+                   &&
+                       !(array_key_exists("lang", $_REQUEST) &&
+                           trim($_REQUEST["lang"]) != "")
+                           // explicit parameter?
+                   )
+               {
+                       if ( self::set_translation(self::get_translation()) ) {
+                               return;
+                       }
+               }
+               
+               
+               $languages = array();
+               
+               // parse Accept-Language header
+               if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
+                       $bits = explode(",", strtolower(
+                                               str_replace(" ", "", $_SERVER['HTTP_ACCEPT_LANGUAGE'])
+                                       ));
+                       foreach($bits as $lang)
+                       {
+                               $b = explode(";", $lang);
+                               if(count($b)>1 && substr($b[1], 0, 2) == "q=")
+                                       $c = floatval(substr($b[1], 2));
+                               else
+                                       $c = 1;
+                               
+                               if ($c != 0)
+                               {
+                                       $languages[trim($b[0])] = $c;
+                               }
+                       }
+               }
+               
+               // check if there is an explicit language given as parameter
+               if(array_key_exists("lang",$_REQUEST) && trim($_REQUEST["lang"]) != "")
+               {
+                       // higher priority than those values in the header
+                       $languages[strtolower(trim($_REQUEST["lang"]))] = 2.0;
+               }
+               
+               arsort($languages, SORT_NUMERIC);
+               
+               // this is used to be compatible with browsers like internet
+               // explorer which only provide the language code including the
+               // region not without. Also handles the fallback to English (qvalues
+               // may only have three digits after the .)
+               $fallbacks = array("en" => 0.0005);
+               
+               foreach($languages as $lang => $qvalue)
+               {
+                       // ignore any non-conforming values (that's why we don't need to
+                       // mysql_real_escape() or escapeshellarg(), but take care of
+                       // the '*')
+                       // spec: ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )
+                       if ( preg_match('/^(?:([a-zA-Z]{1,8})(?:-[a-zA-Z]{1,8})*|\*)$/',
+                                          $lang, $matches) !== 1 ) {
+                               continue;
+                       }
+                       $lang_prefix = $matches[1]; // usually two-letter language code
+                       $fallbacks[$lang_prefix] = $qvalue;
+                       
+                       $chosen_translation = "";
+                       if ($lang === '*') {
+                               // According to the standard '*' matches anything but any
+                               // language explicitly specified. So in theory if there
+                               // was an explicit mention of "en" with a lower priority
+                               // this would be incorrect, but that's too much trouble.
+                               $chosen_translation = "en";
+                       } else {
+                               $lang_length = strlen($lang);
+                               foreach (self::$translations as $translation => $ignore)
+                               {
+                                       // May match exactly or on every '-'
+                                       if ( $translation === $lang ||
+                                                substr($translation, 0, $lang_length + 1)
+                                                    === $lang.'-'
+                                           )
+                                       {
+                                               $chosen_translation = $translation;
+                                               break;
+                                       }
+                               }
+                       }
+                       
+                       if ($chosen_translation !== "")
+                       {
+                               if (self::set_translation($chosen_translation)) {
+                                       return;
+                               }
+                       }
+               }
+               
+               // No translation found yet => try the prefixes
+               arsort($fallbacks, SORT_NUMERIC);
+               foreach ($fallbacks as $lang => $qvalue) {
+                       if (self::set_translation($lang)) {
+                               return;
+                       }
+               }
+               
+               // should not get here, as the fallback of "en" is provided and that
+               // should always work => log an error
+               trigger_error("L10n::detect_language(): could not set language",
+                       E_USER_WARNING);
+       }
+       
+       /**
+        * Get the set translation
+        * 
+        * @return string
+        *              a translation code or the empty string if not set
+        */
+       public static function get_translation() {
+               if (array_key_exists('language', $_SESSION['_config'])) {
+                       return $_SESSION['_config']['language'];
+               } else {
+                       return "";
+               }
+       }
+       
+       /**
+        * Set the translation to use.
+        * 
+        * @param string $translation_code
+        *              the translation code as specified in the keys of {@link $translations}
+        * 
+        * @return bool
+        *              <ul>
+        *              <li>true if the translation has been set successfully</li>
+        *              <li>false if the $translation_code was not contained in the white
+        *                      list or could not be set for other reasons (e.g. setlocale()
+        *                      failed because the locale has not been set up on the system -
+        *                      details will be logged)</li>
+        *              </ul>
+        */
+       public static function set_translation($translation_code) {
+               // check $translation_code against whitelist
+               if ( !array_key_exists($translation_code, self::$translations) ) {
+                       // maybe it's a locale as previously used in the system? e.g. en_AU
+                       if ( preg_match('/^([a-z][a-z])_([A-Z][A-Z])$/', $translation_code,
+                                           $matches) !== 1 ) {
+                               return false;
+                       }
+                       
+                       $lang_code = $matches[1];
+                       $region_code = strtolower($matches[2]);
+                       
+                       if ( array_key_exists("${lang_code}-${region_code}",
+                                                 self::$translations) ) {
+                               $translation_code = "${lang_code}-${region_code}";
+                       } elseif ( array_key_exists($lang_code, self::$translations) ) {
+                               $translation_code = $lang_code;
+                       } else {
+                               return false;
+                       }
+               }
+               
+               // map translation to locale
+               if ( !array_key_exists($translation_code, self::$locales) ) {
+                       // weird. maybe you added a translation but haven't added a
+                       // translation to locale mapping in self::locales?
+                       trigger_error("L10n::set_translation(): could not map the ".
+                               "translation $translation_code to a locale", E_USER_WARNING);
+                       return false;
+               }
+               $locale = self::$locales[$translation_code];
+               
+               // set up locale
+               if ( !putenv("LANG=$locale") ) {
+                       trigger_error("L10n::set_translation(): could not set the ".
+                               "environment variable LANG to $locale", E_USER_WARNING);
+                       return false;
+               }
+               if ( !setlocale(LC_ALL, $locale) ) {
+                       trigger_error("L10n::set_translation(): could not setlocale() ".
+                               "LC_ALL to $locale", E_USER_WARNING);
+                       return false;
+               }
+               
+               
+               // only set if we're running in a server not in a script
+               if (isset($_SESSION)) {
+                       // 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";
+                               
+                       } 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();
                }
        }
 
diff --git a/locale/Makefile b/locale/Makefile
new file mode 100644 (file)
index 0000000..b703fb2
--- /dev/null
@@ -0,0 +1,184 @@
+#
+# This Makefile will download the translations from our translation server (if
+# they don't exist yet) and compile them. Try target help for more information
+#
+
+################################################################################
+###                                 Download                                 ###
+################################################################################
+
+DOWNLOAD_SERVER := translations.cacert.org
+PO_URL_TEMPLATE := http://$(DOWNLOAD_SERVER)/export/cacert/%/messages.po
+
+# Only use languages that have 10% or more of translated strings
+AUTO_LANGS := \
+en \
+de \
+nl \
+pt_BR \
+fr \
+sv \
+it \
+es \
+hu \
+fi \
+ja \
+bg \
+pt \
+da \
+pl \
+zh_CN \
+ru \
+lv \
+cs \
+zh_TW \
+el \
+tr \
+ar \
+
+LANGS := \
+ar \
+bg \
+cs \
+da \
+de \
+el \
+en \
+es \
+fa \
+fi \
+fr \
+he \
+hr \
+hu \
+id \
+is \
+it \
+ja \
+ka \
+ko \
+lv \
+nb \
+nl \
+pl \
+pt \
+pt_BR \
+ro \
+ru \
+sl \
+sv \
+th \
+tr \
+uk \
+zh_CN \
+zh_TW \
+
+
+PO_FILE_TEMPLATE := %/messages.po
+MO_FILE_TEMPLATE := %/LC_MESSAGES/messages.mo
+
+
+# target: all - Build locales downloading po files
+.PHONY: all
+all: $(AUTO_LANGS)
+
+
+# target: help - Display callable targets
+.PHONY: help
+help:
+       @egrep "^# target:" [Mm]akefile
+
+
+# target: clean - remove the build directories
+RM := rm -rf
+.PHONY: clean
+clean:
+       -$(RM) $(LANGS:%=%/)
+
+
+# target: <lang> - build this particular language
+.PHONY: $(LANGS)
+$(LANGS): %: $(MO_FILE_TEMPLATE)
+
+
+$(LANGS:%=$(MO_FILE_TEMPLATE)): $(MO_FILE_TEMPLATE): $(PO_FILE_TEMPLATE)
+       mkdir -p $(@D)
+#filter obsolete translations
+       grep --invert-match '^#~ ' $< | \
+               msgfmt --check --output-file $@ -
+
+
+.PHONY: $(LANGS:%=$(PO_FILE_TEMPLATE))
+$(LANGS:%=$(PO_FILE_TEMPLATE)):
+       mkdir -p $(@D)
+       wget --output-document - '$(@:$(PO_FILE_TEMPLATE)=$(PO_URL_TEMPLATE))' | \
+               # convert UTF-8 characters to HTML entities \
+               php -r 'while (!feof(STDIN)) echo mb_convert_encoding(fgets(STDIN), "HTML-ENTITIES", "UTF-8");' \
+               > $@
+
+
+
+
+################################################################################
+###                                 Upload                                   ###
+################################################################################
+
+UPLOAD_SERVER := $(DOWNLOAD_SERVER)
+SSH_USER := critical
+SSH_OPTIONS :=
+SCP_OPTIONS := $(SSH_OPTIONS)
+
+FILE_OWNER := www-data
+
+POT_UPLOAD_PATH := /var/www/Pootle/po/cacert/templates/messages.pot
+MANAGE_PY := /var/www/Pootle/manage.py
+
+VERSION := Production
+DESCRITPION := LibreSSL - CAcert web application (localisation files)
+COPYRIGHT_YEAR := 2004-$(shell date +\%Y)
+PACKAGE := LibreSSL
+
+GETTEXT_FILE_PATTERN := \
+../CommModule/client.pl \
+../includes/*.php \
+../includes/*/*.php \
+../pages/*/*.php \
+../scripts/*.php \
+../www/*.php \
+../www/*/*.php \
+# ../tverify/*.php \
+# ../tverify/*/*.php \
+
+GETTEXT_FILES := $(wildcard $(GETTEXT_FILE_PATTERN))
+
+# target: template - create the gettext template file, if you want to upload it
+# target:            onto the translation server you can directly use the
+# target:            target "upload"
+.PHONY: template
+template: messages.pot
+
+# target: template.clean - remove anything that was created during the build of
+# target:                  the template file
+.PHONY: template.clean
+template.clean:
+       -$(RM) messages.pot
+
+
+# target: upload - upload the template to the translation server
+.PHONY: upload
+upload: messages.pot
+       scp $(SCP_OPTIONS) messages.pot $(SSH_USER)@$(UPLOAD_SERVER):$(POT_UPLOAD_PATH)
+       ssh $(SSH_OPTIONS) $(SSH_USER)@$(UPLOAD_SERVER) "sudo -u $(FILE_OWNER) pootle-update cacert"
+
+# target: upload.clean - remove anything that was created during the upload
+.PHONY: upload.clean
+upload.clean: template.clean
+
+messages.pot: $(GETTEXT_FILES)
+       xgettext --output - --sort-by-file --copyright-holder "CAcert Inc." \
+               --package-name "CAcert" --package-version "$(VERSION)" \
+               --msgid-bugs-address "translations-admin@cacert.org" $^ | \
+               # replace place holders in the lines before the first msgid\
+               sed '1,/^msgid/ { s/SOME DESCRIPTIVE TITLE/$(DESCRITPION)/; s/YEAR/$(COPYRIGHT_YEAR)/; s/PACKAGE/$(PACKAGE)/ }' \
+               > $@
+
diff --git a/locale/make.php b/locale/make.php
deleted file mode 100755 (executable)
index 859d75e..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/php -q
-<?
-       $lang = array(  "bg" => "bg_BG", "da" => "da_DK", "de" => "de_DE", "es" => "es_ES",
-                       "fr" => "fr_FR", "fi" => "fi_FI", "he" => "he_IL", "hr" => "hr_HR",
-                       "hu" => "hu_HU", "it" => "it_IT", "ja" => "ja_JP", "nl" => "nl_NL",
-                       "pt" => "pt_PT", "ro" => "ro_RO", "ru" => "ru_RU", "fa" => "fa_IR",
-                       "sv" => "sv_SE", "tr" => "tr_TR", "zh" => "zh_CN", "ar" => "ar_SY",
-                       "el" => "el_GR", "tl" => "tl_PH", "pl" => "pl_PL", "cs" => "cs_CZ",
-                       "ka" => "ka_GE", "is" => "is_IS", "ko" => "ko_KR", "nb" => "nb_NO");
-
-       if($argc > 1)
-       {
-               foreach($argv as $key)
-               {
-                       $val = $lang[$key];
-                       if($val != "")
-                       {               
-                               $do = `wget -O $key.po "http://translingo.cacert.org/export2.php?pid=1&editlanguage=$val" 2>&1`;
-echo $do;
-                               echo `mkdir -p $key/LC_MESSAGES/`;
-                               $do = `msgfmt -o $key/LC_MESSAGES/messages.mo $key.po 2>&1`;
-echo $do;
-                       }
-               }
-       } else {
-               foreach($lang as $key => $val)
-               {
-               $do = `wget -O $key.po "http://translingo.cacert.org/export2.php?pid=1&editlanguage=$val" 2>&1`;
-echo $do;
-               echo `mkdir -p $key/LC_MESSAGES/`;
-               $do = `msgfmt -o $key/LC_MESSAGES/messages.mo $key.po 2>&1`;
-echo $do;
-               }
-       }
-?>
index e44eec9..d2cfc8c 100644 (file)
     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($_SESSION['_config']['filepath'].'/includes/lib/l10n.php');
+?>
+
 <form method="post" action="account.php">
 <table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper" width="400">
   <tr>
     <td class="DataTD"><?=_("My prefered language")?>:</td>
     <td class="DataTD"><select name="lang">
 <?
-echo $_SESSION['_config']['language'];
-       foreach($_SESSION['_config']['translations'] as $key => $val)
+       foreach(L10n::$translations as $key => $val)
        {
                echo "<option value='$key'";
-               if($key == $_SESSION['_config']['language'])
+               if($key == L10n::get_translation())
                        echo " selected";
                echo ">$val</option>\n";
        }
index f717870..c1a6438 100644 (file)
@@ -16,6 +16,7 @@
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
        include_once("../includes/shutdown.php");
+       require_once("../includes/lib/l10n.php");
 ?>
 <? 
   if(array_key_exists('error',$_SESSION['_config']) && $_SESSION['_config']['error'] != "") 
@@ -32,8 +33,8 @@
 <select name="reminder-lang">
 <?
        if($_SESSION['_config']['reminder-lang'] == "")
-               $_SESSION['_config']['reminder-lang'] = $_SESSION['profile']['language'];
-        foreach($_SESSION['_config']['translations'] as $key => $val)
+               $_SESSION['_config']['reminder-lang'] = L10n::get_translation();
+        foreach(L10n::$translations as $key => $val)
         {
                 echo "<option value='$key'";
                 if($key == $_SESSION['_config']['reminder-lang'])
index b974c5d..bfa7a98 100644 (file)
     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($_SESSION['_config']['filepath'].'/includes/lib/l10n.php');
+       
+
        $res = mysql_query("select * from `users` where `id`='".intval($_REQUEST['userid'])."' and `listme`='1'");
        if(mysql_num_rows($res) <= 0)
        {
@@ -47,7 +50,7 @@
 <? if($userlang != "") { ?>
   <tr>
     <td class="DataTD"><?=_("Language")?>:</td>
-    <td class="DataTD" align="left"><? printf(_("%s prefers to be contacted in %s"), $user['fname'], $_SESSION['_config']['translations'][$userlang]) ?></td>
+    <td class="DataTD" align="left"><? printf(_("%s prefers to be contacted in %s"), $user['fname'], L10n::$translations[$userlang]) ?></td>
   </tr>
 <? } ?>
 <?
diff --git a/password.dat.sample b/password.dat.sample
deleted file mode 100644 (file)
index f9bbb55..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-$translingo_password = 'ThePassword';
-$translingo_account = 'TheAccount';
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 6b08d38..73380e1 100644 (file)
@@ -15,7 +15,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
-       if($_SESSION['_config']['language'] != "ja_JP")
+       if($_SESSION['_config']['language'] != "ja")
        {
                define('FPDF_FONTPATH','/usr/share/fpdf/font/');
                require_once('/usr/share/ufpdf/fpdf.php');
@@ -35,7 +35,7 @@
                {
                        $this->Image((array_key_exists('bw',$_REQUEST) && $_REQUEST['bw'])?'images/CAcert-logo-mono-1000.png':'images/CAcert-logo-colour-1000.png',8,8,100);
                        $this->SetFont('Arial','B',14);
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',14);
                        $this->Cell(100);
                        $this->Cell(40,20,recode($_SESSION['_config']['recode'], _("CAcert Assurance Programme")));
 
                        $this->SetY(36);
                        $this->SetFont('Arial','I',8);
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','I',8);
                        $this->Cell(0,0,'CAcert Inc. - P.O. Box 4107 - Denistone East NSW 2112 - Australia - http://www.CAcert.org',0,0,'C');
                        $this->Ln(3);
                        $this->SetFont('Arial','',6);
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',6);
                        $this->Cell(0,0, recode($_SESSION['_config']['recode'], _("CAcert's Root Certificate fingerprints")).": A6:1B:37:5E:39:0D:9C:36:54:EE:BD:20:31:46:1F:6B "._("and")." 135C EC36 F49C B8E9 3B1A B270 CD80 8846 76CE 8F33",0,0,'C');
                        $this->SetLineWidth(0.05);
@@ -71,7 +71,7 @@
                        // Show text blurb at top of page
                        $this->SetY(45);
                        $this->SetFont('Arial','',10);
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',10);
                        $this->Write(4,sprintf(recode($_SESSION['_config']['recode'], _("To the Assurer: The CAcert Assurance Programme (CAP) aims to verify the identities of Internet users through face-to-face witnessing of government issued identity documents. The Applicant asks you to verify to CAcert.org that you have met them and verified their identity against one or more original, trusted, government photo identity documents. If you have ANY doubts or concerns about the Applicant's identity, DO NOT COMPLETE OR SIGN this form. For more information about the CAcert Assurance Programme, including detailed guides for CAcert Assurers, please visit: %s")), "http://www.CAcert.org"));
                        $this->Ln(10);
                        $this->Rect(11, $top, $this->w - 25, 60, "D");  //50 -> 60
                        $this->SetXY(11, $top + 5);
                        $this->SetFont("Arial", "BUI", "20");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','BUI',20);
                        $this->Write(0, recode($_SESSION['_config']['recode'], _("Applicant's Statement")));
                        $this->Rect(13, $top + 10, $this->w - 29, 6, "D");
                        $this->Line(80, $top + 10, 80, $top + 16);
                        $this->SetXY(15, $top + 13);
                        $this->SetFont("Arial", "B", "12");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','B',12);
                        $this->Write(0, recode($_SESSION['_config']['recode'], _("Names")).":");
                        if($name)
                        {
                                $this->SetXY(82, $top + 13);
                                $this->SetFont("Arial", '', "11");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',11);
                                $this->Write(0, $name);
                        }
                        $this->Line(80, $top + 16, 80, $top + 22);
                        $this->SetXY(15, $top + 19);
                        $this->SetFont("Arial", "B", "12");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','B',12);
                        $this->Write(0, recode($_SESSION['_config']['recode'], _("Date of Birth")).": ");
                        $this->SetFont("Arial", "", "8");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',8);
                        $this->Write(0, "(".recode($_SESSION['_config']['recode'], _("YYYY-MM-DD")).")");
                        if($dob)
                        {
                                $this->SetXY(82, $top + 19);
                                $this->SetFont("Arial", "", "11");
-                               if($_SESSION['_config']['language'] == "ja_JP")
+                               if($_SESSION['_config']['language'] == "ja")
                                        $this->SetFont('SJIS','',11);
                                $this->Write(0, $dob);
                        }
                        $this->Line(80, $top + 22, 80, $top + 28);
                        $this->SetXY(15, $top + 25);
                        $this->SetFont("Arial", "B", "12");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','B',12);
                        $this->Write(0, recode($_SESSION['_config']['recode'], _("Email Address")).":");
                        if($email)
                        {
                                $this->SetXY(82, $top + 25);
                                $this->SetFont("Arial", "", "11");
-                               if($_SESSION['_config']['language'] == "ja_JP")
+                               if($_SESSION['_config']['language'] == "ja")
                                        $this->SetFont('SJIS','',11);
                                $this->Write(0, $email);
                        }
                        $this->SetXY(13, $top + 32);
                        $this->SetFont("Arial", "", "9");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',9);
                        $this->MultiCell($this->w - 29, 3, recode($_SESSION['_config']['recode'], _("I hereby confirm that the information stated above is both true and correct, and request the CAcert Assurer (identified below) to verify me according to CAcert Assurance Policy.")));
 // new da start
                        $this->SetXY(13, $top + 42);
                        $this->SetFont("Arial", "", "9");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',9);
                        $this->MultiCell($this->w - 29, 3, recode($_SESSION['_config']['recode'], _("I agree to the CAcert Community Agreement.")." ( http://www.cacert.org/policy/CAcertCommunityAgreement.php )"));
 // new da end
                                $this->Write(0, "20___-___-___");
                        } else {
                                $this->SetFont("Arial", "U", "10");
-                               if($_SESSION['_config']['language'] == "ja_JP")
+                               if($_SESSION['_config']['language'] == "ja")
                                        $this->SetFont('SJIS','U',10);
                                $this->Write(0, str_pad($date, 13, " "));
                        }
                        $this->Rect(11, $top, $this->w - 25, 83, "D"); //63->93
                        $this->SetXY(11, $top + 5);
                        $this->SetFont("Arial", "BUI", "20");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','BUI',20);
                        $this->Write(0, recode($_SESSION['_config']['recode'], _("CAcert Assurer")));
                        $this->SetFont("Arial", "", "9");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',9);
                        $this->SetXY(13, $top + 15);
                        if($assurer)
                        {
                                $this->Write(0, recode($_SESSION['_config']['recode'], _("Assurer's Name")).": ");
                                $this->SetFont("Arial", "", "10");
-                               if($_SESSION['_config']['language'] == "ja_JP")
+                               if($_SESSION['_config']['language'] == "ja")
                                        $this->SetFont('SJIS','U',10);
 //                             $this->MultiCell($this->w - 70, 2, recode($_SESSION['_config']['recode'], $assurer));
                                $this->Write(0, str_pad($assurer, 50, " "));
                                $this->Write(0, recode($_SESSION['_config']['recode'], _("Assurer's Name")).": ________________________________________________________________");
                        }
                        $this->SetFont("Arial", "", "9");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',9);
                        $this->SetXY(13, $top + 22);
                        $this->MultiCell($this->w - 34, 3, recode($_SESSION['_config']['recode'], _("Photo ID Shown: (ID types, not numbers. eg Drivers license, Passport)")));
                        } else {
                                $this->Write(0, "1. ");
                                $this->SetFont("Arial", "U", "10");
-                               if($_SESSION['_config']['language'] == "ja_JP")
+                               if($_SESSION['_config']['language'] == "ja")
                                        $this->SetFont('SJIS','U',10);
                                $this->Write(0, str_pad($document1, 90, " "));
                        }
                        $this->SetFont("Arial", "", "9");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',9);
                        $this->SetXY(13, $top + 35);
                        if($document2 == "")
                        } else {
                                $this->Write(0, "2. ");
                                $this->SetFont("Arial", "U", "10");
-                               if($_SESSION['_config']['language'] == "ja_JP")
+                               if($_SESSION['_config']['language'] == "ja")
                                        $this->SetFont('SJIS','U',10);
                                $this->Write(0, str_pad($document2, 90, " "));
                        }
                        $this->SetFont("Arial", "", "9");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',9);
                        $this->SetXY(13, $top + 45);
                        $this->Write(0, recode($_SESSION['_config']['recode'], _("Location of Face-to-face Meeting")).": ");
                                $this->Write(0, "_____________________________________________");
                        } else {
                                $this->SetFont("Arial", "U", "10");
-                               if($_SESSION['_config']['language'] == "ja_JP")
+                               if($_SESSION['_config']['language'] == "ja")
                                        $this->SetFont('SJIS','U',10);
                                $this->Write(0, str_pad($location, 70, " "));
                        }
                        $this->SetFont("Arial", "", "9");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',9);
                        $this->SetXY(13, $top + 50);
                        if($maxpoints > 0)
                                $this->Write(0, recode($_SESSION['_config']['recode'], _("Points Allocated")).": ______________");
                        }
                        $this->SetFont("Arial", "", "9");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',9);
                        $this->SetXY(13, $top + 54);
                        $this->MultiCell($this->w - 33, 3, recode($_SESSION['_config']['recode'], _("I, the Assurer, hereby confirm that I have verified the Member according to CAcert Assurance Policy.")));
                        $this->MultiCell($this->w - 33, 3, recode($_SESSION['_config']['recode'], _("I am a CAcert Community Member, have passed the Assurance Challenge, and have been assured with at least 100 Assurance Points.")));
 
                        $this->SetFont("Arial", "", "9");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',9);
                        $this->SetXY(13, $top + 74);  //22->67
                        $this->Write(0, recode($_SESSION['_config']['recode'], _("Assurer's signature")).": __________________________________");
                                $this->Write(0, "20___-___-___");
                        } else {
                                $this->SetFont("Arial", "U", "10");
-                               if($_SESSION['_config']['language'] == "ja_JP")
+                               if($_SESSION['_config']['language'] == "ja")
                                        $this->SetFont('SJIS','U',10);
                                $this->Write(0, str_pad($date, 13, " "));
                        }
                $maxpoints = 0;
 
        $pdf = new PDF('P', 'mm', $format);
-       if($_SESSION['_config']['language'] == "ja_JP")
+       if($_SESSION['_config']['language'] == "ja")
                $pdf->AddSJISFont();
        $pdf->Open();
        $pdf->AddPage();
index 3136993..41a0894 100644 (file)
@@ -17,8 +17,8 @@
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
-//   $Id: capnew.php,v 1.3 2011-06-10 18:30:41 wytze Exp $
-define('REV', '$Revision: 1.3 $');
+//   $Id: capnew.php,v 1.4 2012-01-24 14:26:05 root Exp $
+define('REV', '$Revision: 1.4 $');
 
 /*
 **  Created from old cap.php 2003, which used the now obsoleted ftpdf package
@@ -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');
     }
@@ -387,7 +387,7 @@ function utf8_is_ascii_ctrl($str) {
 // extend TCPF with custom functions
 class CAPPDF extends TCPDF {
 
-    // do cap form version numbering automatically '$Revision: 1.3 $'
+    // do cap form version numbering automatically '$Revision: 1.4 $'
     /*public*/ function Version() {
        strtok(REV, ' ');
         return(strtok(' '));
index c9e4e47..4f69247 100644 (file)
@@ -17,8 +17,8 @@
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
-//   $Id: coapnew.php,v 1.3 2011-06-10 18:30:42 wytze Exp $
-define('REV', '$Revision: 1.3 $');
+//   $Id: coapnew.php,v 1.4 2012-01-24 14:26:05 root Exp $
+define('REV', '$Revision: 1.4 $');
 
 /*
 **  Created from old cap.php 2003, which used the now obsoleted ftpdf package
@@ -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');
     }
@@ -422,7 +422,7 @@ function utf8_is_ascii_ctrl($str) {
 // extend TCPF with custom functions
 class COAPPDF extends TCPDF {
 
-    // do cap form version numbering automatically "$Revision: 1.3 $"
+    // do cap form version numbering automatically "$Revision: 1.4 $"
     /*public*/ function Version() {
        strtok(REV, " ");
         return(strtok(" "));
index 5f7fc14..41b6d7a 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 2240518..6385127 100644 (file)
@@ -15,7 +15,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
-       if($_SESSION['_config']['language'] != "ja_JP")
+       if($_SESSION['_config']['language'] != "ja")
        {
                define('FPDF_FONTPATH','/usr/share/fpdf/font/');
                require_once('/usr/share/ufpdf/fpdf.php');
@@ -40,7 +40,7 @@
                {
                        $this->Image($_REQUEST['bw']?'images/CAcert-logo-mono-1000.png':'images/CAcert-logo-colour-1000.png',8,8,100);
                        $this->SetFont('Arial','B',14);
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','B',14);
                        $this->Cell(100);
                        $this->Cell(40,20,recode($_SESSION['_config']['recode'], _("Trusted Third Party")));
                {
                        $this->SetY(-10);
                        $this->SetFont('Arial','I',8);
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','I',8);
                        $this->Cell(0,0,'CAcert Inc. - P.O. Box 4107 - Denistone East NSW 2112 - Australia - http://www.CAcert.org',0,0,'C');
                        $this->SetY(-7);
                        $this->SetFont('Arial','',6);
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',6);
                        $this->Cell(0,0, recode($_SESSION['_config']['recode'], _("CAcert's Root Certificate fingerprints")).": A6:1B:37:5E:39:0D:9C:36:54:EE:BD:20:31:46:1F:6B "._("and")." 135C EC36 F49C B8E9 3B1A B270 CD80 8846 76CE 8F33",0,0,'C');
                }
@@ -72,7 +72,7 @@
                        // Show text blurb at top of page
                        $this->SetY(40);
                        $this->SetFont('Arial','',10);
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','',10);
                        $this->Write(4, recode($_SESSION['_config']['recode'], _("The CAcert Trusted Third Party (TTP) Programme is designed to assure Internet user identities through personal verification of government issued identity documents.")));
                        $this->Ln(7);
                        $this->Line(120, $top + 6, 120, $top + 36);
                        $this->SetXY(11, $top + 3);
                        $this->SetFont("Arial", "BUI", "12");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','BUI',12);
                        $this->Write(0, recode($_SESSION['_config']['recode'],_("Person Verifying Applicant's Identity")));
                        $this->SetXY(11, $top + 9);
                        $this->SetFont("Arial", "B", "8");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','B',8);
                        $this->Write(0, recode($_SESSION['_config']['recode'],_("Names").":"));
                        $this->SetXY(120, $top + 9);
                        $this->Write(0, recode($_SESSION['_config']['recode'],_("Office Street Address").":"));
                        $this->SetFont("Arial", "B", "6");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','B',6);
                        $this->SetXY(11, $top + 14);
                        $this->Write(0, recode($_SESSION['_config']['recode'],_("Profession (Please circle one)")).":");
                        $this->SetXY(11, $top + 22);
                        $this->Write(0, recode($_SESSION['_config']['recode'], "("._("as applicable")."):"));
                        $this->SetFont("Arial", "B", "8");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','B',8);
                        $this->SetXY(11, $top + 27);
                        $this->Write(0, recode($_SESSION['_config']['recode'],_("Office Phone")).":");
                        $this->Line(120, $top + 6, 120, $top + 36);
                        $this->SetXY(11, $top + 3);
                        $this->SetFont("Arial", "BUI", "12");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','BUI',12);
                        $this->Write(0, recode($_SESSION['_config']['recode'],_("Applicant Information")));
                        $this->SetXY(11, $top + 9);
                        $this->SetFont("Arial", "B", "8");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','B',8);
                        $this->Write(0, recode($_SESSION['_config']['recode'],_("Full Name (as shown on ID)").":"));
                        if($name)
                        $this->SetXY(11, $top + 21);
                        $this->Write(0, recode($_SESSION['_config']['recode'],_("Date of Birth")).": ");
                        $this->SetFont("Arial", "B", "6");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','B',6);
                        $this->Write(0, "(".recode($_SESSION['_config']['recode'], _("YYYY-MM-DD")).")");
                        $this->SetFont("Arial", "B", "8");
-                       if($_SESSION['_config']['language'] == "ja_JP")
+                       if($_SESSION['_config']['language'] == "ja")
                                $this->SetFont('SJIS','B',8);
                        if($dob)
                        {
                $format = "A4";
 
        $pdf = new PDF('P', 'mm', $format);
-       if($_SESSION['_config']['language'] == "ja_JP")
+       if($_SESSION['_config']['language'] == "ja")
                $pdf->AddSJISFont();
        $pdf->Open();
        $pdf->AddPage();
index d70f1d5..66bf7cb 100644 (file)
@@ -16,6 +16,9 @@
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */ ?>
 <?
+require_once("../includes/loggedin.php");
+require_once("../includes/lib/l10n.php");
+
 
 function show_page($target,$message,$error)
 {
@@ -83,43 +86,35 @@ function show_page($target,$message,$error)
 function send_reminder()
 {
        $body = "";
-       if($_POST['reminder-lang'] != "" && $_POST['reminder-lang'] != "en_AU")
-        {
-               $userlang = $_POST['reminder-lang'];
-               $_SESSION['_config']['reminder-lang'] = $_POST['reminder-lang'];
-               putenv("LANG=".$userlang);
-               setlocale(LC_ALL, $userlang);
-
-               $body .= $_SESSION['_config']['translations'][$userlang].":\n\n";
+       $my_translation = L10n::get_translation();
+       
+       $_SESSION['_config']['reminder-lang'] = $_POST['reminder-lang'];
+       
+       $reminder_translations[] = $_POST['reminder-lang'];
+       if ( !in_array("en", $reminder_translations, $strict=true) ) {
+               $reminder_translations[] = "en";
+       }
+       
+       foreach ($reminder_translations as $translation) {
+               L10n::set_translation($translation);
+               
+               $body .= L10n::$translations[$translation].":\n\n";
                $body .= sprintf(_("This is a short reminder that you filled out forms to become trusted with CAcert.org, and %s has attempted to issue you points. Please create your account at %s as soon as possible and then notify %s so that the points can be issued."), $_SESSION['profile']['fname']." (".$_SESSION['profile']['email'].")", "http://www.cacert.org", $_SESSION['profile']['fname'])."\n\n";
                $body .= _("Best regards")."\n";
-               $body .= _("CAcert Support Team");
-
-               $body .= "\n\nEnglish:\n\n";
+               $body .= _("CAcert Support Team")."\n\n";
        }
-
-       $body .= sprintf("This is a short reminder that you filled out forms to become trusted with CAcert.org, and %s has attempted to issue you points. Please create your account at %s as soon as possible and then notify %s so that the points can be issued.", $_SESSION['profile']['fname']." (".$_SESSION['profile']['email'].")", "http://www.cacert.org", $_SESSION['profile']['fname'])."\n\n";
-       $body .= "Best regards"."\n";
-       $body .= "CAcert Support Team";
-
+       
+       L10n::set_translation($reminder_translations[0]); // for the subject
        sendmail($_POST['email'], "[CAcert.org] "._("Reminder Notice"), $body, $_SESSION['profile']['email'], "", "", $_SESSION['profile']['fname']);
-
-       if($_POST['reminder-lang'] != "" && $_POST['reminder-lang'] != "en_AU")
-       {
-               $userlang = $_SESSION['profile']['language'];
-               putenv("LANG=".$userlang);
-               setlocale(LC_ALL, $userlang);
-       }
-
+       
+       L10n::set_translation($my_translation);
+       
        $_SESSION['_config']['remindersent'] = 1;
+       $_SESSION['_config']['error'] = _("A reminder notice has been sent.");
 }
 
 
 
-
-
-       require_once("../includes/loggedin.php");
-
        loadem("account");
        if(array_key_exists('date',$_POST) && $_POST['date'] != "")
                $_SESSION['_config']['date'] = $_POST['date'];
@@ -322,13 +317,9 @@ $iecho= "c";
                        $_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";
@@ -359,8 +350,7 @@ $iecho= "c";
 
                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)