X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fgettext.php;h=4b2cae526e189ed8ba75bcc5b8371698e5f6df8b;hb=20d8f465db6de6683de84f6828f9a0b46c1c2a98;hp=2bbf221d46c353ce8b584812c203bd7cf9cea27f;hpb=355861846a51d35efe50848869d680fd3b4a5316;p=squirrelmail.git diff --git a/functions/gettext.php b/functions/gettext.php index 2bbf221d..4b2cae52 100644 --- a/functions/gettext.php +++ b/functions/gettext.php @@ -1,9 +1,9 @@ - $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; - } - +?>