filename typo
[squirrelmail.git] / functions / gettext.php
index 6fc7884d09f93c761061ae6cec56d4e097f1f4cb..bc4e7f1219040b70305fa4dcd9a8c209b9d76cfe 100644 (file)
@@ -1,21 +1,21 @@
 <?php
+
 /**
  * SquirrelMail internal gettext functions
  *
  * Since 1.5.1 uses php-gettext classes.
  * Original implementation was done by Tyler Akins (fidian)
- * @copyright (c) 1999-2005 The SquirrelMail Project Team
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
  * @link http://www.php.net/gettext Original php gettext manual
  * @link http://savannah.nongnu.org/projects/php-gettext php-gettext classes
+ * @copyright 1999-2014 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @since 1.1.2
  * @package squirrelmail
  * @subpackage i18n
  */
 
-/** Almost everything requires global.php... */
-require_once(SM_PATH . 'functions/global.php');
 
 /** Load classes and other functions */
 include_once(SM_PATH . 'class/l10n.class.php');
@@ -32,7 +32,10 @@ include_once(SM_PATH . 'functions/ngettext.php');
  */
 function _($str) {
     global $l10n, $gettext_domain;
-    if ($l10n[$gettext_domain]->error==1) return $str;
+    if (! isset($l10n[$gettext_domain]) ||
+        ! is_object($l10n[$gettext_domain]) ||
+        $l10n[$gettext_domain]->error==1)
+        return $str;
     return $l10n[$gettext_domain]->translate($str);
 }
 
@@ -74,4 +77,27 @@ function textdomain($name = false) {
     if ($name) $gettext_domain=$name;
     return $gettext_domain;
 }
-?>
\ No newline at end of file
+
+/**
+ * Safety check.
+ * Setup where three standard gettext functions don't exist and dgettext() exists.
+ */
+if (! function_exists('dgettext')) {
+    /**
+     * Alternative php dgettext function
+     *
+     * @link http://www.php.net/function.dgettext
+     * @param string $domain Gettext domain
+     * @param string $str English string
+     * @return string translated string
+     * @since 1.5.1
+     */
+    function dgettext($domain, $str) {
+        global $l10n;
+        if (! isset($l10n[$domain]) ||
+            ! is_object($l10n[$domain]) ||
+            $l10n[$domain]->error==1)
+            return $str;
+        return $l10n[$domain]->translate($str);
+    }
+}