X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fgettext.php;h=af1e118712324b756c85652831a932afa54212f6;hp=50ce7b251e84c50e0514164da78ff4f4b5bcc599;hb=2229a3ae504ba005fca71bef2c3111e28050e1b6;hpb=15e6162eacc97158393bc75aed3afeb7b19c24a6 diff --git a/functions/gettext.php b/functions/gettext.php index 50ce7b25..af1e1187 100644 --- a/functions/gettext.php +++ b/functions/gettext.php @@ -1,217 +1,103 @@ -error==1) + return $str; + return $l10n[$gettext_domain]->translate($str); +} - $gettext_php_loaded = true; - $gettext_php_loaded_language = $squirrelmail_language; - } +/** + * Alternative php bindtextdomain function + * + * Sets path to directory containing domain translations + * + * @link http://www.php.net/function.bindtextdomain + * @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; + if (substr($dir, -1) != '/') $dir .= '/'; + $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo'; - function _($str) { - global $gettext_php_loaded, $gettext_php_translateStrings, - $squirrelmail_language, $gettext_php_loaded_language, - $gettext_php_short_circuit; - - if (! $gettext_php_loaded || - $gettext_php_loaded_language != $squirrelmail_language) - gettext_php_load_strings(); + $input = new FileReader($mofile); + $l10n[$domain] = new gettext_reader($input); - // Try finding the exact string - if (isset($gettext_php_translateStrings[$str])) - return $gettext_php_translateStrings[$str]; - - // See if we should short-circuit - if ($gettext_php_short_circuit) { - $gettext_php_translateStrings[$str] = $str; - return $str; - } - - // Look for a string that is very close to the one we want - // Very computationally expensive - $oldPercent = 0; - $oldStr = ''; - $newPercent = 0; - foreach ($gettext_php_translateStrings as $k => $v) { - similar_text($str, $k, $newPercent); - if ($newPercent > $oldPercent) { - $oldStr = $v; - $oldPercent = $newPercent; - } - } - // Require 80% match or better - // Adjust to suit your needs - if ($oldPercent > 80) { - // Remember this so we don't need to search again - $gettext_php_translateStrings[$str] = $oldStr; - return $oldStr; - } - - // Remember this so we don't need to search again - $gettext_php_translateStrings[$str] = $str; - return $str; - } - - function bindtextdomain($name, $dir) { - global $gettext_php_domain, $gettext_php_dir, $gettext_php_loaded; + return $dir; +} - if ($gettext_php_domain != $name) { - $gettext_php_domain = $name; - $gettext_php_loaded = false; - } - if ($gettext_php_dir != $dir) { - $gettext_php_dir = $dir; - $gettext_php_loaded = false; - } - - return $dir; - } - - function textdomain($name = false) { - global $gettext_php_domain, $gettext_php_loaded; +/** + * Alternative php textdomain function + * + * 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; +} - if ($name != false && $gettext_php_domain != $name) { - $gettext_php_domain = $name; - $gettext_php_loaded = false; - } - return $gettext_php_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); + } +}