Happy New Year
[squirrelmail.git] / functions / gettext.php
CommitLineData
99f538bf 1<?php
4b4abf93 2
35586184 3/**
eb19bc67 4 * SquirrelMail internal gettext functions
35586184 5 *
987843d6 6 * Since 1.5.1 uses php-gettext classes.
7 * Original implementation was done by Tyler Akins (fidian)
4b4abf93 8 *
f875f87b 9 * @link http://www.php.net/gettext Original php gettext manual
3b84e1b1 10 * @link http://savannah.nongnu.org/projects/php-gettext php-gettext classes
c4faef33 11 * @copyright 1999-2020 The SquirrelMail Project Team
4b4abf93 12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
eb19bc67 13 * @version $Id$
987843d6 14 * @since 1.1.2
d6c32258 15 * @package squirrelmail
eb19bc67 16 * @subpackage i18n
35586184 17 */
2ba13803 18
9eb0fbd4 19
3b84e1b1 20/** Load classes and other functions */
21include_once(SM_PATH . 'class/l10n.class.php');
22include_once(SM_PATH . 'functions/ngettext.php');
55c10992 23
f875f87b 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
987843d6 31 * @since 1.1.2
f875f87b 32 */
99f538bf 33function _($str) {
3b84e1b1 34 global $l10n, $gettext_domain;
a9a10f57 35 if (! isset($l10n[$gettext_domain]) ||
36 ! is_object($l10n[$gettext_domain]) ||
202bcbcc 37 $l10n[$gettext_domain]->error==1)
a9a10f57 38 return $str;
3b84e1b1 39 return $l10n[$gettext_domain]->translate($str);
99f538bf 40}
41
f875f87b 42/**
43 * Alternative php bindtextdomain function
44 *
45 * Sets path to directory containing domain translations
46 *
47 * @link http://www.php.net/function.bindtextdomain
3b84e1b1 48 * @param string $domain gettext domain name
f875f87b 49 * @param string $dir directory that contains all translations
50 * @return string path to translation directory
987843d6 51 * @since 1.1.2
f875f87b 52 */
3b84e1b1 53function 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
99f538bf 61 return $dir;
62}
55c10992 63
f875f87b 64/**
65 * Alternative php textdomain function
66 *
987843d6 67 * Sets default domain name. Before 1.5.1 command required
68 * bindtextdomain() call for each gettext domain change.
f875f87b 69 *
70 * @link http://www.php.net/function.textdomain
71 * @param string $name gettext domain name
72 * @return string gettext domain name
987843d6 73 * @since 1.1.2
f875f87b 74 */
99f538bf 75function textdomain($name = false) {
3b84e1b1 76 global $gettext_domain;
77 if ($name) $gettext_domain=$name;
78 return $gettext_domain;
99f538bf 79}
a9a10f57 80
81/**
82 * Safety check.
83 * Setup where three standard gettext functions don't exist and dgettext() exists.
84 */
85if (! 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]) ||
202bcbcc 99 $l10n[$domain]->error==1)
a9a10f57 100 return $str;
101 return $l10n[$domain]->translate($str);
102 }
103}