phpDocumentor updates
[squirrelmail.git] / functions / gettext.php
1 <?php
2
3 /**
4 * SquirrelMail internal gettext functions
5 *
6 * Since 1.5.1 uses php-gettext classes.
7 * Original implementation was done by Tyler Akins (fidian)
8 *
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 &copy; 1999-2005 The SquirrelMail Project Team
12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 * @version $Id$
14 * @since 1.1.2
15 * @package squirrelmail
16 * @subpackage i18n
17 */
18
19 /** Almost everything requires global.php... */
20 require_once(SM_PATH . 'functions/global.php');
21
22 /** Load classes and other functions */
23 include_once(SM_PATH . 'class/l10n.class.php');
24 include_once(SM_PATH . 'functions/ngettext.php');
25
26 /**
27 * Alternative php gettext function (short form)
28 *
29 * @link http://www.php.net/function.gettext
30 *
31 * @param string $str English string
32 * @return string translated string
33 * @since 1.1.2
34 */
35 function _($str) {
36 global $l10n, $gettext_domain;
37 if (! isset($l10n[$gettext_domain]) ||
38 ! is_object($l10n[$gettext_domain]) ||
39 $l10n[$gettext_domain]->error==1)
40 return $str;
41 return $l10n[$gettext_domain]->translate($str);
42 }
43
44 /**
45 * Alternative php bindtextdomain function
46 *
47 * Sets path to directory containing domain translations
48 *
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
53 * @since 1.1.2
54 */
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';
59
60 $input = new FileReader($mofile);
61 $l10n[$domain] = new gettext_reader($input);
62
63 return $dir;
64 }
65
66 /**
67 * Alternative php textdomain function
68 *
69 * Sets default domain name. Before 1.5.1 command required
70 * bindtextdomain() call for each gettext domain change.
71 *
72 * @link http://www.php.net/function.textdomain
73 * @param string $name gettext domain name
74 * @return string gettext domain name
75 * @since 1.1.2
76 */
77 function textdomain($name = false) {
78 global $gettext_domain;
79 if ($name) $gettext_domain=$name;
80 return $gettext_domain;
81 }
82
83 /**
84 * Safety check.
85 * Setup where three standard gettext functions don't exist and dgettext() exists.
86 */
87 if (! function_exists('dgettext')) {
88 /**
89 * Alternative php dgettext function
90 *
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
95 * @since 1.5.1
96 */
97 function dgettext($domain, $str) {
98 global $l10n;
99 if (! isset($l10n[$domain]) ||
100 ! is_object($l10n[$domain]) ||
101 $l10n[$domain]->error==1)
102 return $str;
103 return $l10n[$domain]->translate($str);
104 }
105 }
106 ?>