This is CAN-2005-2095
[squirrelmail.git] / functions / gettext.php
CommitLineData
99f538bf 1<?php
35586184 2/**
eb19bc67 3 * SquirrelMail internal gettext functions
35586184 4 *
987843d6 5 * Since 1.5.1 uses php-gettext classes.
6 * Original implementation was done by Tyler Akins (fidian)
6c84ba1e 7 * @copyright (c) 1999-2005 The SquirrelMail Project Team
987843d6 8 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
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
eb19bc67 11 * @version $Id$
987843d6 12 * @since 1.1.2
d6c32258 13 * @package squirrelmail
eb19bc67 14 * @subpackage i18n
35586184 15 */
2ba13803 16
d6c32258 17/** Almost everything requires global.php... */
4f664925 18require_once(SM_PATH . 'functions/global.php');
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;
35 if ($l10n[$gettext_domain]->error==1) return $str;
36 return $l10n[$gettext_domain]->translate($str);
99f538bf 37}
38
f875f87b 39/**
40 * Alternative php bindtextdomain function
41 *
42 * Sets path to directory containing domain translations
43 *
44 * @link http://www.php.net/function.bindtextdomain
3b84e1b1 45 * @param string $domain gettext domain name
f875f87b 46 * @param string $dir directory that contains all translations
47 * @return string path to translation directory
987843d6 48 * @since 1.1.2
f875f87b 49 */
3b84e1b1 50function bindtextdomain($domain, $dir) {
51 global $l10n, $sm_notAlias;
52 if (substr($dir, -1) != '/') $dir .= '/';
53 $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo';
54
55 $input = new FileReader($mofile);
56 $l10n[$domain] = new gettext_reader($input);
57
99f538bf 58 return $dir;
59}
55c10992 60
f875f87b 61/**
62 * Alternative php textdomain function
63 *
987843d6 64 * Sets default domain name. Before 1.5.1 command required
65 * bindtextdomain() call for each gettext domain change.
f875f87b 66 *
67 * @link http://www.php.net/function.textdomain
68 * @param string $name gettext domain name
69 * @return string gettext domain name
987843d6 70 * @since 1.1.2
f875f87b 71 */
99f538bf 72function textdomain($name = false) {
3b84e1b1 73 global $gettext_domain;
74 if ($name) $gettext_domain=$name;
75 return $gettext_domain;
99f538bf 76}
f875f87b 77?>