gettext.php 1.9 KB

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