@@ -70,17 +70,17 @@ discard block |
||
| 70 | 70 | /* not really important, this one; perhaps I could've put it inline with |
| 71 | 71 | * the rest. */ |
| 72 | 72 | function find_match($curlscore,$curcscore,$curgtlang,$langval,$charval, |
| 73 | - $gtlang) |
|
| 73 | + $gtlang) |
|
| 74 | 74 | { |
| 75 | 75 | if($curlscore < $langval) { |
| 76 | - $curlscore=$langval; |
|
| 77 | - $curcscore=$charval; |
|
| 78 | - $curgtlang=$gtlang; |
|
| 76 | + $curlscore=$langval; |
|
| 77 | + $curcscore=$charval; |
|
| 78 | + $curgtlang=$gtlang; |
|
| 79 | 79 | } else if ($curlscore == $langval) { |
| 80 | - if($curcscore < $charval) { |
|
| 81 | - $curcscore=$charval; |
|
| 82 | - $curgtlang=$gtlang; |
|
| 83 | - } |
|
| 80 | + if($curcscore < $charval) { |
|
| 81 | + $curcscore=$charval; |
|
| 82 | + $curgtlang=$gtlang; |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | return array($curlscore, $curcscore, $curgtlang); |
| 86 | 86 | } |
@@ -88,22 +88,22 @@ discard block |
||
| 88 | 88 | function al2gt($gettextlangs, $mime) { |
| 89 | 89 | /* default to "everything is acceptable", as RFC2616 specifies */ |
| 90 | 90 | $acceptLang=(($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : |
| 91 | - $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
|
| 91 | + $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
|
| 92 | 92 | $acceptChar=(($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : |
| 93 | - $_SERVER["HTTP_ACCEPT_CHARSET"]); |
|
| 93 | + $_SERVER["HTTP_ACCEPT_CHARSET"]); |
|
| 94 | 94 | $alparts=@preg_split("/,/",$acceptLang); |
| 95 | 95 | $acparts=@preg_split("/,/",$acceptChar); |
| 96 | 96 | |
| 97 | 97 | /* Parse the contents of the Accept-Language header.*/ |
| 98 | 98 | foreach($alparts as $part) { |
| 99 | - $part=trim($part); |
|
| 100 | - if(preg_match("/;/", $part)) { |
|
| 101 | - $lang=@preg_split("/;/",$part); |
|
| 102 | - $score=@preg_split("/=/",$lang[1]); |
|
| 103 | - $alscores[$lang[0]]=$score[1]; |
|
| 104 | - } else { |
|
| 105 | - $alscores[$part]=1; |
|
| 106 | - } |
|
| 99 | + $part=trim($part); |
|
| 100 | + if(preg_match("/;/", $part)) { |
|
| 101 | + $lang=@preg_split("/;/",$part); |
|
| 102 | + $score=@preg_split("/=/",$lang[1]); |
|
| 103 | + $alscores[$lang[0]]=$score[1]; |
|
| 104 | + } else { |
|
| 105 | + $alscores[$part]=1; |
|
| 106 | + } |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /* Do the same for the Accept-Charset header. */ |
@@ -119,17 +119,17 @@ discard block |
||
| 119 | 119 | $acscores["ISO-8859-1"]=2; |
| 120 | 120 | |
| 121 | 121 | foreach($acparts as $part) { |
| 122 | - $part=trim($part); |
|
| 123 | - if(preg_match("/;/", $part)) { |
|
| 124 | - $cs=@preg_split("/;/",$part); |
|
| 125 | - $score=@preg_split("/=/",$cs[1]); |
|
| 126 | - $acscores[strtoupper($cs[0])]=$score[1]; |
|
| 127 | - } else { |
|
| 128 | - $acscores[strtoupper($part)]=1; |
|
| 129 | - } |
|
| 122 | + $part=trim($part); |
|
| 123 | + if(preg_match("/;/", $part)) { |
|
| 124 | + $cs=@preg_split("/;/",$part); |
|
| 125 | + $score=@preg_split("/=/",$cs[1]); |
|
| 126 | + $acscores[strtoupper($cs[0])]=$score[1]; |
|
| 127 | + } else { |
|
| 128 | + $acscores[strtoupper($part)]=1; |
|
| 129 | + } |
|
| 130 | 130 | } |
| 131 | 131 | if($acscores["ISO-8859-1"]==2) { |
| 132 | - $acscores["ISO-8859-1"]=(isset($acscores["*"])?$acscores["*"]:1); |
|
| 132 | + $acscores["ISO-8859-1"]=(isset($acscores["*"])?$acscores["*"]:1); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /* |
@@ -142,31 +142,31 @@ discard block |
||
| 142 | 142 | $curgtlang=NULL; |
| 143 | 143 | foreach($gettextlangs as $gtlang) { |
| 144 | 144 | |
| 145 | - $tmp1=preg_replace("/\_/","-",$gtlang); |
|
| 146 | - $tmp2=@preg_split("/\./",$tmp1); |
|
| 147 | - $allang=strtolower($tmp2[0]); |
|
| 148 | - $gtcs=strtoupper($tmp2[1]); |
|
| 149 | - $noct=@preg_split("/-/",$allang); |
|
| 145 | + $tmp1=preg_replace("/\_/","-",$gtlang); |
|
| 146 | + $tmp2=@preg_split("/\./",$tmp1); |
|
| 147 | + $allang=strtolower($tmp2[0]); |
|
| 148 | + $gtcs=strtoupper($tmp2[1]); |
|
| 149 | + $noct=@preg_split("/-/",$allang); |
|
| 150 | 150 | |
| 151 | - $testvals=array( |
|
| 152 | - array(@$alscores[$allang], @$acscores[$gtcs]), |
|
| 153 | - array(@$alscores[$noct[0]], @$acscores[$gtcs]), |
|
| 154 | - array(@$alscores[$allang], @$acscores["*"]), |
|
| 155 | - array(@$alscores[$noct[0]], @$acscores["*"]), |
|
| 156 | - array(@$alscores["*"], @$acscores[$gtcs]), |
|
| 157 | - array(@$alscores["*"], @$acscores["*"])); |
|
| 151 | + $testvals=array( |
|
| 152 | + array(@$alscores[$allang], @$acscores[$gtcs]), |
|
| 153 | + array(@$alscores[$noct[0]], @$acscores[$gtcs]), |
|
| 154 | + array(@$alscores[$allang], @$acscores["*"]), |
|
| 155 | + array(@$alscores[$noct[0]], @$acscores["*"]), |
|
| 156 | + array(@$alscores["*"], @$acscores[$gtcs]), |
|
| 157 | + array(@$alscores["*"], @$acscores["*"])); |
|
| 158 | 158 | |
| 159 | - $found=FALSE; |
|
| 160 | - foreach($testvals as $tval) { |
|
| 161 | - if(!$found && isset($tval[0]) && isset($tval[1])) { |
|
| 162 | - $arr=find_match($curlscore, $curcscore, $curgtlang, $tval[0], |
|
| 163 | - $tval[1], $gtlang); |
|
| 164 | - $curlscore=$arr[0]; |
|
| 165 | - $curcscore=$arr[1]; |
|
| 166 | - $curgtlang=$arr[2]; |
|
| 167 | - $found=TRUE; |
|
| 168 | - } |
|
| 169 | - } |
|
| 159 | + $found=FALSE; |
|
| 160 | + foreach($testvals as $tval) { |
|
| 161 | + if(!$found && isset($tval[0]) && isset($tval[1])) { |
|
| 162 | + $arr=find_match($curlscore, $curcscore, $curgtlang, $tval[0], |
|
| 163 | + $tval[1], $gtlang); |
|
| 164 | + $curlscore=$arr[0]; |
|
| 165 | + $curcscore=$arr[1]; |
|
| 166 | + $curgtlang=$arr[2]; |
|
| 167 | + $found=TRUE; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /* We must re-parse the gettext-string now, since we may have found it |
@@ -74,38 +74,38 @@ discard block |
||
| 74 | 74 | $charset = NULL; |
| 75 | 75 | $modifier = NULL; |
| 76 | 76 | if ($locale) { |
| 77 | - if (preg_match("/^(?P<lang>[a-z]{2,3})" // language code |
|
| 78 | - ."(?:_(?P<country>[A-Z]{2}))?" // country code |
|
| 79 | - ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?" // charset |
|
| 80 | - ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
| 81 | - $locale, $matches)) { |
|
| 82 | - |
|
| 83 | - if (isset($matches["lang"])) $lang = $matches["lang"]; |
|
| 84 | - if (isset($matches["country"])) $country = $matches["country"]; |
|
| 85 | - if (isset($matches["charset"])) $charset = $matches["charset"]; |
|
| 86 | - if (isset($matches["modifier"])) $modifier = $matches["modifier"]; |
|
| 87 | - |
|
| 88 | - if ($modifier) { |
|
| 89 | - if ($country) { |
|
| 90 | - if ($charset) |
|
| 91 | - array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
| 92 | - array_push($locale_names, "${lang}_$country@$modifier"); |
|
| 93 | - } elseif ($charset) |
|
| 94 | - array_push($locale_names, "${lang}.$charset@$modifier"); |
|
| 95 | - array_push($locale_names, "$lang@$modifier"); |
|
| 96 | - } |
|
| 97 | - if ($country) { |
|
| 98 | - if ($charset) |
|
| 99 | - array_push($locale_names, "${lang}_$country.$charset"); |
|
| 100 | - array_push($locale_names, "${lang}_$country"); |
|
| 101 | - } elseif ($charset) |
|
| 102 | - array_push($locale_names, "${lang}.$charset"); |
|
| 103 | - array_push($locale_names, $lang); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // If the locale name doesn't match POSIX style, just include it as-is. |
|
| 107 | - if (!in_array($locale, $locale_names)) |
|
| 108 | - array_push($locale_names, $locale); |
|
| 77 | + if (preg_match("/^(?P<lang>[a-z]{2,3})" // language code |
|
| 78 | + ."(?:_(?P<country>[A-Z]{2}))?" // country code |
|
| 79 | + ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?" // charset |
|
| 80 | + ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
| 81 | + $locale, $matches)) { |
|
| 82 | + |
|
| 83 | + if (isset($matches["lang"])) $lang = $matches["lang"]; |
|
| 84 | + if (isset($matches["country"])) $country = $matches["country"]; |
|
| 85 | + if (isset($matches["charset"])) $charset = $matches["charset"]; |
|
| 86 | + if (isset($matches["modifier"])) $modifier = $matches["modifier"]; |
|
| 87 | + |
|
| 88 | + if ($modifier) { |
|
| 89 | + if ($country) { |
|
| 90 | + if ($charset) |
|
| 91 | + array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
| 92 | + array_push($locale_names, "${lang}_$country@$modifier"); |
|
| 93 | + } elseif ($charset) |
|
| 94 | + array_push($locale_names, "${lang}.$charset@$modifier"); |
|
| 95 | + array_push($locale_names, "$lang@$modifier"); |
|
| 96 | + } |
|
| 97 | + if ($country) { |
|
| 98 | + if ($charset) |
|
| 99 | + array_push($locale_names, "${lang}_$country.$charset"); |
|
| 100 | + array_push($locale_names, "${lang}_$country"); |
|
| 101 | + } elseif ($charset) |
|
| 102 | + array_push($locale_names, "${lang}.$charset"); |
|
| 103 | + array_push($locale_names, $lang); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // If the locale name doesn't match POSIX style, just include it as-is. |
|
| 107 | + if (!in_array($locale, $locale_names)) |
|
| 108 | + array_push($locale_names, $locale); |
|
| 109 | 109 | } |
| 110 | 110 | return $locale_names; |
| 111 | 111 | } |
@@ -114,60 +114,60 @@ discard block |
||
| 114 | 114 | * Utility function to get a StreamReader for the given text domain. |
| 115 | 115 | */ |
| 116 | 116 | function _get_reader($domain=null, $category=5, $enable_cache=true) { |
| 117 | - global $text_domains, $default_domain, $LC_CATEGORIES; |
|
| 118 | - if (!isset($domain)) $domain = $default_domain; |
|
| 119 | - if (!isset($text_domains[$domain]->l10n)) { |
|
| 120 | - // get the current locale |
|
| 121 | - $locale = _setlocale(LC_MESSAGES, 0); |
|
| 122 | - $bound_path = isset($text_domains[$domain]->path) ? |
|
| 123 | - $text_domains[$domain]->path : './'; |
|
| 124 | - $subpath = $LC_CATEGORIES[$category] ."/$domain.mo"; |
|
| 125 | - |
|
| 126 | - $locale_names = get_list_of_locales($locale); |
|
| 127 | - $input = null; |
|
| 128 | - foreach ($locale_names as $locale) { |
|
| 129 | - $full_path = $bound_path . $locale . "/" . $subpath; |
|
| 130 | - if (file_exists($full_path)) { |
|
| 131 | - $input = new FileReader($full_path); |
|
| 132 | - break; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - if (!array_key_exists($domain, $text_domains)) { |
|
| 137 | - // Initialize an empty domain object. |
|
| 138 | - $text_domains[$domain] = new domain(); |
|
| 139 | - } |
|
| 140 | - $text_domains[$domain]->l10n = new gettext_reader($input, |
|
| 141 | - $enable_cache); |
|
| 142 | - } |
|
| 143 | - return $text_domains[$domain]->l10n; |
|
| 117 | + global $text_domains, $default_domain, $LC_CATEGORIES; |
|
| 118 | + if (!isset($domain)) $domain = $default_domain; |
|
| 119 | + if (!isset($text_domains[$domain]->l10n)) { |
|
| 120 | + // get the current locale |
|
| 121 | + $locale = _setlocale(LC_MESSAGES, 0); |
|
| 122 | + $bound_path = isset($text_domains[$domain]->path) ? |
|
| 123 | + $text_domains[$domain]->path : './'; |
|
| 124 | + $subpath = $LC_CATEGORIES[$category] ."/$domain.mo"; |
|
| 125 | + |
|
| 126 | + $locale_names = get_list_of_locales($locale); |
|
| 127 | + $input = null; |
|
| 128 | + foreach ($locale_names as $locale) { |
|
| 129 | + $full_path = $bound_path . $locale . "/" . $subpath; |
|
| 130 | + if (file_exists($full_path)) { |
|
| 131 | + $input = new FileReader($full_path); |
|
| 132 | + break; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + if (!array_key_exists($domain, $text_domains)) { |
|
| 137 | + // Initialize an empty domain object. |
|
| 138 | + $text_domains[$domain] = new domain(); |
|
| 139 | + } |
|
| 140 | + $text_domains[$domain]->l10n = new gettext_reader($input, |
|
| 141 | + $enable_cache); |
|
| 142 | + } |
|
| 143 | + return $text_domains[$domain]->l10n; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | 147 | * Returns whether we are using our emulated gettext API or PHP built-in one. |
| 148 | 148 | */ |
| 149 | 149 | function locale_emulation() { |
| 150 | - global $EMULATEGETTEXT; |
|
| 151 | - return $EMULATEGETTEXT; |
|
| 150 | + global $EMULATEGETTEXT; |
|
| 151 | + return $EMULATEGETTEXT; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | 155 | * Checks if the current locale is supported on this system. |
| 156 | 156 | */ |
| 157 | 157 | function _check_locale_and_function($function=false) { |
| 158 | - global $EMULATEGETTEXT; |
|
| 159 | - if ($function and !function_exists($function)) |
|
| 160 | - return false; |
|
| 161 | - return !$EMULATEGETTEXT; |
|
| 158 | + global $EMULATEGETTEXT; |
|
| 159 | + if ($function and !function_exists($function)) |
|
| 160 | + return false; |
|
| 161 | + return !$EMULATEGETTEXT; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
| 165 | 165 | * Get the codeset for the given domain. |
| 166 | 166 | */ |
| 167 | 167 | function _get_codeset($domain=null) { |
| 168 | - global $text_domains, $default_domain, $LC_CATEGORIES; |
|
| 169 | - if (!isset($domain)) $domain = $default_domain; |
|
| 170 | - return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding'); |
|
| 168 | + global $text_domains, $default_domain, $LC_CATEGORIES; |
|
| 169 | + if (!isset($domain)) $domain = $default_domain; |
|
| 170 | + return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding'); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | function _encode($text) { |
| 177 | 177 | $target_encoding = _get_codeset(); |
| 178 | 178 | if (function_exists("mb_detect_encoding")) { |
| 179 | - $source_encoding = mb_detect_encoding($text); |
|
| 180 | - if ($source_encoding != $target_encoding) |
|
| 181 | - $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
| 179 | + $source_encoding = mb_detect_encoding($text); |
|
| 180 | + if ($source_encoding != $target_encoding) |
|
| 181 | + $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
| 182 | 182 | } |
| 183 | 183 | return $text; |
| 184 | 184 | } |
@@ -191,185 +191,185 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | function _get_default_locale($locale) { |
| 193 | 193 | if ($locale == '') // emulate variable support |
| 194 | - return getenv('LANG'); |
|
| 194 | + return getenv('LANG'); |
|
| 195 | 195 | else |
| 196 | - return $locale; |
|
| 196 | + return $locale; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
| 200 | 200 | * Sets a requested locale, if needed emulates it. |
| 201 | 201 | */ |
| 202 | 202 | function _setlocale($category, $locale) { |
| 203 | - global $CURRENTLOCALE, $EMULATEGETTEXT; |
|
| 204 | - if ($locale === 0) { // use === to differentiate between string "0" |
|
| 205 | - if ($CURRENTLOCALE != '') |
|
| 206 | - return $CURRENTLOCALE; |
|
| 207 | - else |
|
| 208 | - // obey LANG variable, maybe extend to support all of LC_* vars |
|
| 209 | - // even if we tried to read locale without setting it first |
|
| 210 | - return _setlocale($category, $CURRENTLOCALE); |
|
| 211 | - } else { |
|
| 212 | - if (function_exists('setlocale')) { |
|
| 213 | - $ret = setlocale($category, $locale); |
|
| 214 | - if (($locale == '' and !$ret) or // failed setting it by env |
|
| 215 | - ($locale != '' and $ret != $locale)) { // failed setting it |
|
| 216 | - // Failed setting it according to environment. |
|
| 217 | - $CURRENTLOCALE = _get_default_locale($locale); |
|
| 218 | - $EMULATEGETTEXT = 1; |
|
| 219 | - } else { |
|
| 220 | - $CURRENTLOCALE = $ret; |
|
| 221 | - $EMULATEGETTEXT = 0; |
|
| 222 | - } |
|
| 223 | - } else { |
|
| 224 | - // No function setlocale(), emulate it all. |
|
| 225 | - $CURRENTLOCALE = _get_default_locale($locale); |
|
| 226 | - $EMULATEGETTEXT = 1; |
|
| 227 | - } |
|
| 228 | - // Allow locale to be changed on the go for one translation domain. |
|
| 229 | - global $text_domains, $default_domain; |
|
| 230 | - if (array_key_exists($default_domain, $text_domains)) { |
|
| 231 | - unset($text_domains[$default_domain]->l10n); |
|
| 232 | - } |
|
| 233 | - return $CURRENTLOCALE; |
|
| 234 | - } |
|
| 203 | + global $CURRENTLOCALE, $EMULATEGETTEXT; |
|
| 204 | + if ($locale === 0) { // use === to differentiate between string "0" |
|
| 205 | + if ($CURRENTLOCALE != '') |
|
| 206 | + return $CURRENTLOCALE; |
|
| 207 | + else |
|
| 208 | + // obey LANG variable, maybe extend to support all of LC_* vars |
|
| 209 | + // even if we tried to read locale without setting it first |
|
| 210 | + return _setlocale($category, $CURRENTLOCALE); |
|
| 211 | + } else { |
|
| 212 | + if (function_exists('setlocale')) { |
|
| 213 | + $ret = setlocale($category, $locale); |
|
| 214 | + if (($locale == '' and !$ret) or // failed setting it by env |
|
| 215 | + ($locale != '' and $ret != $locale)) { // failed setting it |
|
| 216 | + // Failed setting it according to environment. |
|
| 217 | + $CURRENTLOCALE = _get_default_locale($locale); |
|
| 218 | + $EMULATEGETTEXT = 1; |
|
| 219 | + } else { |
|
| 220 | + $CURRENTLOCALE = $ret; |
|
| 221 | + $EMULATEGETTEXT = 0; |
|
| 222 | + } |
|
| 223 | + } else { |
|
| 224 | + // No function setlocale(), emulate it all. |
|
| 225 | + $CURRENTLOCALE = _get_default_locale($locale); |
|
| 226 | + $EMULATEGETTEXT = 1; |
|
| 227 | + } |
|
| 228 | + // Allow locale to be changed on the go for one translation domain. |
|
| 229 | + global $text_domains, $default_domain; |
|
| 230 | + if (array_key_exists($default_domain, $text_domains)) { |
|
| 231 | + unset($text_domains[$default_domain]->l10n); |
|
| 232 | + } |
|
| 233 | + return $CURRENTLOCALE; |
|
| 234 | + } |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
| 238 | 238 | * Sets the path for a domain. |
| 239 | 239 | */ |
| 240 | 240 | function _bindtextdomain($domain, $path) { |
| 241 | - global $text_domains; |
|
| 242 | - // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
|
| 243 | - if (substr(php_uname(), 0, 7) == "Windows") { |
|
| 244 | - if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
| 245 | - $path .= '\\'; |
|
| 246 | - } else { |
|
| 247 | - if ($path[strlen($path)-1] != '/') |
|
| 248 | - $path .= '/'; |
|
| 249 | - } |
|
| 250 | - if (!array_key_exists($domain, $text_domains)) { |
|
| 251 | - // Initialize an empty domain object. |
|
| 252 | - $text_domains[$domain] = new domain(); |
|
| 253 | - } |
|
| 254 | - $text_domains[$domain]->path = $path; |
|
| 241 | + global $text_domains; |
|
| 242 | + // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
|
| 243 | + if (substr(php_uname(), 0, 7) == "Windows") { |
|
| 244 | + if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
| 245 | + $path .= '\\'; |
|
| 246 | + } else { |
|
| 247 | + if ($path[strlen($path)-1] != '/') |
|
| 248 | + $path .= '/'; |
|
| 249 | + } |
|
| 250 | + if (!array_key_exists($domain, $text_domains)) { |
|
| 251 | + // Initialize an empty domain object. |
|
| 252 | + $text_domains[$domain] = new domain(); |
|
| 253 | + } |
|
| 254 | + $text_domains[$domain]->path = $path; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
| 258 | 258 | * Specify the character encoding in which the messages from the DOMAIN message catalog will be returned. |
| 259 | 259 | */ |
| 260 | 260 | function _bind_textdomain_codeset($domain, $codeset) { |
| 261 | - global $text_domains; |
|
| 262 | - $text_domains[$domain]->codeset = $codeset; |
|
| 261 | + global $text_domains; |
|
| 262 | + $text_domains[$domain]->codeset = $codeset; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
| 266 | 266 | * Sets the default domain. |
| 267 | 267 | */ |
| 268 | 268 | function _textdomain($domain) { |
| 269 | - global $default_domain; |
|
| 270 | - $default_domain = $domain; |
|
| 269 | + global $default_domain; |
|
| 270 | + $default_domain = $domain; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
| 274 | 274 | * Lookup a message in the current domain. |
| 275 | 275 | */ |
| 276 | 276 | function _gettext($msgid) { |
| 277 | - $l10n = _get_reader(); |
|
| 278 | - return _encode($l10n->translate($msgid)); |
|
| 277 | + $l10n = _get_reader(); |
|
| 278 | + return _encode($l10n->translate($msgid)); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
| 282 | 282 | * Alias for gettext. |
| 283 | 283 | */ |
| 284 | 284 | function __($msgid) { |
| 285 | - return _gettext($msgid); |
|
| 285 | + return _gettext($msgid); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
| 289 | 289 | * Plural version of gettext. |
| 290 | 290 | */ |
| 291 | 291 | function _ngettext($singular, $plural, $number) { |
| 292 | - $l10n = _get_reader(); |
|
| 293 | - return _encode($l10n->ngettext($singular, $plural, $number)); |
|
| 292 | + $l10n = _get_reader(); |
|
| 293 | + return _encode($l10n->ngettext($singular, $plural, $number)); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
| 297 | 297 | * Override the current domain. |
| 298 | 298 | */ |
| 299 | 299 | function _dgettext($domain, $msgid) { |
| 300 | - $l10n = _get_reader($domain); |
|
| 301 | - return _encode($l10n->translate($msgid)); |
|
| 300 | + $l10n = _get_reader($domain); |
|
| 301 | + return _encode($l10n->translate($msgid)); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
| 305 | 305 | * Plural version of dgettext. |
| 306 | 306 | */ |
| 307 | 307 | function _dngettext($domain, $singular, $plural, $number) { |
| 308 | - $l10n = _get_reader($domain); |
|
| 309 | - return _encode($l10n->ngettext($singular, $plural, $number)); |
|
| 308 | + $l10n = _get_reader($domain); |
|
| 309 | + return _encode($l10n->ngettext($singular, $plural, $number)); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
| 313 | 313 | * Overrides the domain and category for a single lookup. |
| 314 | 314 | */ |
| 315 | 315 | function _dcgettext($domain, $msgid, $category) { |
| 316 | - $l10n = _get_reader($domain, $category); |
|
| 317 | - return _encode($l10n->translate($msgid)); |
|
| 316 | + $l10n = _get_reader($domain, $category); |
|
| 317 | + return _encode($l10n->translate($msgid)); |
|
| 318 | 318 | } |
| 319 | 319 | /** |
| 320 | 320 | * Plural version of dcgettext. |
| 321 | 321 | */ |
| 322 | 322 | function _dcngettext($domain, $singular, $plural, $number, $category) { |
| 323 | - $l10n = _get_reader($domain, $category); |
|
| 324 | - return _encode($l10n->ngettext($singular, $plural, $number)); |
|
| 323 | + $l10n = _get_reader($domain, $category); |
|
| 324 | + return _encode($l10n->ngettext($singular, $plural, $number)); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
| 328 | 328 | * Context version of gettext. |
| 329 | 329 | */ |
| 330 | 330 | function _pgettext($context, $msgid) { |
| 331 | - $l10n = _get_reader(); |
|
| 332 | - return _encode($l10n->pgettext($context, $msgid)); |
|
| 331 | + $l10n = _get_reader(); |
|
| 332 | + return _encode($l10n->pgettext($context, $msgid)); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
| 336 | 336 | * Override the current domain in a context gettext call. |
| 337 | 337 | */ |
| 338 | 338 | function _dpgettext($domain, $context, $msgid) { |
| 339 | - $l10n = _get_reader($domain); |
|
| 340 | - return _encode($l10n->pgettext($context, $msgid)); |
|
| 339 | + $l10n = _get_reader($domain); |
|
| 340 | + return _encode($l10n->pgettext($context, $msgid)); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
| 344 | 344 | * Overrides the domain and category for a single context-based lookup. |
| 345 | 345 | */ |
| 346 | 346 | function _dcpgettext($domain, $context, $msgid, $category) { |
| 347 | - $l10n = _get_reader($domain, $category); |
|
| 348 | - return _encode($l10n->pgettext($context, $msgid)); |
|
| 347 | + $l10n = _get_reader($domain, $category); |
|
| 348 | + return _encode($l10n->pgettext($context, $msgid)); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
| 352 | 352 | * Context version of ngettext. |
| 353 | 353 | */ |
| 354 | 354 | function _npgettext($context, $singular, $plural) { |
| 355 | - $l10n = _get_reader(); |
|
| 356 | - return _encode($l10n->npgettext($context, $singular, $plural)); |
|
| 355 | + $l10n = _get_reader(); |
|
| 356 | + return _encode($l10n->npgettext($context, $singular, $plural)); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
| 360 | 360 | * Override the current domain in a context ngettext call. |
| 361 | 361 | */ |
| 362 | 362 | function _dnpgettext($domain, $context, $singular, $plural) { |
| 363 | - $l10n = _get_reader($domain); |
|
| 364 | - return _encode($l10n->npgettext($context, $singular, $plural)); |
|
| 363 | + $l10n = _get_reader($domain); |
|
| 364 | + return _encode($l10n->npgettext($context, $singular, $plural)); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
| 368 | 368 | * Overrides the domain and category for a plural context-based lookup. |
| 369 | 369 | */ |
| 370 | 370 | function _dcnpgettext($domain, $context, $singular, $plural, $category) { |
| 371 | - $l10n = _get_reader($domain, $category); |
|
| 372 | - return _encode($l10n->npgettext($context, $singular, $plural)); |
|
| 371 | + $l10n = _get_reader($domain, $category); |
|
| 372 | + return _encode($l10n->npgettext($context, $singular, $plural)); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | |
@@ -380,99 +380,99 @@ discard block |
||
| 380 | 380 | // custom impl otherwise. |
| 381 | 381 | |
| 382 | 382 | function T_setlocale($category, $locale) { |
| 383 | - return _setlocale($category, $locale); |
|
| 383 | + return _setlocale($category, $locale); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | function T_bindtextdomain($domain, $path) { |
| 387 | - if (_check_locale_and_function()) return bindtextdomain($domain, $path); |
|
| 388 | - else return _bindtextdomain($domain, $path); |
|
| 387 | + if (_check_locale_and_function()) return bindtextdomain($domain, $path); |
|
| 388 | + else return _bindtextdomain($domain, $path); |
|
| 389 | 389 | } |
| 390 | 390 | function T_bind_textdomain_codeset($domain, $codeset) { |
| 391 | - // bind_textdomain_codeset is available only in PHP 4.2.0+ |
|
| 392 | - if (_check_locale_and_function('bind_textdomain_codeset')) |
|
| 393 | - return bind_textdomain_codeset($domain, $codeset); |
|
| 394 | - else return _bind_textdomain_codeset($domain, $codeset); |
|
| 391 | + // bind_textdomain_codeset is available only in PHP 4.2.0+ |
|
| 392 | + if (_check_locale_and_function('bind_textdomain_codeset')) |
|
| 393 | + return bind_textdomain_codeset($domain, $codeset); |
|
| 394 | + else return _bind_textdomain_codeset($domain, $codeset); |
|
| 395 | 395 | } |
| 396 | 396 | function T_textdomain($domain) { |
| 397 | - if (_check_locale_and_function()) return textdomain($domain); |
|
| 398 | - else return _textdomain($domain); |
|
| 397 | + if (_check_locale_and_function()) return textdomain($domain); |
|
| 398 | + else return _textdomain($domain); |
|
| 399 | 399 | } |
| 400 | 400 | function T_gettext($msgid) { |
| 401 | - if (_check_locale_and_function()) return gettext($msgid); |
|
| 402 | - else return _gettext($msgid); |
|
| 401 | + if (_check_locale_and_function()) return gettext($msgid); |
|
| 402 | + else return _gettext($msgid); |
|
| 403 | 403 | } |
| 404 | 404 | function T_($msgid) { |
| 405 | - if (_check_locale_and_function()) return _($msgid); |
|
| 406 | - return __($msgid); |
|
| 405 | + if (_check_locale_and_function()) return _($msgid); |
|
| 406 | + return __($msgid); |
|
| 407 | 407 | } |
| 408 | 408 | function T_ngettext($singular, $plural, $number) { |
| 409 | - if (_check_locale_and_function()) |
|
| 410 | - return ngettext($singular, $plural, $number); |
|
| 411 | - else return _ngettext($singular, $plural, $number); |
|
| 409 | + if (_check_locale_and_function()) |
|
| 410 | + return ngettext($singular, $plural, $number); |
|
| 411 | + else return _ngettext($singular, $plural, $number); |
|
| 412 | 412 | } |
| 413 | 413 | function T_dgettext($domain, $msgid) { |
| 414 | - if (_check_locale_and_function()) return dgettext($domain, $msgid); |
|
| 415 | - else return _dgettext($domain, $msgid); |
|
| 414 | + if (_check_locale_and_function()) return dgettext($domain, $msgid); |
|
| 415 | + else return _dgettext($domain, $msgid); |
|
| 416 | 416 | } |
| 417 | 417 | function T_dngettext($domain, $singular, $plural, $number) { |
| 418 | - if (_check_locale_and_function()) |
|
| 419 | - return dngettext($domain, $singular, $plural, $number); |
|
| 420 | - else return _dngettext($domain, $singular, $plural, $number); |
|
| 418 | + if (_check_locale_and_function()) |
|
| 419 | + return dngettext($domain, $singular, $plural, $number); |
|
| 420 | + else return _dngettext($domain, $singular, $plural, $number); |
|
| 421 | 421 | } |
| 422 | 422 | function T_dcgettext($domain, $msgid, $category) { |
| 423 | - if (_check_locale_and_function()) |
|
| 424 | - return dcgettext($domain, $msgid, $category); |
|
| 425 | - else return _dcgettext($domain, $msgid, $category); |
|
| 423 | + if (_check_locale_and_function()) |
|
| 424 | + return dcgettext($domain, $msgid, $category); |
|
| 425 | + else return _dcgettext($domain, $msgid, $category); |
|
| 426 | 426 | } |
| 427 | 427 | function T_dcngettext($domain, $singular, $plural, $number, $category) { |
| 428 | - if (_check_locale_and_function()) |
|
| 429 | - return dcngettext($domain, $singular, $plural, $number, $category); |
|
| 430 | - else return _dcngettext($domain, $singular, $plural, $number, $category); |
|
| 428 | + if (_check_locale_and_function()) |
|
| 429 | + return dcngettext($domain, $singular, $plural, $number, $category); |
|
| 430 | + else return _dcngettext($domain, $singular, $plural, $number, $category); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | function T_pgettext($context, $msgid) { |
| 434 | 434 | if (_check_locale_and_function('pgettext')) |
| 435 | - return pgettext($context, $msgid); |
|
| 435 | + return pgettext($context, $msgid); |
|
| 436 | 436 | else |
| 437 | - return _pgettext($context, $msgid); |
|
| 437 | + return _pgettext($context, $msgid); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | function T_dpgettext($domain, $context, $msgid) { |
| 441 | 441 | if (_check_locale_and_function('dpgettext')) |
| 442 | - return dpgettext($domain, $context, $msgid); |
|
| 442 | + return dpgettext($domain, $context, $msgid); |
|
| 443 | 443 | else |
| 444 | - return _dpgettext($domain, $context, $msgid); |
|
| 444 | + return _dpgettext($domain, $context, $msgid); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | function T_dcpgettext($domain, $context, $msgid, $category) { |
| 448 | 448 | if (_check_locale_and_function('dcpgettext')) |
| 449 | - return dcpgettext($domain, $context, $msgid, $category); |
|
| 449 | + return dcpgettext($domain, $context, $msgid, $category); |
|
| 450 | 450 | else |
| 451 | - return _dcpgettext($domain, $context, $msgid, $category); |
|
| 451 | + return _dcpgettext($domain, $context, $msgid, $category); |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | function T_npgettext($context, $singular, $plural, $number) { |
| 455 | - if (_check_locale_and_function('npgettext')) |
|
| 456 | - return npgettext($context, $singular, $plural, $number); |
|
| 457 | - else |
|
| 458 | - return _npgettext($context, $singular, $plural, $number); |
|
| 455 | + if (_check_locale_and_function('npgettext')) |
|
| 456 | + return npgettext($context, $singular, $plural, $number); |
|
| 457 | + else |
|
| 458 | + return _npgettext($context, $singular, $plural, $number); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | function T_dnpgettext($domain, $context, $singular, $plural, $number) { |
| 462 | 462 | if (_check_locale_and_function('dnpgettext')) |
| 463 | - return dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 463 | + return dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 464 | 464 | else |
| 465 | - return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 465 | + return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | function T_dcnpgettext($domain, $context, $singular, $plural, |
| 469 | - $number, $category) { |
|
| 470 | - if (_check_locale_and_function('dcnpgettext')) |
|
| 471 | - return dcnpgettext($domain, $context, $singular, |
|
| 472 | - $plural, $number, $category); |
|
| 473 | - else |
|
| 474 | - return _dcnpgettext($domain, $context, $singular, |
|
| 475 | - $plural, $number, $category); |
|
| 469 | + $number, $category) { |
|
| 470 | + if (_check_locale_and_function('dcnpgettext')) |
|
| 471 | + return dcnpgettext($domain, $context, $singular, |
|
| 472 | + $plural, $number, $category); |
|
| 473 | + else |
|
| 474 | + return _dcnpgettext($domain, $context, $singular, |
|
| 475 | + $plural, $number, $category); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | |
@@ -480,56 +480,56 @@ discard block |
||
| 480 | 480 | // Wrappers used as a drop in replacement for the standard gettext functions |
| 481 | 481 | |
| 482 | 482 | if (!function_exists('gettext')) { |
| 483 | - function bindtextdomain($domain, $path) { |
|
| 484 | - return _bindtextdomain($domain, $path); |
|
| 485 | - } |
|
| 486 | - function bind_textdomain_codeset($domain, $codeset) { |
|
| 487 | - return _bind_textdomain_codeset($domain, $codeset); |
|
| 488 | - } |
|
| 489 | - function textdomain($domain) { |
|
| 490 | - return _textdomain($domain); |
|
| 491 | - } |
|
| 492 | - function gettext($msgid) { |
|
| 493 | - return _gettext($msgid); |
|
| 494 | - } |
|
| 495 | - function _($msgid) { |
|
| 496 | - return __($msgid); |
|
| 497 | - } |
|
| 498 | - function ngettext($singular, $plural, $number) { |
|
| 499 | - return _ngettext($singular, $plural, $number); |
|
| 500 | - } |
|
| 501 | - function dgettext($domain, $msgid) { |
|
| 502 | - return _dgettext($domain, $msgid); |
|
| 503 | - } |
|
| 504 | - function dngettext($domain, $singular, $plural, $number) { |
|
| 505 | - return _dngettext($domain, $singular, $plural, $number); |
|
| 506 | - } |
|
| 507 | - function dcgettext($domain, $msgid, $category) { |
|
| 508 | - return _dcgettext($domain, $msgid, $category); |
|
| 509 | - } |
|
| 510 | - function dcngettext($domain, $singular, $plural, $number, $category) { |
|
| 511 | - return _dcngettext($domain, $singular, $plural, $number, $category); |
|
| 512 | - } |
|
| 513 | - function pgettext($context, $msgid) { |
|
| 514 | - return _pgettext($context, $msgid); |
|
| 515 | - } |
|
| 516 | - function npgettext($context, $singular, $plural, $number) { |
|
| 517 | - return _npgettext($context, $singular, $plural, $number); |
|
| 518 | - } |
|
| 519 | - function dpgettext($domain, $context, $msgid) { |
|
| 520 | - return _dpgettext($domain, $context, $msgid); |
|
| 521 | - } |
|
| 522 | - function dnpgettext($domain, $context, $singular, $plural, $number) { |
|
| 523 | - return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 524 | - } |
|
| 525 | - function dcpgettext($domain, $context, $msgid, $category) { |
|
| 526 | - return _dcpgettext($domain, $context, $msgid, $category); |
|
| 527 | - } |
|
| 528 | - function dcnpgettext($domain, $context, $singular, $plural, |
|
| 529 | - $number, $category) { |
|
| 530 | - return _dcnpgettext($domain, $context, $singular, $plural, |
|
| 531 | - $number, $category); |
|
| 532 | - } |
|
| 483 | + function bindtextdomain($domain, $path) { |
|
| 484 | + return _bindtextdomain($domain, $path); |
|
| 485 | + } |
|
| 486 | + function bind_textdomain_codeset($domain, $codeset) { |
|
| 487 | + return _bind_textdomain_codeset($domain, $codeset); |
|
| 488 | + } |
|
| 489 | + function textdomain($domain) { |
|
| 490 | + return _textdomain($domain); |
|
| 491 | + } |
|
| 492 | + function gettext($msgid) { |
|
| 493 | + return _gettext($msgid); |
|
| 494 | + } |
|
| 495 | + function _($msgid) { |
|
| 496 | + return __($msgid); |
|
| 497 | + } |
|
| 498 | + function ngettext($singular, $plural, $number) { |
|
| 499 | + return _ngettext($singular, $plural, $number); |
|
| 500 | + } |
|
| 501 | + function dgettext($domain, $msgid) { |
|
| 502 | + return _dgettext($domain, $msgid); |
|
| 503 | + } |
|
| 504 | + function dngettext($domain, $singular, $plural, $number) { |
|
| 505 | + return _dngettext($domain, $singular, $plural, $number); |
|
| 506 | + } |
|
| 507 | + function dcgettext($domain, $msgid, $category) { |
|
| 508 | + return _dcgettext($domain, $msgid, $category); |
|
| 509 | + } |
|
| 510 | + function dcngettext($domain, $singular, $plural, $number, $category) { |
|
| 511 | + return _dcngettext($domain, $singular, $plural, $number, $category); |
|
| 512 | + } |
|
| 513 | + function pgettext($context, $msgid) { |
|
| 514 | + return _pgettext($context, $msgid); |
|
| 515 | + } |
|
| 516 | + function npgettext($context, $singular, $plural, $number) { |
|
| 517 | + return _npgettext($context, $singular, $plural, $number); |
|
| 518 | + } |
|
| 519 | + function dpgettext($domain, $context, $msgid) { |
|
| 520 | + return _dpgettext($domain, $context, $msgid); |
|
| 521 | + } |
|
| 522 | + function dnpgettext($domain, $context, $singular, $plural, $number) { |
|
| 523 | + return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 524 | + } |
|
| 525 | + function dcpgettext($domain, $context, $msgid, $category) { |
|
| 526 | + return _dcpgettext($domain, $context, $msgid, $category); |
|
| 527 | + } |
|
| 528 | + function dcnpgettext($domain, $context, $singular, $plural, |
|
| 529 | + $number, $category) { |
|
| 530 | + return _dcnpgettext($domain, $context, $singular, $plural, |
|
| 531 | + $number, $category); |
|
| 532 | + } |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | ?> |
@@ -26,22 +26,22 @@ discard block |
||
| 26 | 26 | class StreamReader { |
| 27 | 27 | // should return a string [FIXME: perhaps return array of bytes?] |
| 28 | 28 | function read($bytes) { |
| 29 | - return false; |
|
| 29 | + return false; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | // should return new position |
| 33 | 33 | function seekto($position) { |
| 34 | - return false; |
|
| 34 | + return false; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | // returns current position |
| 38 | 38 | function currentpos() { |
| 39 | - return false; |
|
| 39 | + return false; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // returns length of entire stream (limit for seekto()s) |
| 43 | 43 | function length() { |
| 44 | - return false; |
|
| 44 | + return false; |
|
| 45 | 45 | } |
| 46 | 46 | }; |
| 47 | 47 | |
@@ -50,32 +50,32 @@ discard block |
||
| 50 | 50 | var $_str; |
| 51 | 51 | |
| 52 | 52 | function StringReader($str='') { |
| 53 | - $this->_str = $str; |
|
| 54 | - $this->_pos = 0; |
|
| 53 | + $this->_str = $str; |
|
| 54 | + $this->_pos = 0; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | function read($bytes) { |
| 58 | - $data = substr($this->_str, $this->_pos, $bytes); |
|
| 59 | - $this->_pos += $bytes; |
|
| 60 | - if (strlen($this->_str)<$this->_pos) |
|
| 61 | - $this->_pos = strlen($this->_str); |
|
| 58 | + $data = substr($this->_str, $this->_pos, $bytes); |
|
| 59 | + $this->_pos += $bytes; |
|
| 60 | + if (strlen($this->_str)<$this->_pos) |
|
| 61 | + $this->_pos = strlen($this->_str); |
|
| 62 | 62 | |
| 63 | - return $data; |
|
| 63 | + return $data; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | function seekto($pos) { |
| 67 | - $this->_pos = $pos; |
|
| 68 | - if (strlen($this->_str)<$this->_pos) |
|
| 69 | - $this->_pos = strlen($this->_str); |
|
| 70 | - return $this->_pos; |
|
| 67 | + $this->_pos = $pos; |
|
| 68 | + if (strlen($this->_str)<$this->_pos) |
|
| 69 | + $this->_pos = strlen($this->_str); |
|
| 70 | + return $this->_pos; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | function currentpos() { |
| 74 | - return $this->_pos; |
|
| 74 | + return $this->_pos; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function length() { |
| 78 | - return strlen($this->_str); |
|
| 78 | + return strlen($this->_str); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | }; |
@@ -87,55 +87,55 @@ discard block |
||
| 87 | 87 | var $_length; |
| 88 | 88 | |
| 89 | 89 | function FileReader($filename) { |
| 90 | - if (file_exists($filename)) { |
|
| 90 | + if (file_exists($filename)) { |
|
| 91 | 91 | |
| 92 | - $this->_length=filesize($filename); |
|
| 93 | - $this->_pos = 0; |
|
| 94 | - $this->_fd = fopen($filename,'rb'); |
|
| 95 | - if (!$this->_fd) { |
|
| 96 | - $this->error = 3; // Cannot read file, probably permissions |
|
| 97 | - return false; |
|
| 98 | - } |
|
| 99 | - } else { |
|
| 100 | - $this->error = 2; // File doesn't exist |
|
| 101 | - return false; |
|
| 102 | - } |
|
| 92 | + $this->_length=filesize($filename); |
|
| 93 | + $this->_pos = 0; |
|
| 94 | + $this->_fd = fopen($filename,'rb'); |
|
| 95 | + if (!$this->_fd) { |
|
| 96 | + $this->error = 3; // Cannot read file, probably permissions |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 99 | + } else { |
|
| 100 | + $this->error = 2; // File doesn't exist |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | function read($bytes) { |
| 106 | - if ($bytes) { |
|
| 107 | - fseek($this->_fd, $this->_pos); |
|
| 106 | + if ($bytes) { |
|
| 107 | + fseek($this->_fd, $this->_pos); |
|
| 108 | 108 | |
| 109 | - // PHP 5.1.1 does not read more than 8192 bytes in one fread() |
|
| 110 | - // the discussions at PHP Bugs suggest it's the intended behaviour |
|
| 111 | - $data = ''; |
|
| 112 | - while ($bytes > 0) { |
|
| 113 | - $chunk = fread($this->_fd, $bytes); |
|
| 114 | - $data .= $chunk; |
|
| 115 | - $bytes -= strlen($chunk); |
|
| 116 | - } |
|
| 117 | - $this->_pos = ftell($this->_fd); |
|
| 109 | + // PHP 5.1.1 does not read more than 8192 bytes in one fread() |
|
| 110 | + // the discussions at PHP Bugs suggest it's the intended behaviour |
|
| 111 | + $data = ''; |
|
| 112 | + while ($bytes > 0) { |
|
| 113 | + $chunk = fread($this->_fd, $bytes); |
|
| 114 | + $data .= $chunk; |
|
| 115 | + $bytes -= strlen($chunk); |
|
| 116 | + } |
|
| 117 | + $this->_pos = ftell($this->_fd); |
|
| 118 | 118 | |
| 119 | - return $data; |
|
| 120 | - } else return ''; |
|
| 119 | + return $data; |
|
| 120 | + } else return ''; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | function seekto($pos) { |
| 124 | - fseek($this->_fd, $pos); |
|
| 125 | - $this->_pos = ftell($this->_fd); |
|
| 126 | - return $this->_pos; |
|
| 124 | + fseek($this->_fd, $pos); |
|
| 125 | + $this->_pos = ftell($this->_fd); |
|
| 126 | + return $this->_pos; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | function currentpos() { |
| 130 | - return $this->_pos; |
|
| 130 | + return $this->_pos; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | function length() { |
| 134 | - return $this->_length; |
|
| 134 | + return $this->_length; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | function close() { |
| 138 | - fclose($this->_fd); |
|
| 138 | + fclose($this->_fd); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | }; |
@@ -144,22 +144,22 @@ discard block |
||
| 144 | 144 | // over it (it assumes knowledge of StringReader internals) |
| 145 | 145 | class CachedFileReader extends StringReader { |
| 146 | 146 | function CachedFileReader($filename) { |
| 147 | - if (file_exists($filename)) { |
|
| 148 | - |
|
| 149 | - $length=filesize($filename); |
|
| 150 | - $fd = fopen($filename,'rb'); |
|
| 151 | - |
|
| 152 | - if (!$fd) { |
|
| 153 | - $this->error = 3; // Cannot read file, probably permissions |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - $this->_str = fread($fd, $length); |
|
| 157 | - fclose($fd); |
|
| 158 | - |
|
| 159 | - } else { |
|
| 160 | - $this->error = 2; // File doesn't exist |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 147 | + if (file_exists($filename)) { |
|
| 148 | + |
|
| 149 | + $length=filesize($filename); |
|
| 150 | + $fd = fopen($filename,'rb'); |
|
| 151 | + |
|
| 152 | + if (!$fd) { |
|
| 153 | + $this->error = 3; // Cannot read file, probably permissions |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + $this->_str = fread($fd, $length); |
|
| 157 | + fclose($fd); |
|
| 158 | + |
|
| 159 | + } else { |
|
| 160 | + $this->error = 2; // File doesn't exist |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | 163 | } |
| 164 | 164 | }; |
| 165 | 165 | |
@@ -61,19 +61,19 @@ discard block |
||
| 61 | 61 | * @return Integer from the Stream |
| 62 | 62 | */ |
| 63 | 63 | function readint() { |
| 64 | - if ($this->BYTEORDER == 0) { |
|
| 65 | - // low endian |
|
| 66 | - $input=unpack('V', $this->STREAM->read(4)); |
|
| 67 | - return array_shift($input); |
|
| 68 | - } else { |
|
| 69 | - // big endian |
|
| 70 | - $input=unpack('N', $this->STREAM->read(4)); |
|
| 71 | - return array_shift($input); |
|
| 72 | - } |
|
| 73 | - } |
|
| 64 | + if ($this->BYTEORDER == 0) { |
|
| 65 | + // low endian |
|
| 66 | + $input=unpack('V', $this->STREAM->read(4)); |
|
| 67 | + return array_shift($input); |
|
| 68 | + } else { |
|
| 69 | + // big endian |
|
| 70 | + $input=unpack('N', $this->STREAM->read(4)); |
|
| 71 | + return array_shift($input); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | function read($bytes) { |
| 76 | - return $this->STREAM->read($bytes); |
|
| 76 | + return $this->STREAM->read($bytes); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -83,13 +83,13 @@ discard block |
||
| 83 | 83 | * @return Array of Integers |
| 84 | 84 | */ |
| 85 | 85 | function readintarray($count) { |
| 86 | - if ($this->BYTEORDER == 0) { |
|
| 87 | - // low endian |
|
| 88 | - return unpack('V'.$count, $this->STREAM->read(4 * $count)); |
|
| 89 | - } else { |
|
| 90 | - // big endian |
|
| 91 | - return unpack('N'.$count, $this->STREAM->read(4 * $count)); |
|
| 92 | - } |
|
| 86 | + if ($this->BYTEORDER == 0) { |
|
| 87 | + // low endian |
|
| 88 | + return unpack('V'.$count, $this->STREAM->read(4 * $count)); |
|
| 89 | + } else { |
|
| 90 | + // big endian |
|
| 91 | + return unpack('N'.$count, $this->STREAM->read(4 * $count)); |
|
| 92 | + } |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,35 +99,35 @@ discard block |
||
| 99 | 99 | * @param boolean enable_cache Enable or disable caching of strings (default on) |
| 100 | 100 | */ |
| 101 | 101 | function __construct($Reader, $enable_cache = true) { |
| 102 | - // If there isn't a StreamReader, turn on short circuit mode. |
|
| 103 | - if (! $Reader || isset($Reader->error) ) { |
|
| 104 | - $this->short_circuit = true; |
|
| 105 | - return; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // Caching can be turned off |
|
| 109 | - $this->enable_cache = $enable_cache; |
|
| 110 | - |
|
| 111 | - $MAGIC1 = "\x95\x04\x12\xde"; |
|
| 112 | - $MAGIC2 = "\xde\x12\x04\x95"; |
|
| 113 | - |
|
| 114 | - $this->STREAM = $Reader; |
|
| 115 | - $magic = $this->read(4); |
|
| 116 | - if ($magic == $MAGIC1) { |
|
| 117 | - $this->BYTEORDER = 1; |
|
| 118 | - } elseif ($magic == $MAGIC2) { |
|
| 119 | - $this->BYTEORDER = 0; |
|
| 120 | - } else { |
|
| 121 | - $this->error = 1; // not MO file |
|
| 122 | - return false; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - // FIXME: Do we care about revision? We should. |
|
| 126 | - $revision = $this->readint(); |
|
| 127 | - |
|
| 128 | - $this->total = $this->readint(); |
|
| 129 | - $this->originals = $this->readint(); |
|
| 130 | - $this->translations = $this->readint(); |
|
| 102 | + // If there isn't a StreamReader, turn on short circuit mode. |
|
| 103 | + if (! $Reader || isset($Reader->error) ) { |
|
| 104 | + $this->short_circuit = true; |
|
| 105 | + return; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // Caching can be turned off |
|
| 109 | + $this->enable_cache = $enable_cache; |
|
| 110 | + |
|
| 111 | + $MAGIC1 = "\x95\x04\x12\xde"; |
|
| 112 | + $MAGIC2 = "\xde\x12\x04\x95"; |
|
| 113 | + |
|
| 114 | + $this->STREAM = $Reader; |
|
| 115 | + $magic = $this->read(4); |
|
| 116 | + if ($magic == $MAGIC1) { |
|
| 117 | + $this->BYTEORDER = 1; |
|
| 118 | + } elseif ($magic == $MAGIC2) { |
|
| 119 | + $this->BYTEORDER = 0; |
|
| 120 | + } else { |
|
| 121 | + $this->error = 1; // not MO file |
|
| 122 | + return false; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + // FIXME: Do we care about revision? We should. |
|
| 126 | + $revision = $this->readint(); |
|
| 127 | + |
|
| 128 | + $this->total = $this->readint(); |
|
| 129 | + $this->originals = $this->readint(); |
|
| 130 | + $this->translations = $this->readint(); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -138,32 +138,32 @@ discard block |
||
| 138 | 138 | * @access private |
| 139 | 139 | */ |
| 140 | 140 | function load_tables() { |
| 141 | - if (is_array($this->cache_translations) && |
|
| 142 | - is_array($this->table_originals) && |
|
| 143 | - is_array($this->table_translations)) |
|
| 144 | - return; |
|
| 145 | - |
|
| 146 | - /* get original and translations tables */ |
|
| 147 | - if (!is_array($this->table_originals)) { |
|
| 148 | - $this->STREAM->seekto($this->originals); |
|
| 149 | - $this->table_originals = $this->readintarray($this->total * 2); |
|
| 150 | - } |
|
| 151 | - if (!is_array($this->table_translations)) { |
|
| 152 | - $this->STREAM->seekto($this->translations); |
|
| 153 | - $this->table_translations = $this->readintarray($this->total * 2); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - if ($this->enable_cache) { |
|
| 157 | - $this->cache_translations = array (); |
|
| 158 | - /* read all strings in the cache */ |
|
| 159 | - for ($i = 0; $i < $this->total; $i++) { |
|
| 160 | - $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
|
| 161 | - $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); |
|
| 162 | - $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); |
|
| 163 | - $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); |
|
| 164 | - $this->cache_translations[$original] = $translation; |
|
| 165 | - } |
|
| 166 | - } |
|
| 141 | + if (is_array($this->cache_translations) && |
|
| 142 | + is_array($this->table_originals) && |
|
| 143 | + is_array($this->table_translations)) |
|
| 144 | + return; |
|
| 145 | + |
|
| 146 | + /* get original and translations tables */ |
|
| 147 | + if (!is_array($this->table_originals)) { |
|
| 148 | + $this->STREAM->seekto($this->originals); |
|
| 149 | + $this->table_originals = $this->readintarray($this->total * 2); |
|
| 150 | + } |
|
| 151 | + if (!is_array($this->table_translations)) { |
|
| 152 | + $this->STREAM->seekto($this->translations); |
|
| 153 | + $this->table_translations = $this->readintarray($this->total * 2); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + if ($this->enable_cache) { |
|
| 157 | + $this->cache_translations = array (); |
|
| 158 | + /* read all strings in the cache */ |
|
| 159 | + for ($i = 0; $i < $this->total; $i++) { |
|
| 160 | + $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
|
| 161 | + $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); |
|
| 162 | + $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); |
|
| 163 | + $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); |
|
| 164 | + $this->cache_translations[$original] = $translation; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -174,13 +174,13 @@ discard block |
||
| 174 | 174 | * @return string Requested string if found, otherwise '' |
| 175 | 175 | */ |
| 176 | 176 | function get_original_string($num) { |
| 177 | - $length = $this->table_originals[$num * 2 + 1]; |
|
| 178 | - $offset = $this->table_originals[$num * 2 + 2]; |
|
| 179 | - if (! $length) |
|
| 180 | - return ''; |
|
| 181 | - $this->STREAM->seekto($offset); |
|
| 182 | - $data = $this->STREAM->read($length); |
|
| 183 | - return (string)$data; |
|
| 177 | + $length = $this->table_originals[$num * 2 + 1]; |
|
| 178 | + $offset = $this->table_originals[$num * 2 + 2]; |
|
| 179 | + if (! $length) |
|
| 180 | + return ''; |
|
| 181 | + $this->STREAM->seekto($offset); |
|
| 182 | + $data = $this->STREAM->read($length); |
|
| 183 | + return (string)$data; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | * @return string Requested string if found, otherwise '' |
| 192 | 192 | */ |
| 193 | 193 | function get_translation_string($num) { |
| 194 | - $length = $this->table_translations[$num * 2 + 1]; |
|
| 195 | - $offset = $this->table_translations[$num * 2 + 2]; |
|
| 196 | - if (! $length) |
|
| 197 | - return ''; |
|
| 198 | - $this->STREAM->seekto($offset); |
|
| 199 | - $data = $this->STREAM->read($length); |
|
| 200 | - return (string)$data; |
|
| 194 | + $length = $this->table_translations[$num * 2 + 1]; |
|
| 195 | + $offset = $this->table_translations[$num * 2 + 2]; |
|
| 196 | + if (! $length) |
|
| 197 | + return ''; |
|
| 198 | + $this->STREAM->seekto($offset); |
|
| 199 | + $data = $this->STREAM->read($length); |
|
| 200 | + return (string)$data; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -210,35 +210,35 @@ discard block |
||
| 210 | 210 | * @return int string number (offset in originals table) |
| 211 | 211 | */ |
| 212 | 212 | function find_string($string, $start = -1, $end = -1) { |
| 213 | - if (($start == -1) or ($end == -1)) { |
|
| 214 | - // find_string is called with only one parameter, set start end end |
|
| 215 | - $start = 0; |
|
| 216 | - $end = $this->total; |
|
| 217 | - } |
|
| 218 | - if (abs($start - $end) <= 1) { |
|
| 219 | - // We're done, now we either found the string, or it doesn't exist |
|
| 220 | - $txt = $this->get_original_string($start); |
|
| 221 | - if ($string == $txt) |
|
| 222 | - return $start; |
|
| 223 | - else |
|
| 224 | - return -1; |
|
| 225 | - } else if ($start > $end) { |
|
| 226 | - // start > end -> turn around and start over |
|
| 227 | - return $this->find_string($string, $end, $start); |
|
| 228 | - } else { |
|
| 229 | - // Divide table in two parts |
|
| 230 | - $half = (int)(($start + $end) / 2); |
|
| 231 | - $cmp = strcmp($string, $this->get_original_string($half)); |
|
| 232 | - if ($cmp == 0) |
|
| 233 | - // string is exactly in the middle => return it |
|
| 234 | - return $half; |
|
| 235 | - else if ($cmp < 0) |
|
| 236 | - // The string is in the upper half |
|
| 237 | - return $this->find_string($string, $start, $half); |
|
| 238 | - else |
|
| 239 | - // The string is in the lower half |
|
| 240 | - return $this->find_string($string, $half, $end); |
|
| 241 | - } |
|
| 213 | + if (($start == -1) or ($end == -1)) { |
|
| 214 | + // find_string is called with only one parameter, set start end end |
|
| 215 | + $start = 0; |
|
| 216 | + $end = $this->total; |
|
| 217 | + } |
|
| 218 | + if (abs($start - $end) <= 1) { |
|
| 219 | + // We're done, now we either found the string, or it doesn't exist |
|
| 220 | + $txt = $this->get_original_string($start); |
|
| 221 | + if ($string == $txt) |
|
| 222 | + return $start; |
|
| 223 | + else |
|
| 224 | + return -1; |
|
| 225 | + } else if ($start > $end) { |
|
| 226 | + // start > end -> turn around and start over |
|
| 227 | + return $this->find_string($string, $end, $start); |
|
| 228 | + } else { |
|
| 229 | + // Divide table in two parts |
|
| 230 | + $half = (int)(($start + $end) / 2); |
|
| 231 | + $cmp = strcmp($string, $this->get_original_string($half)); |
|
| 232 | + if ($cmp == 0) |
|
| 233 | + // string is exactly in the middle => return it |
|
| 234 | + return $half; |
|
| 235 | + else if ($cmp < 0) |
|
| 236 | + // The string is in the upper half |
|
| 237 | + return $this->find_string($string, $start, $half); |
|
| 238 | + else |
|
| 239 | + // The string is in the lower half |
|
| 240 | + return $this->find_string($string, $half, $end); |
|
| 241 | + } |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -249,24 +249,24 @@ discard block |
||
| 249 | 249 | * @return string translated string (or original, if not found) |
| 250 | 250 | */ |
| 251 | 251 | function translate($string) { |
| 252 | - if ($this->short_circuit) |
|
| 253 | - return $string; |
|
| 254 | - $this->load_tables(); |
|
| 255 | - |
|
| 256 | - if ($this->enable_cache) { |
|
| 257 | - // Caching enabled, get translated string from cache |
|
| 258 | - if (array_key_exists($string, $this->cache_translations)) |
|
| 259 | - return $this->cache_translations[$string]; |
|
| 260 | - else |
|
| 261 | - return $string; |
|
| 262 | - } else { |
|
| 263 | - // Caching not enabled, try to find string |
|
| 264 | - $num = $this->find_string($string); |
|
| 265 | - if ($num == -1) |
|
| 266 | - return $string; |
|
| 267 | - else |
|
| 268 | - return $this->get_translation_string($num); |
|
| 269 | - } |
|
| 252 | + if ($this->short_circuit) |
|
| 253 | + return $string; |
|
| 254 | + $this->load_tables(); |
|
| 255 | + |
|
| 256 | + if ($this->enable_cache) { |
|
| 257 | + // Caching enabled, get translated string from cache |
|
| 258 | + if (array_key_exists($string, $this->cache_translations)) |
|
| 259 | + return $this->cache_translations[$string]; |
|
| 260 | + else |
|
| 261 | + return $string; |
|
| 262 | + } else { |
|
| 263 | + // Caching not enabled, try to find string |
|
| 264 | + $num = $this->find_string($string); |
|
| 265 | + if ($num == -1) |
|
| 266 | + return $string; |
|
| 267 | + else |
|
| 268 | + return $this->get_translation_string($num); |
|
| 269 | + } |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -276,32 +276,32 @@ discard block |
||
| 276 | 276 | * @return string sanitized plural form expression |
| 277 | 277 | */ |
| 278 | 278 | function sanitize_plural_expression($expr) { |
| 279 | - // Get rid of disallowed characters. |
|
| 280 | - $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr); |
|
| 281 | - |
|
| 282 | - // Add parenthesis for tertiary '?' operator. |
|
| 283 | - $expr .= ';'; |
|
| 284 | - $res = ''; |
|
| 285 | - $p = 0; |
|
| 286 | - for ($i = 0; $i < strlen($expr); $i++) { |
|
| 287 | - $ch = $expr[$i]; |
|
| 288 | - switch ($ch) { |
|
| 289 | - case '?': |
|
| 290 | - $res .= ' ? ('; |
|
| 291 | - $p++; |
|
| 292 | - break; |
|
| 293 | - case ':': |
|
| 294 | - $res .= ') : ('; |
|
| 295 | - break; |
|
| 296 | - case ';': |
|
| 297 | - $res .= str_repeat( ')', $p) . ';'; |
|
| 298 | - $p = 0; |
|
| 299 | - break; |
|
| 300 | - default: |
|
| 301 | - $res .= $ch; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - return $res; |
|
| 279 | + // Get rid of disallowed characters. |
|
| 280 | + $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr); |
|
| 281 | + |
|
| 282 | + // Add parenthesis for tertiary '?' operator. |
|
| 283 | + $expr .= ';'; |
|
| 284 | + $res = ''; |
|
| 285 | + $p = 0; |
|
| 286 | + for ($i = 0; $i < strlen($expr); $i++) { |
|
| 287 | + $ch = $expr[$i]; |
|
| 288 | + switch ($ch) { |
|
| 289 | + case '?': |
|
| 290 | + $res .= ' ? ('; |
|
| 291 | + $p++; |
|
| 292 | + break; |
|
| 293 | + case ':': |
|
| 294 | + $res .= ') : ('; |
|
| 295 | + break; |
|
| 296 | + case ';': |
|
| 297 | + $res .= str_repeat( ')', $p) . ';'; |
|
| 298 | + $p = 0; |
|
| 299 | + break; |
|
| 300 | + default: |
|
| 301 | + $res .= $ch; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + return $res; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -311,11 +311,11 @@ discard block |
||
| 311 | 311 | * @return string verbatim plural form header field |
| 312 | 312 | */ |
| 313 | 313 | function extract_plural_forms_header_from_po_header($header) { |
| 314 | - if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) |
|
| 315 | - $expr = $regs[2]; |
|
| 316 | - else |
|
| 317 | - $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
| 318 | - return $expr; |
|
| 314 | + if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) |
|
| 315 | + $expr = $regs[2]; |
|
| 316 | + else |
|
| 317 | + $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
| 318 | + return $expr; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
@@ -325,21 +325,21 @@ discard block |
||
| 325 | 325 | * @return string plural form header |
| 326 | 326 | */ |
| 327 | 327 | function get_plural_forms() { |
| 328 | - // lets assume message number 0 is header |
|
| 329 | - // this is true, right? |
|
| 330 | - $this->load_tables(); |
|
| 331 | - |
|
| 332 | - // cache header field for plural forms |
|
| 333 | - if (! is_string($this->pluralheader)) { |
|
| 334 | - if ($this->enable_cache) { |
|
| 335 | - $header = $this->cache_translations[""]; |
|
| 336 | - } else { |
|
| 337 | - $header = $this->get_translation_string(0); |
|
| 338 | - } |
|
| 339 | - $expr = $this->extract_plural_forms_header_from_po_header($header); |
|
| 340 | - $this->pluralheader = $this->sanitize_plural_expression($expr); |
|
| 341 | - } |
|
| 342 | - return $this->pluralheader; |
|
| 328 | + // lets assume message number 0 is header |
|
| 329 | + // this is true, right? |
|
| 330 | + $this->load_tables(); |
|
| 331 | + |
|
| 332 | + // cache header field for plural forms |
|
| 333 | + if (! is_string($this->pluralheader)) { |
|
| 334 | + if ($this->enable_cache) { |
|
| 335 | + $header = $this->cache_translations[""]; |
|
| 336 | + } else { |
|
| 337 | + $header = $this->get_translation_string(0); |
|
| 338 | + } |
|
| 339 | + $expr = $this->extract_plural_forms_header_from_po_header($header); |
|
| 340 | + $this->pluralheader = $this->sanitize_plural_expression($expr); |
|
| 341 | + } |
|
| 342 | + return $this->pluralheader; |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | /** |
@@ -350,21 +350,21 @@ discard block |
||
| 350 | 350 | * @return int array index of the right plural form |
| 351 | 351 | */ |
| 352 | 352 | function select_string($n) { |
| 353 | - if (!is_int($n)) { |
|
| 354 | - throw new InvalidArgumentException( |
|
| 355 | - "Select_string only accepts integers: " . $n); |
|
| 356 | - } |
|
| 357 | - $string = $this->get_plural_forms(); |
|
| 358 | - $string = str_replace('nplurals',"\$total",$string); |
|
| 359 | - $string = str_replace("n",$n,$string); |
|
| 360 | - $string = str_replace('plural',"\$plural",$string); |
|
| 361 | - |
|
| 362 | - $total = 0; |
|
| 363 | - $plural = 0; |
|
| 364 | - |
|
| 365 | - eval("$string"); |
|
| 366 | - if ($plural >= $total) $plural = $total - 1; |
|
| 367 | - return $plural; |
|
| 353 | + if (!is_int($n)) { |
|
| 354 | + throw new InvalidArgumentException( |
|
| 355 | + "Select_string only accepts integers: " . $n); |
|
| 356 | + } |
|
| 357 | + $string = $this->get_plural_forms(); |
|
| 358 | + $string = str_replace('nplurals',"\$total",$string); |
|
| 359 | + $string = str_replace("n",$n,$string); |
|
| 360 | + $string = str_replace('plural',"\$plural",$string); |
|
| 361 | + |
|
| 362 | + $total = 0; |
|
| 363 | + $plural = 0; |
|
| 364 | + |
|
| 365 | + eval("$string"); |
|
| 366 | + if ($plural >= $total) $plural = $total - 1; |
|
| 367 | + return $plural; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -377,58 +377,58 @@ discard block |
||
| 377 | 377 | * @return translated plural form |
| 378 | 378 | */ |
| 379 | 379 | function ngettext($single, $plural, $number) { |
| 380 | - if ($this->short_circuit) { |
|
| 381 | - if ($number != 1) |
|
| 382 | - return $plural; |
|
| 383 | - else |
|
| 384 | - return $single; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - // find out the appropriate form |
|
| 388 | - $select = $this->select_string($number); |
|
| 389 | - |
|
| 390 | - // this should contains all strings separated by NULLs |
|
| 391 | - $key = $single . chr(0) . $plural; |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - if ($this->enable_cache) { |
|
| 395 | - if (! array_key_exists($key, $this->cache_translations)) { |
|
| 396 | - return ($number != 1) ? $plural : $single; |
|
| 397 | - } else { |
|
| 398 | - $result = $this->cache_translations[$key]; |
|
| 399 | - $list = explode(chr(0), $result); |
|
| 400 | - return $list[$select]; |
|
| 401 | - } |
|
| 402 | - } else { |
|
| 403 | - $num = $this->find_string($key); |
|
| 404 | - if ($num == -1) { |
|
| 405 | - return ($number != 1) ? $plural : $single; |
|
| 406 | - } else { |
|
| 407 | - $result = $this->get_translation_string($num); |
|
| 408 | - $list = explode(chr(0), $result); |
|
| 409 | - return $list[$select]; |
|
| 410 | - } |
|
| 411 | - } |
|
| 380 | + if ($this->short_circuit) { |
|
| 381 | + if ($number != 1) |
|
| 382 | + return $plural; |
|
| 383 | + else |
|
| 384 | + return $single; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + // find out the appropriate form |
|
| 388 | + $select = $this->select_string($number); |
|
| 389 | + |
|
| 390 | + // this should contains all strings separated by NULLs |
|
| 391 | + $key = $single . chr(0) . $plural; |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + if ($this->enable_cache) { |
|
| 395 | + if (! array_key_exists($key, $this->cache_translations)) { |
|
| 396 | + return ($number != 1) ? $plural : $single; |
|
| 397 | + } else { |
|
| 398 | + $result = $this->cache_translations[$key]; |
|
| 399 | + $list = explode(chr(0), $result); |
|
| 400 | + return $list[$select]; |
|
| 401 | + } |
|
| 402 | + } else { |
|
| 403 | + $num = $this->find_string($key); |
|
| 404 | + if ($num == -1) { |
|
| 405 | + return ($number != 1) ? $plural : $single; |
|
| 406 | + } else { |
|
| 407 | + $result = $this->get_translation_string($num); |
|
| 408 | + $list = explode(chr(0), $result); |
|
| 409 | + return $list[$select]; |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | function pgettext($context, $msgid) { |
| 415 | - $key = $context . chr(4) . $msgid; |
|
| 416 | - $ret = $this->translate($key); |
|
| 417 | - if (strpos($ret, "\004") !== FALSE) { |
|
| 418 | - return $msgid; |
|
| 419 | - } else { |
|
| 420 | - return $ret; |
|
| 421 | - } |
|
| 415 | + $key = $context . chr(4) . $msgid; |
|
| 416 | + $ret = $this->translate($key); |
|
| 417 | + if (strpos($ret, "\004") !== FALSE) { |
|
| 418 | + return $msgid; |
|
| 419 | + } else { |
|
| 420 | + return $ret; |
|
| 421 | + } |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | function npgettext($context, $singular, $plural, $number) { |
| 425 | - $key = $context . chr(4) . $singular; |
|
| 426 | - $ret = $this->ngettext($key, $plural, $number); |
|
| 427 | - if (strpos($ret, "\004") !== FALSE) { |
|
| 428 | - return $singular; |
|
| 429 | - } else { |
|
| 430 | - return $ret; |
|
| 431 | - } |
|
| 425 | + $key = $context . chr(4) . $singular; |
|
| 426 | + $ret = $this->ngettext($key, $plural, $number); |
|
| 427 | + if (strpos($ret, "\004") !== FALSE) { |
|
| 428 | + return $singular; |
|
| 429 | + } else { |
|
| 430 | + return $ret; |
|
| 431 | + } |
|
| 432 | 432 | |
| 433 | 433 | } |
| 434 | 434 | } |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | <?php |
| 94 | 94 | foreach (PluginHost::getInstance()->get_plugins() as $n => $p) { |
| 95 | 95 | if (method_exists($p, "get_js")) { |
| 96 | - $script = $p->get_js(); |
|
| 96 | + $script = $p->get_js(); |
|
| 97 | 97 | |
| 98 | - if ($script) { |
|
| 98 | + if ($script) { |
|
| 99 | 99 | echo "try { |
| 100 | 100 | $script |
| 101 | 101 | } catch (e) { |
@@ -146,10 +146,10 @@ discard block |
||
| 146 | 146 | <img src='images/indicator_tiny.gif'/> |
| 147 | 147 | <?php echo __("Loading, please wait..."); ?></div> |
| 148 | 148 | <?php |
| 149 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_TREE) as $p) { |
|
| 150 | - echo $p->hook_feed_tree(); |
|
| 151 | - } |
|
| 152 | - ?> |
|
| 149 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_TREE) as $p) { |
|
| 150 | + echo $p->hook_feed_tree(); |
|
| 151 | + } |
|
| 152 | + ?> |
|
| 153 | 153 | <div id="feedTree"></div> |
| 154 | 154 | </div> |
| 155 | 155 | |
@@ -167,10 +167,10 @@ discard block |
||
| 167 | 167 | title="<?php echo __('Updates are available from Git.') ?>">new_releases</i> |
| 168 | 168 | |
| 169 | 169 | <?php |
| 170 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_MAIN_TOOLBAR_BUTTON) as $p) { |
|
| 171 | - echo $p->hook_main_toolbar_button(); |
|
| 172 | - } |
|
| 173 | - ?> |
|
| 170 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_MAIN_TOOLBAR_BUTTON) as $p) { |
|
| 171 | + echo $p->hook_main_toolbar_button(); |
|
| 172 | + } |
|
| 173 | + ?> |
|
| 174 | 174 | |
| 175 | 175 | <form id="toolbar-headlines" action="" style="order : 10" onsubmit='return false'> |
| 176 | 176 | |
@@ -220,10 +220,10 @@ discard block |
||
| 220 | 220 | <div class="action-chooser" style="order : 30"> |
| 221 | 221 | |
| 222 | 222 | <?php |
| 223 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_TOOLBAR_BUTTON) as $p) { |
|
| 224 | - echo $p->hook_toolbar_button(); |
|
| 225 | - } |
|
| 226 | - ?> |
|
| 223 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_TOOLBAR_BUTTON) as $p) { |
|
| 224 | + echo $p->hook_toolbar_button(); |
|
| 225 | + } |
|
| 226 | + ?> |
|
| 227 | 227 | |
| 228 | 228 | <div dojoType="fox.form.DropDownButton" class="action-button" title="<?php echo __('Actions...') ?>"> |
| 229 | 229 | <span><i class="material-icons">menu</i></span> |
@@ -242,10 +242,10 @@ discard block |
||
| 242 | 242 | <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcHKhelp')"><?php echo __('Keyboard shortcuts help') ?></div> |
| 243 | 243 | |
| 244 | 244 | <?php |
| 245 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ACTION_ITEM) as $p) { |
|
| 246 | - echo $p->hook_action_item(); |
|
| 247 | - } |
|
| 248 | - ?> |
|
| 245 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ACTION_ITEM) as $p) { |
|
| 246 | + echo $p->hook_action_item(); |
|
| 247 | + } |
|
| 248 | + ?> |
|
| 249 | 249 | |
| 250 | 250 | <?php if (!$_SESSION["hide_logout"]) { ?> |
| 251 | 251 | <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcLogout')"><?php echo __('Logout') ?></div> |