gettext.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /** Almost everything requires global.php... */
  17. require_once(SM_PATH . 'functions/global.php');
  18. /** Load classes and other functions */
  19. include_once(SM_PATH . 'class/l10n.class.php');
  20. include_once(SM_PATH . 'functions/ngettext.php');
  21. /**
  22. * Alternative php gettext function (short form)
  23. *
  24. * @link http://www.php.net/function.gettext
  25. *
  26. * @param string $str English string
  27. * @return string translated string
  28. * @since 1.1.2
  29. */
  30. function _($str) {
  31. global $l10n, $gettext_domain;
  32. if ($l10n[$gettext_domain]->error==1) return $str;
  33. return $l10n[$gettext_domain]->translate($str);
  34. }
  35. /**
  36. * Alternative php bindtextdomain function
  37. *
  38. * Sets path to directory containing domain translations
  39. *
  40. * @link http://www.php.net/function.bindtextdomain
  41. * @param string $domain gettext domain name
  42. * @param string $dir directory that contains all translations
  43. * @return string path to translation directory
  44. * @since 1.1.2
  45. */
  46. function bindtextdomain($domain, $dir) {
  47. global $l10n, $sm_notAlias;
  48. if (substr($dir, -1) != '/') $dir .= '/';
  49. $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo';
  50. $input = new FileReader($mofile);
  51. $l10n[$domain] = new gettext_reader($input);
  52. return $dir;
  53. }
  54. /**
  55. * Alternative php textdomain function
  56. *
  57. * Sets default domain name. Before 1.5.1 command required
  58. * bindtextdomain() call for each gettext domain change.
  59. *
  60. * @link http://www.php.net/function.textdomain
  61. * @param string $name gettext domain name
  62. * @return string gettext domain name
  63. * @since 1.1.2
  64. */
  65. function textdomain($name = false) {
  66. global $gettext_domain;
  67. if ($name) $gettext_domain=$name;
  68. return $gettext_domain;
  69. }
  70. ?>