| 16 |
/** |
/** |
| 17 |
* The current locale. eg: en-GB |
* The current locale. eg: en-GB |
| 18 |
*/ |
*/ |
| 19 |
|
var $lang; |
| 20 |
|
/** |
| 21 |
|
* The current locale. eg: en-GB |
| 22 |
|
*/ |
| 23 |
var $locale; |
var $locale; |
| 24 |
|
|
| 25 |
/** |
/** |
| 38 |
var $text_domains = array(); |
var $text_domains = array(); |
| 39 |
|
|
| 40 |
/** |
/** |
| 41 |
|
* The asssociative array of headers for the current domain |
| 42 |
|
*/ |
| 43 |
|
var $headers = array(); |
| 44 |
|
/** |
| 45 |
* The asssociative array of messages for the current domain |
* The asssociative array of messages for the current domain |
| 46 |
*/ |
*/ |
| 47 |
var $messages = array(); |
var $messages = array(); |
| 67 |
* @return unknown |
* @return unknown |
| 68 |
*/ |
*/ |
| 69 |
|
|
| 70 |
function setlocale($lang) { |
function setlocale($lang, $locale) { |
| 71 |
#dump(setlocale(LC_ALL, 0)); |
#dump(setlocale(LC_ALL, 0)); |
|
$this->locale = $lang; |
|
| 72 |
putenv("LANGUAGE=$lang"); |
putenv("LANGUAGE=$lang"); |
| 73 |
putenv("LC_ALL=$lang"); |
putenv("LC_ALL=$lang"); |
| 74 |
putenv("LC_MESSAGE=$lang"); |
putenv("LC_MESSAGE=$lang"); |
| 77 |
$_ENV['LC_ALL'] = $lang; |
$_ENV['LC_ALL'] = $lang; |
| 78 |
$_ENV['LC_MESSAGE'] = $lang; |
$_ENV['LC_MESSAGE'] = $lang; |
| 79 |
$_ENV['LANG'] = $lang;*/ |
$_ENV['LANG'] = $lang;*/ |
| 80 |
setlocale(LC_ALL, ''); |
$this->lang = $lang; |
| 81 |
return $this->locale; |
$this->locale = setlocale(LC_ALL, $locale); |
| 82 |
|
setlocale(LC_ALL, $locale); |
| 83 |
} |
} |
| 84 |
|
|
| 85 |
function getlocale() { |
function getlocale() { |
| 111 |
$str = sprintf($html, ($untranslated ? 'red' : 'green'), str_replace('\\', '/', $trace[2]['file']), $trace[2]['line'], $message); |
$str = sprintf($html, ($untranslated ? 'red' : 'green'), str_replace('\\', '/', $trace[2]['file']), $trace[2]['line'], $message); |
| 112 |
break; |
break; |
| 113 |
case 1: |
case 1: |
| 114 |
$str = sprintf('T_(%s)%s',$message, $untranslated ? ';' : ''); |
$str = sprintf('%sT_(%s)',$untranslated ? '!' : '', $message); |
| 115 |
break; |
break; |
| 116 |
case 0: |
case 0: |
| 117 |
default: |
default: |
| 157 |
function dgettext($domain, $message){ |
function dgettext($domain, $message){ |
| 158 |
$translation = $message; |
$translation = $message; |
| 159 |
if (array_key_exists($domain, $this->messages)){ |
if (array_key_exists($domain, $this->messages)){ |
| 160 |
|
if (isset($this->messages[$domain][$message])) |
| 161 |
$translation = $this->messages[$domain][$message]; |
$translation = $this->messages[$domain][$message]; |
| 162 |
} |
} |
| 163 |
$untranslated = (strcmp($translation, $message) === 0) ? true : false; |
$untranslated = (strcmp($translation, $message) === 0) ? true : false; |
| 165 |
} |
} |
| 166 |
|
|
| 167 |
/** |
/** |
| 168 |
* Plural version of gettext * |
* Plural version of gettext |
|
* not yet implemented |
|
| 169 |
*/ |
*/ |
| 170 |
function ngettext($msg1, $msg2, $count){ |
function ngettext($msgid, $msgid_plural, $count){ |
|
$translation = $msg1; |
|
| 171 |
if ($this->has_gettext){ |
if ($this->has_gettext){ |
| 172 |
$translation = ngettext($msg1, $msg2, $count); |
$translation = ngettext($msgid, $msgid_plural, $count); |
| 173 |
} |
} |
| 174 |
if (isset( $this->messages[$this->domain][$msg1])) { |
$plural = $this->getplural($count, $this->domain); |
| 175 |
$translation = $this->messages[$this->domain][$msg1]; |
if (isset($this->messages[$this->domain][$msgid][$plural])) { |
| 176 |
return $translation; |
$translation = $this->messages[$this->domain][$msgid][$plural]; |
| 177 |
|
} else { |
| 178 |
|
$original = array($msgid, $msgid_plural); |
| 179 |
|
$translation = $original[$plural]; |
| 180 |
} |
} |
| 181 |
$untranslated = (strcmp($translation, $msg1) === 0) ? true : false; |
$untranslated = (strcmp($translation, $original[$plural]) === 0) ? true : false; |
| 182 |
return $this->output($translation, $untranslated); |
return $this->output($translation, $untranslated); |
| 183 |
} |
} |
| 184 |
/** |
/** |
| 185 |
* Plural version of dgettext . |
* Plural version of dgettext |
|
* not yet implemented |
|
| 186 |
*/ |
*/ |
| 187 |
function dngettext($domain, $msg1, $msg2, $count){ |
function dngettext($domain, $msgid, $msgid_plural, $count){ |
| 188 |
return $msg1; |
$original = array($msgid, $msgid_plural); |
| 189 |
|
$plural = $this->getplural($count, $domain); |
| 190 |
|
if ($this->has_gettext){ |
| 191 |
|
$translation = dngettext($domain, $msgid, $msgid_plural, $count); |
| 192 |
|
} else { |
| 193 |
|
if (isset($this->messages[$domain][$msgid][$plural])) { |
| 194 |
|
$translation = $this->messages[$domain][$msgid][$plural]; |
| 195 |
|
} else { |
| 196 |
|
$translation = $original[$plural]; |
| 197 |
|
} |
| 198 |
|
} |
| 199 |
|
$untranslated = (strcmp($translation, $original[$plural]) === 0) ? true : false; |
| 200 |
|
return $this->output($translation, $untranslated); |
| 201 |
} |
} |
| 202 |
|
|
| 203 |
/** |
/** |
| 231 |
*/ |
*/ |
| 232 |
function textdomain($domain = null){ |
function textdomain($domain = null){ |
| 233 |
if ($this->has_gettext){ |
if ($this->has_gettext){ |
| 234 |
textdomain($domain); |
$domain = textdomain($domain); |
| 235 |
} |
} |
| 236 |
if (is_null($domain)) |
elseif (!is_null($domain)) { |
| 237 |
return $this->domain; |
$this->domain = $domain; |
| 238 |
else |
$this->load($domain, $this->text_domains[$this->domain]['path']); |
|
return $this->domain = $domain; |
|
| 239 |
} |
} |
| 240 |
|
return $this->domain; |
|
function load($domain, $path) { |
|
|
require_once('phpgettext.catalog.php'); |
|
|
$catalog = new PHPGettext_catalog($domain, $path); |
|
|
$catalog->setproperty('mode', _MODE_MO_); |
|
|
$catalog->setproperty('lang', $this->getlocale()); |
|
|
$catalog->load(); |
|
|
foreach ($catalog->strings as $string) |
|
|
$this->messages[$domain][$string->msgid] = $string->msgstr; |
|
| 241 |
} |
} |
| 242 |
|
|
| 243 |
/** |
/** |
| 244 |
* Overrides the domain for a single lookup string |
* Overrides the domain for a single lookup |
| 245 |
* This function allows you to override the current domain for a single message lookup. |
* This function allows you to override the current domain for a single message lookup. |
| 246 |
* It also allows you to specify a category. |
* It also allows you to specify a category. |
| 247 |
* Categories are folders within the languages directory . |
* Categories are folders within the languages directory . |
| 263 |
} |
} |
| 264 |
|
|
| 265 |
/** |
/** |
| 266 |
* Plural version of dcgettext |
* dcngettext -- Plural version of dcgettext |
| 267 |
* not yet implemented |
* not yet implemented |
| 268 |
*/ |
*/ |
| 269 |
function dcngettext($domain, $msg1, $msg2, $count, $category){ |
function dcngettext($domain, $msg1, $msg2, $count, $category){ |
| 271 |
} |
} |
| 272 |
|
|
| 273 |
|
|
| 274 |
|
/** |
| 275 |
|
* Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1; |
| 276 |
|
* |
| 277 |
|
* nplurals - total number of plurals |
| 278 |
|
* plural - the plural index |
| 279 |
|
* |
| 280 |
|
* Plural-Forms: nplurals=1; plural=0; |
| 281 |
|
* 1 form only |
| 282 |
|
* |
| 283 |
|
* Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1; |
| 284 |
|
* Plural-Forms: nplurals=2; plural=n != 1; |
| 285 |
|
* 2 forms, singular used for one only |
| 286 |
|
* |
| 287 |
|
* Plural-Forms: nplurals=2; plural=n>1; |
| 288 |
|
* 2 forms, singular used for zero and one |
| 289 |
|
* |
| 290 |
|
* Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2; |
| 291 |
|
* 3 forms, special case for zero |
| 292 |
|
* |
| 293 |
|
* Plural-Forms: nplurals=3; plural=n==1 ? 0 : n==2 ? 1 : 2; |
| 294 |
|
* 3 forms, special cases for one and two |
| 295 |
|
* |
| 296 |
|
* Plural-Forms: nplurals=4; plural=n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3; |
| 297 |
|
* 4 forms, special case for one and all numbers ending in 02, 03, or 04 |
| 298 |
|
*/ |
| 299 |
|
function getplural($count, $domain) { |
| 300 |
|
if (isset($this->headers[$domain]['Plural-Forms'])) { |
| 301 |
|
$plural_forms = $this->headers[$domain]['Plural-Forms']; |
| 302 |
|
preg_match('/nplurals[\s]*[=]{1}[\s]*([\d]+);[\s]*plural[\s]*[=]{1}[\s]*(.*);$/', $plural_forms, $matches); |
| 303 |
|
$nplurals = $matches[1]; |
| 304 |
|
$plural_exp = $matches[2]; |
| 305 |
|
if ($nplurals > 1 && strpos($plural_exp, ':') === false) { |
| 306 |
|
$plural = 'return ('.preg_replace('/n/', $count, $plural_exp).') ? 1 : 0;'; |
| 307 |
|
} else { |
| 308 |
|
$plural = 'return '.preg_replace('/n/', $count, $plural_exp); |
| 309 |
|
} |
| 310 |
|
} else { |
| 311 |
|
$plural = 'return '.preg_replace('/n/', $count, 'n != 1 ? 1 : 0;'); |
| 312 |
|
} |
| 313 |
|
return eval($plural); |
| 314 |
|
} |
| 315 |
|
|
| 316 |
|
function load($domain, $path) { |
| 317 |
|
require_once('phpgettext.catalog.php'); |
| 318 |
|
$catalog = new PHPGettext_catalog($domain, $path); |
| 319 |
|
$catalog->setproperty('mode', _MODE_MO_); |
| 320 |
|
$catalog->setproperty('lang', $this->lang); |
| 321 |
|
$catalog->load(); |
| 322 |
|
$this->headers[$domain] = $catalog->headers; |
| 323 |
|
foreach ($catalog->strings as $string) |
| 324 |
|
$this->messages[$domain][$string->msgid] = $string->msgstr; |
| 325 |
|
} |
| 326 |
} |
} |
| 327 |
|
|
| 328 |
class PHPGettextAdmin |
class PHPGettextAdmin |
| 348 |
* @param unknown_type $domain |
* @param unknown_type $domain |
| 349 |
* @param unknown_type $langdir |
* @param unknown_type $langdir |
| 350 |
*/ |
*/ |
| 351 |
function msgmerge ($outdated, $recent, $langdir) { |
function msgmerge ($args) { |
|
#msgmerge $langdir/$old.po $new.po |
|
| 352 |
$cmd = "msgmerge"; |
$cmd = "msgmerge"; |
| 353 |
$arg = "$langdir/$outdated $recent"; |
return $this->execute($cmd.$args); |
|
//$exec = 'msgmerge --help'; |
|
|
return $this->execute($cmd, $arg); |
|
| 354 |
} |
} |
| 355 |
|
|
| 356 |
/** |
/** |
| 361 |
* @return unknown |
* @return unknown |
| 362 |
*/ |
*/ |
| 363 |
function xgettext($args) { |
function xgettext($args) { |
| 364 |
$cmd = substr(strtoupper(PHP_OS), 0, 3) == 'WIN' ? "xgettext.exe " : "xgettext "; |
$cmd = "xgettext "; |
| 365 |
return $this->execute($cmd.$args); |
return $this->execute($cmd.$args); |
| 366 |
} |
} |
| 367 |
|
|
| 377 |
$return = false; |
$return = false; |
| 378 |
if (substr(strtoupper(PHP_OS), 0, 3) == 'WIN'){ |
if (substr(strtoupper(PHP_OS), 0, 3) == 'WIN'){ |
| 379 |
$outputfile = session_save_path() . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true)) . ".txt"; |
$outputfile = session_save_path() . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true)) . ".txt"; |
| 380 |
$shell = new COM("WScript.Shell"); |
$fp = fopen("execute.bat", 'w+'); |
| 381 |
$shell->Run("cmd /C $cmd > $outputfile", 0, true); |
fwrite($fp, "@echo on\r\n $cmd"); |
| 382 |
$return = file_get_contents($outputfile); |
fclose($fp); |
| 383 |
unlink($outputfile); |
exec("execute.bat", $output, $return); |
| 384 |
|
unlink("execute.bat"); |
| 385 |
} else { |
} else { |
| 386 |
$cmd = "$cmd"; |
$cmd = "$cmd"; |
| 387 |
$lastline = exec($cmd, $output, $return); |
$lastline = exec($cmd, $output, $return); |
| 390 |
} |
} |
| 391 |
} |
} |
| 392 |
|
|
|
|
|
|
|
|
|
|
|
| 393 |
/** |
/** |
| 394 |
* Enter description here... |
* Enter description here... |
| 395 |
* |
* |
| 408 |
} |
} |
| 409 |
return $gettext; |
return $gettext; |
| 410 |
} |
} |
|
|
|
| 411 |
function T_($message) { |
function T_($message) { |
| 412 |
$gettext =& phpgettext(); |
$gettext =& phpgettext(); |
| 413 |
$trans = $gettext->gettext($message); |
$trans = $gettext->gettext($message); |
| 414 |
return $trans; |
return $trans; |
| 415 |
} |
} |
|
|
|
| 416 |
function Tn_($msg1, $msg2, $count) { |
function Tn_($msg1, $msg2, $count) { |
| 417 |
$gettext =& phpgettext(); |
$gettext =& phpgettext(); |
| 418 |
return $gettext->ngettext($msg1, $msg2, $count); |
return $gettext->ngettext($msg1, $msg2, $count); |
| 425 |
$gettext =& phpgettext(); |
$gettext =& phpgettext(); |
| 426 |
return $gettext->dngettext($domain, $msg1, $msg2, $count); |
return $gettext->dngettext($domain, $msg1, $msg2, $count); |
| 427 |
} |
} |
|
|
|
| 428 |
?> |
?> |