New icon theming. Also added basic template for left_main.php
[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
47ccfad4 11 * @copyright &copy; 1999-2006 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
d6c32258 19/** Almost everything requires global.php... */
4f664925 20require_once(SM_PATH . 'functions/global.php');
9eb0fbd4 21
3b84e1b1 22/** Load classes and other functions */
23include_once(SM_PATH . 'class/l10n.class.php');
24include_once(SM_PATH . 'functions/ngettext.php');
55c10992 25
f875f87b 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
987843d6 33 * @since 1.1.2
f875f87b 34 */
99f538bf 35function _($str) {
3b84e1b1 36 global $l10n, $gettext_domain;
a9a10f57 37 if (! isset($l10n[$gettext_domain]) ||
38 ! is_object($l10n[$gettext_domain]) ||
39 $l10n[$gettext_domain]->error==1)
40 return $str;
3b84e1b1 41 return $l10n[$gettext_domain]->translate($str);
99f538bf 42}
43
f875f87b 44/**
45 * Alternative php bindtextdomain function
46 *
47 * Sets path to directory containing domain translations
48 *
49 * @link http://www.php.net/function.bindtextdomain
3b84e1b1 50 * @param string $domain gettext domain name
f875f87b 51 * @param string $dir directory that contains all translations
52 * @return string path to translation directory
987843d6 53 * @since 1.1.2
f875f87b 54 */
3b84e1b1 55function 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
99f538bf 63 return $dir;
64}
55c10992 65
f875f87b 66/**
67 * Alternative php textdomain function
68 *
987843d6 69 * Sets default domain name. Before 1.5.1 command required
70 * bindtextdomain() call for each gettext domain change.
f875f87b 71 *
72 * @link http://www.php.net/function.textdomain
73 * @param string $name gettext domain name
74 * @return string gettext domain name
987843d6 75 * @since 1.1.2
f875f87b 76 */
99f538bf 77function textdomain($name = false) {
3b84e1b1 78 global $gettext_domain;
79 if ($name) $gettext_domain=$name;
80 return $gettext_domain;
99f538bf 81}
a9a10f57 82
83/**
84 * Safety check.
85 * Setup where three standard gettext functions don't exist and dgettext() exists.
86 */
87if (! 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}
f875f87b 106?>