[prev in list] [next in list] [prev in thread] [next in thread] 

List:       squirrelmail-cvs
Subject:    [SM-CVS] CVS: squirrelmail/functions gettext.php,1.26,1.27 i18n.php,1.213,1.214 ngettext.php,1.4,1.5
From:       Tomas Kuliavas <tokul () users ! sourceforge ! net>
Date:       2005-07-31 12:56:54
Message-ID: E1DzDN8-0007w1-73 () sc8-pr-cvs1 ! sourceforge ! net
[Download RAW message or body]

Update of /cvsroot/squirrelmail/squirrelmail/functions
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30311

Modified Files:
	gettext.php i18n.php ngettext.php 
Log Message:
adding dgettext and dngettext function support and additional $l10n array safety checks.


Index: gettext.php
===================================================================
RCS file: /cvsroot/squirrelmail/squirrelmail/functions/gettext.php,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -w -r1.26 -r1.27
--- gettext.php	29 Mar 2005 16:35:55 -0000	1.26
+++ gettext.php	31 Jul 2005 12:56:51 -0000	1.27
@@ -32,7 +32,10 @@
  */
 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,28 @@
     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

Index: i18n.php
===================================================================
RCS file: /cvsroot/squirrelmail/squirrelmail/functions/i18n.php,v
retrieving revision 1.213
retrieving revision 1.214
diff -u -w -r1.213 -r1.214
--- i18n.php	29 Jul 2005 16:39:54 -0000	1.213
+++ i18n.php	31 Jul 2005 12:56:51 -0000	1.214
@@ -1297,5 +1297,23 @@
             }
         }
     }
+    if (! function_exists('dgettext')) {
+        /**
+         * Replacement for broken setups.
+         * @ignore
+         */
+        function dgettext($domain,$str) {
+            return $str;
+        }
+    }
+    if (! function_exists('dngettext')) {
+        /**
+         * Replacement for broken setups
+         * @ignore
+         */
+        function dngettext($domain,$str1,$strn,$number) {
+            return ($number==1 ? $str1 : $strn);
+        }
+    }
 }
 ?>
\ No newline at end of file

Index: ngettext.php
===================================================================
RCS file: /cvsroot/squirrelmail/squirrelmail/functions/ngettext.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -r1.4 -r1.5
--- ngettext.php	7 Jan 2005 17:42:19 -0000	1.4
+++ ngettext.php	31 Jul 2005 12:56:52 -0000	1.5
@@ -30,7 +30,43 @@
  */
 function ngettext($single, $plural, $number) {
     global $l10n, $gettext_domain;
-    if ($l10n[$gettext_domain]->error==1) return $single;
+    if (! isset($l10n[$gettext_domain]) ||
+        ! is_object($l10n[$gettext_domain]) ||
+        $l10n[$gettext_domain]->error==1)
+        return ($number==1 ? $single : $plural);
     return $l10n[$gettext_domain]->ngettext($single, $plural, $number);
 }
+
+/**
+ * safety check. 
+ * freaky setup where ngettext is not available and dngettext is available.
+ */
+if (! function_exists('dngettext')) {
+    /**
+     * internal dngettext wrapper.
+     *
+     * provides dngettext support
+     * @since 1.5.1
+     * @link http://www.php.net/function.dngettext
+     * @param string $domain Gettext domain
+     * @param string $single English string, singular form
+     * @param string $plural English string, plural form
+     * @param integer $number number that shows used quantity
+     * @return string translated string
+     */
+    function dngettext($domain, $single, $plural, $number) {
+        global $l10n;
+        // Make sure that $number is integer
+        $number = (int) $number;
+        
+        // Make sure that domain is initialized
+        if (! isset($l10n[$domain]) || 
+            ! is_object($l10n[$domain]) || 
+            $l10n[$domain]->error==1)
+            return ($number==1 ? $single : $plural);
+
+        // use ngettext class function
+        return $l10n[$domain]->ngettext($single, $plural, $number);
+    }
+}
 ?>
\ No newline at end of file



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
--
squirrelmail-cvs mailing list
List Address: squirrelmail-cvs@lists.sourceforge.net
List Info: https://lists.sourceforge.net/lists/listinfo/squirrelmail-cvs
http://squirrelmail.org/cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic