X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fgettext.php;h=f11f13f426b0e3a90da56715b6fd2c8404e9d570;hp=852f4c346831ef099a935904c2f087451e26314f;hb=eb19bc676326931545976b817f594025ed13eec0;hpb=55c10992cd9f162e50a44c5216bc135103e83fc5 diff --git a/functions/gettext.php b/functions/gettext.php index 852f4c34..f11f13f4 100644 --- a/functions/gettext.php +++ b/functions/gettext.php @@ -1,180 +1,251 @@ - $v) { - similar_text($str, $k, &$newPercent); - if ($newPercent > $oldPercent) { +/** + * Alternative php gettext function (short form) + * + * @link http://www.php.net/function.gettext + * + * @param string $str English string + * @return string translated string + */ +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(); + } + + /* 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; + } + } + /* 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; +} + +/** + * Alternative php bindtextdomain function + * + * Sets path to directory containing domain translations + * + * @link http://www.php.net/function.bindtextdomain + * @param string $name gettext domain name + * @param string $dir directory that contains all translations + * @return string path to translation directory + */ +function bindtextdomain($name, $dir) { + global $gettext_php_domain, $gettext_php_dir, $gettext_php_loaded; + + 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; +} - 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 + * + * @link http://www.php.net/function.textdomain + * @param string $name gettext domain name + * @return string gettext domain name + */ +function textdomain($name = false) { + global $gettext_php_domain, $gettext_php_loaded; + + if ($name != false && $gettext_php_domain != $name) { + $gettext_php_domain = $name; + $gettext_php_loaded = false; + } - if ($name != false && $gettext_php_domain != $name) { - $gettext_php_domain = $name; - $gettext_php_loaded = false; - } - return $gettext_php_domain; - } - + return $gettext_php_domain; +} +?> \ No newline at end of file