From 1989cc04ad1bab78d711d65a85f468bf4ce6ad2c Mon Sep 17 00:00:00 2001 From: tokul Date: Thu, 9 Dec 2004 14:58:08 +0000 Subject: [PATCH] adding sq_setlocale function in order to use multiple locale names without php 4.3+ dependency git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@8428 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/i18n.php | 119 ++++++++++++++++++++++++++++++++------------- 1 file changed, 85 insertions(+), 34 deletions(-) diff --git a/functions/i18n.php b/functions/i18n.php index ebd0118c..37cde724 100644 --- a/functions/i18n.php +++ b/functions/i18n.php @@ -59,6 +59,39 @@ function sq_textdomain($domain) { return $gettext_domain; } +/** + * php setlocale function wrapper + * + * From php 4.3.0 it is possible to use arrays in order to set locale. + * php gettext extension works only when locale is set. This wrapper + * function allows to use more than one locale name. + * + * @param int $category locale category name. Use php named constants + * (LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME) + * @param mixed $locale option contains array with possible locales or string with one locale + * @return string name of set locale or false, if all locales fail. + * @since 1.5.1 + * @see http://www.php.net/setlocale + */ +function sq_setlocale($category,$locale) { + // string with only one locale + if (is_string($locale)) + return setlocale($category,$locale); + + if (! check_php_version(4,3)) { + $ret=false; + $index=0; + while ( ! $ret && $index