X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fgettext.php;h=10d658be80eb7093daa8d2cb7a421438a78597fb;hp=851f7ad488bede9ad20c2a667294990536f9b544;hb=4f664925c839b9a9f58e4699718a1254ba35a8d7;hpb=a68fb657b2ed586fc67a820d2e0cd0a1f58bfa62 diff --git a/functions/gettext.php b/functions/gettext.php index 851f7ad4..10d658be 100644 --- a/functions/gettext.php +++ b/functions/gettext.php @@ -1,181 +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; - } - +?>