summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xCommModule/client.pl2
-rw-r--r--includes/general.php9
-rw-r--r--includes/lib/l10n.php66
-rw-r--r--includes/loggedin.php13
-rw-r--r--pages/wot/5.php2
-rwxr-xr-xscripts/removedead.php5
-rw-r--r--www/capnew.php4
-rw-r--r--www/coapnew.php4
-rw-r--r--www/index.php19
-rw-r--r--www/wot.php13
10 files changed, 62 insertions, 75 deletions
diff --git a/CommModule/client.pl b/CommModule/client.pl
index 44be6f2..bf92b27 100755
--- a/CommModule/client.pl
+++ b/CommModule/client.pl
@@ -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.@]+)/);
diff --git a/includes/general.php b/includes/general.php
index d608d2d..8687ee6 100644
--- a/includes/general.php
+++ b/includes/general.php
@@ -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)
{
@@ -518,14 +519,6 @@
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 == "")
diff --git a/includes/lib/l10n.php b/includes/lib/l10n.php
index 58b6859..1a8109b 100644
--- a/includes/lib/l10n.php
+++ b/includes/lib/l10n.php
@@ -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
diff --git a/includes/loggedin.php b/includes/loggedin.php
index bf6b455..5734fad 100644
--- a/includes/loggedin.php
+++ b/includes/loggedin.php
@@ -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)
{
@@ -110,18 +111,12 @@
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/pages/wot/5.php b/pages/wot/5.php
index 4b574af..8b56fa5 100644
--- a/pages/wot/5.php
+++ b/pages/wot/5.php
@@ -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'";
diff --git a/scripts/removedead.php b/scripts/removedead.php
index 7e47c7f..23c4cd9 100755
--- a/scripts/removedead.php
+++ b/scripts/removedead.php
@@ -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";
diff --git a/www/capnew.php b/www/capnew.php
index 3136993..abcc855 100644
--- a/www/capnew.php
+++ b/www/capnew.php
@@ -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');
}
diff --git a/www/coapnew.php b/www/coapnew.php
index c9e4e47..1fe8610 100644
--- a/www/coapnew.php
+++ b/www/coapnew.php
@@ -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');
}
diff --git a/www/index.php b/www/index.php
index a139c4a..b8cfbf3 100644
--- a/www/index.php
+++ b/www/index.php
@@ -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']);
@@ -310,18 +311,12 @@
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);
@@ -551,7 +546,7 @@
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");
diff --git a/www/wot.php b/www/wot.php
index 33ce4bb..904046e 100644
--- a/www/wot.php
+++ b/www/wot.php
@@ -321,13 +321,9 @@
$_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";
@@ -358,8 +354,7 @@
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)