must have functions/i18n.php available to use $squirrelmail_language further
[squirrelmail.git] / functions / gettext.php
index 6fc7884d09f93c761061ae6cec56d4e097f1f4cb..5a8f180a4285065c9c32a9be5e764ab50cec7bcb 100644 (file)
@@ -1,13 +1,15 @@
 <?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 &copy; 1999-2006 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @since 1.1.2
  * @package squirrelmail
@@ -32,7 +34,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 +79,28 @@ function textdomain($name = false) {
     if ($name) $gettext_domain=$name;
     return $gettext_domain;
 }
+
+/**
+ * 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);
+    }
+}
 ?>
\ No newline at end of file