| 1 | <?php |
| 2 | /** |
| 3 | * SquirrelMail internal gettext functions |
| 4 | * |
| 5 | * Since 1.5.1 uses php-gettext classes. |
| 6 | * Original implementation was done by Tyler Akins (fidian) |
| 7 | * @copyright (c) 1999-2005 The SquirrelMail Project Team |
| 8 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 9 | * @link http://www.php.net/gettext Original php gettext manual |
| 10 | * @link http://savannah.nongnu.org/projects/php-gettext php-gettext classes |
| 11 | * @version $Id$ |
| 12 | * @since 1.1.2 |
| 13 | * @package squirrelmail |
| 14 | * @subpackage i18n |
| 15 | */ |
| 16 | |
| 17 | /** Almost everything requires global.php... */ |
| 18 | require_once(SM_PATH . 'functions/global.php'); |
| 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 ($l10n[$gettext_domain]->error==1) return $str; |
| 36 | return $l10n[$gettext_domain]->translate($str); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Alternative php bindtextdomain function |
| 41 | * |
| 42 | * Sets path to directory containing domain translations |
| 43 | * |
| 44 | * @link http://www.php.net/function.bindtextdomain |
| 45 | * @param string $domain gettext domain name |
| 46 | * @param string $dir directory that contains all translations |
| 47 | * @return string path to translation directory |
| 48 | * @since 1.1.2 |
| 49 | */ |
| 50 | function 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 | |
| 58 | return $dir; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Alternative php textdomain function |
| 63 | * |
| 64 | * Sets default domain name. Before 1.5.1 command required |
| 65 | * bindtextdomain() call for each gettext domain change. |
| 66 | * |
| 67 | * @link http://www.php.net/function.textdomain |
| 68 | * @param string $name gettext domain name |
| 69 | * @return string gettext domain name |
| 70 | * @since 1.1.2 |
| 71 | */ |
| 72 | function textdomain($name = false) { |
| 73 | global $gettext_domain; |
| 74 | if ($name) $gettext_domain=$name; |
| 75 | return $gettext_domain; |
| 76 | } |
| 77 | ?> |