Increment year in copyright notice.
[squirrelmail.git] / functions / gettext.php
CommitLineData
99f538bf 1<?php
35586184 2/**
eb19bc67 3 * SquirrelMail internal gettext functions
35586184 4 *
3b84e1b1 5 * Uses php-gettext classes
6c84ba1e 6 * @copyright (c) 1999-2005 The SquirrelMail Project Team
3b84e1b1 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public Licens
f875f87b 8 * @link http://www.php.net/gettext Original php gettext manual
3b84e1b1 9 * @link http://savannah.nongnu.org/projects/php-gettext php-gettext classes
eb19bc67 10 * @version $Id$
d6c32258 11 * @package squirrelmail
eb19bc67 12 * @subpackage i18n
35586184 13 */
2ba13803 14
d6c32258 15/** Almost everything requires global.php... */
4f664925 16require_once(SM_PATH . 'functions/global.php');
9eb0fbd4 17
3b84e1b1 18/** Load classes and other functions */
19include_once(SM_PATH . 'class/l10n.class.php');
20include_once(SM_PATH . 'functions/ngettext.php');
55c10992 21
f875f87b 22/**
23 * Alternative php gettext function (short form)
24 *
25 * @link http://www.php.net/function.gettext
26 *
27 * @param string $str English string
28 * @return string translated string
29 */
99f538bf 30function _($str) {
3b84e1b1 31 global $l10n, $gettext_domain;
32 if ($l10n[$gettext_domain]->error==1) return $str;
33 return $l10n[$gettext_domain]->translate($str);
99f538bf 34}
35
f875f87b 36/**
37 * Alternative php bindtextdomain function
38 *
39 * Sets path to directory containing domain translations
40 *
41 * @link http://www.php.net/function.bindtextdomain
3b84e1b1 42 * @param string $domain gettext domain name
f875f87b 43 * @param string $dir directory that contains all translations
44 * @return string path to translation directory
45 */
3b84e1b1 46function bindtextdomain($domain, $dir) {
47 global $l10n, $sm_notAlias;
48 if (substr($dir, -1) != '/') $dir .= '/';
49 $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo';
50
51 $input = new FileReader($mofile);
52 $l10n[$domain] = new gettext_reader($input);
53
99f538bf 54 return $dir;
55}
55c10992 56
f875f87b 57/**
58 * Alternative php textdomain function
59 *
60 * Sets default domain name
61 *
62 * @link http://www.php.net/function.textdomain
63 * @param string $name gettext domain name
64 * @return string gettext domain name
65 */
99f538bf 66function textdomain($name = false) {
3b84e1b1 67 global $gettext_domain;
68 if ($name) $gettext_domain=$name;
69 return $gettext_domain;
99f538bf 70}
f875f87b 71?>