X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fgettext.php;h=89685b01e6d4b0b3fa81d81ec0d15e2678c9eac6;hb=1428d38dcbbce5cb9440b95bfa827e96ca4fa614;hp=6d18d8e54250175724dfffd2fdda88a8fc027010;hpb=7350889b45590aee831ba1150ee94efb95b03992;p=squirrelmail.git diff --git a/functions/gettext.php b/functions/gettext.php index 6d18d8e5..89685b01 100644 --- a/functions/gettext.php +++ b/functions/gettext.php @@ -1,198 +1,71 @@ -error==1) return $str; + return $l10n[$gettext_domain]->translate($str); +} - $filename = $gettext_php_dir; - if (substr($filename, -1) != '/') - $filename .= '/'; - $filename .= $squirrelmail_language . '/LC_MESSAGES/' . - $gettext_php_domain . '.po'; - - $file = @fopen($filename, 'r'); - if ($file == false) { - // Uh-ho -- we can't load the file. Just fake it. :-) - // This is also for English, which doesn't use translations - $gettext_php_loaded = true; - $gettext_php_loaded_language = $squirrelmail_language; - $gettext_php_short_circuit = true; // Avoid fuzzy matching when we - // didn't load strings - return; - } - - $key = ''; - $SkipRead = false; - while (! feof($file)) { - if (! $SkipRead) - $line = trim(fgets($file, 4096)); - else - $SkipRead = false; - - if (ereg('^msgid "(.*)"$', $line, $match)) { - if ($match[1] == '') { - // Potential multi-line - // msgid "" - // "string string " - // "string string" - $key = ''; - $line = trim(fgets($file, 4096)); - while (ereg('^[ ]*"(.*)"[ ]*$', $line, $match)) { - $key .= $match[1]; - $line = trim(fgets($file, 4096)); - } - $SkipRead = true; - } else { - // msgid "string string" - $key = $match[1]; - } - } elseif (ereg('^msgstr "(.*)"$', $line, $match)) { - if ($match[1] == '') { - // Potential multi-line - // msgstr "" - // "string string " - // "string string" - $gettext_php_translateStrings[$key] = ''; - $line = trim(fgets($file, 4096)); - while (ereg('^[ ]*"(.*)"[ ]*$', $line, $match)) { - $gettext_php_translateStrings[$key] .= $match[1]; - $line = trim(fgets($file, 4096)); - } - $SkipRead = true; - } else { - // msgstr "string string" - $gettext_php_translateStrings[$key] = $match[1]; - } - $gettext_php_translateStrings[$key] = - stripslashes($gettext_php_translateStrings[$key]); - $key = ''; - } - } - fclose($file); +/** + * 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 + */ +function bindtextdomain($domain, $dir) { + global $l10n, $sm_notAlias; + if (substr($dir, -1) != '/') $dir .= '/'; + $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo'; - $gettext_php_loaded = true; - $gettext_php_loaded_language = $squirrelmail_language; - } + $input = new FileReader($mofile); + $l10n[$domain] = new gettext_reader($input); - 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(); + return $dir; +} - // 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; - - 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; - - if ($name != false && $gettext_php_domain != $name) { - $gettext_php_domain = $name; - $gettext_php_loaded = false; - } - return $gettext_php_domain; - } - +/** + * 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_domain; + if ($name) $gettext_domain=$name; + return $gettext_domain; +} +?> \ No newline at end of file