X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fgettext.php;h=e95e80ba5b11952ab6874bec442e37a46c262b37;hb=41f701c15f3cd18f412eefe487e12d0d48270b6f;hp=89685b01e6d4b0b3fa81d81ec0d15e2678c9eac6;hpb=6c84ba1ec45ab854c37b6f65c5b4d84ab1c7aad4;p=squirrelmail.git diff --git a/functions/gettext.php b/functions/gettext.php index 89685b01..e95e80ba 100644 --- a/functions/gettext.php +++ b/functions/gettext.php @@ -2,12 +2,14 @@ /** * SquirrelMail internal gettext functions * - * Uses php-gettext classes + * Since 1.5.1 uses php-gettext classes. + * Original implementation was done by Tyler Akins (fidian) * @copyright (c) 1999-2005 The SquirrelMail Project Team - * @license http://opensource.org/licenses/gpl-license.php GNU Public Licens + * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @link http://www.php.net/gettext Original php gettext manual * @link http://savannah.nongnu.org/projects/php-gettext php-gettext classes * @version $Id$ + * @since 1.1.2 * @package squirrelmail * @subpackage i18n */ @@ -26,10 +28,14 @@ include_once(SM_PATH . 'functions/ngettext.php'); * * @param string $str English string * @return string translated string + * @since 1.1.2 */ function _($str) { global $l10n, $gettext_domain; - if ($l10n[$gettext_domain]->error==1) return $str; + if (! isset($l10n[$gettext_domain]) || + ! is_object($l10n[$gettext_domain]) || + $l10n[$gettext_domain]->error==1) + return $str; return $l10n[$gettext_domain]->translate($str); } @@ -42,6 +48,7 @@ function _($str) { * @param string $domain gettext domain name * @param string $dir directory that contains all translations * @return string path to translation directory + * @since 1.1.2 */ function bindtextdomain($domain, $dir) { global $l10n, $sm_notAlias; @@ -57,15 +64,41 @@ function bindtextdomain($domain, $dir) { /** * Alternative php textdomain function * - * Sets default domain name + * Sets default domain name. Before 1.5.1 command required + * bindtextdomain() call for each gettext domain change. * * @link http://www.php.net/function.textdomain * @param string $name gettext domain name * @return string gettext domain name + * @since 1.1.2 */ function textdomain($name = false) { global $gettext_domain; if ($name) $gettext_domain=$name; return $gettext_domain; } + +/** + * Safety check. + * Setup where three standard gettext functions don't exist and dgettext() exists. + */ +if (! function_exists('dgettext')) { + /** + * Alternative php dgettext function + * + * @link http://www.php.net/function.dgettext + * @param string $domain Gettext domain + * @param string $str English string + * @return string translated string + * @since 1.5.1 + */ + function dgettext($domain, $str) { + global $l10n; + if (! isset($l10n[$domain]) || + ! is_object($l10n[$domain]) || + $l10n[$domain]->error==1) + return $str; + return $l10n[$domain]->translate($str); + } +} ?> \ No newline at end of file