summaryrefslogtreecommitdiff
path: root/includes/lib/l10n.php
diff options
context:
space:
mode:
authorMichael Tänzer <neo@nhng.de>2011-10-16 22:47:02 +0200
committerMichael Tänzer <neo@nhng.de>2011-10-16 22:47:02 +0200
commit883ea6270b45e2d712a71d8361fb4a4daffb12a9 (patch)
treed33236ed3dd40c3ee0df536cf6e4e9f4f3a0de97 /includes/lib/l10n.php
parent147cce7acd3ce673c494dc9b30f36b3d5554abea (diff)
downloadcacert-devel-883ea6270b45e2d712a71d8361fb4a4daffb12a9.tar.gz
cacert-devel-883ea6270b45e2d712a71d8361fb4a4daffb12a9.tar.xz
cacert-devel-883ea6270b45e2d712a71d8361fb4a4daffb12a9.zip
bug 985: move binding to a gettext domain into a separate method and
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>
Diffstat (limited to 'includes/lib/l10n.php')
-rw-r--r--includes/lib/l10n.php66
1 files changed, 38 insertions, 28 deletions
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