4 * SquirrelMail internal gettext functions
6 * Since 1.5.1 uses php-gettext classes.
7 * Original implementation was done by Tyler Akins (fidian)
9 * @link http://www.php.net/gettext Original php gettext manual
10 * @link http://savannah.nongnu.org/projects/php-gettext php-gettext classes
11 * @copyright © 1999-2006 The SquirrelMail Project Team
12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
15 * @package squirrelmail
19 /** Almost everything requires global.php... */
20 require_once(SM_PATH
. 'functions/global.php');
22 /** Load classes and other functions */
23 include_once(SM_PATH
. 'class/l10n.class.php');
24 include_once(SM_PATH
. 'functions/ngettext.php');
27 * Alternative php gettext function (short form)
29 * @link http://www.php.net/function.gettext
31 * @param string $str English string
32 * @return string translated string
36 global $l10n, $gettext_domain;
37 if (! isset($l10n[$gettext_domain]) ||
38 ! is_object($l10n[$gettext_domain]) ||
39 $l10n[$gettext_domain]->error
==1)
41 return $l10n[$gettext_domain]->translate($str);
45 * Alternative php bindtextdomain function
47 * Sets path to directory containing domain translations
49 * @link http://www.php.net/function.bindtextdomain
50 * @param string $domain gettext domain name
51 * @param string $dir directory that contains all translations
52 * @return string path to translation directory
55 function bindtextdomain($domain, $dir) {
56 global $l10n, $sm_notAlias;
57 if (substr($dir, -1) != '/') $dir .= '/';
58 $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo';
60 $input = new FileReader($mofile);
61 $l10n[$domain] = new gettext_reader($input);
67 * Alternative php textdomain function
69 * Sets default domain name. Before 1.5.1 command required
70 * bindtextdomain() call for each gettext domain change.
72 * @link http://www.php.net/function.textdomain
73 * @param string $name gettext domain name
74 * @return string gettext domain name
77 function textdomain($name = false) {
78 global $gettext_domain;
79 if ($name) $gettext_domain=$name;
80 return $gettext_domain;
85 * Setup where three standard gettext functions don't exist and dgettext() exists.
87 if (! function_exists('dgettext')) {
89 * Alternative php dgettext function
91 * @link http://www.php.net/function.dgettext
92 * @param string $domain Gettext domain
93 * @param string $str English string
94 * @return string translated string
97 function dgettext($domain, $str) {
99 if (! isset($l10n[$domain]) ||
100 ! is_object($l10n[$domain]) ||
101 $l10n[$domain]->error
==1)
103 return $l10n[$domain]->translate($str);