Add ability to control the display of the "Check Spelling" button. Allows administrat...
[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 1999-2017 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
20 /** Load classes and other functions */
21 include_once(SM_PATH . 'class/l10n.class.php');
22 include_once(SM_PATH . 'functions/ngettext.php');
23
24 /**
25 * Alternative php gettext function (short form)
26 *
27 * @link http://www.php.net/function.gettext
28 *
29 * @param string $str English string
30 * @return string translated string
31 * @since 1.1.2
32 */
33 function _($str) {
34 global $l10n, $gettext_domain;
35 if (! isset($l10n[$gettext_domain]) ||
36 ! is_object($l10n[$gettext_domain]) ||
37 $l10n[$gettext_domain]->error==1)
38 return $str;
39 return $l10n[$gettext_domain]->translate($str);
40 }
41
42 /**
43 * Alternative php bindtextdomain function
44 *
45 * Sets path to directory containing domain translations
46 *
47 * @link http://www.php.net/function.bindtextdomain
48 * @param string $domain gettext domain name
49 * @param string $dir directory that contains all translations
50 * @return string path to translation directory
51 * @since 1.1.2
52 */
53 function bindtextdomain($domain, $dir) {
54 global $l10n, $sm_notAlias;
55 if (substr($dir, -1) != '/') $dir .= '/';
56 $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo';
57
58 $input = new FileReader($mofile);
59 $l10n[$domain] = new gettext_reader($input);
60
61 return $dir;
62 }
63
64 /**
65 * Alternative php textdomain function
66 *
67 * Sets default domain name. Before 1.5.1 command required
68 * bindtextdomain() call for each gettext domain change.
69 *
70 * @link http://www.php.net/function.textdomain
71 * @param string $name gettext domain name
72 * @return string gettext domain name
73 * @since 1.1.2
74 */
75 function textdomain($name = false) {
76 global $gettext_domain;
77 if ($name) $gettext_domain=$name;
78 return $gettext_domain;
79 }
80
81 /**
82 * Safety check.
83 * Setup where three standard gettext functions don't exist and dgettext() exists.
84 */
85 if (! function_exists('dgettext')) {
86 /**
87 * Alternative php dgettext function
88 *
89 * @link http://www.php.net/function.dgettext
90 * @param string $domain Gettext domain
91 * @param string $str English string
92 * @return string translated string
93 * @since 1.5.1
94 */
95 function dgettext($domain, $str) {
96 global $l10n;
97 if (! isset($l10n[$domain]) ||
98 ! is_object($l10n[$domain]) ||
99 $l10n[$domain]->error==1)
100 return $str;
101 return $l10n[$domain]->translate($str);
102 }
103 }