X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fgettext.php;h=924904b9d6d9a373ee93bbf3f7729a8c392c2de2;hb=5d55b3d5a8aa567b2a9fb2d53d317976dc6cce5a;hp=7f8c59624b25be143b2d167fd826470ba40b7b03;hpb=b771345a46bcd229ae988a09a7cfa56c758d584a;p=squirrelmail.git diff --git a/functions/gettext.php b/functions/gettext.php index 7f8c5962..924904b9 100644 --- a/functions/gettext.php +++ b/functions/gettext.php @@ -1,193 +1,214 @@ - $v) { - similar_text($str, $k, $newPercent); - if ($newPercent > $oldPercent) { +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; +} + +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; +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; + } + return $gettext_php_domain; +} - if ($name != false && $gettext_php_domain != $name) { - $gettext_php_domain = $name; - $gettext_php_loaded = false; - } - return $gettext_php_domain; - } - +?>