| 322 |
} |
} |
| 323 |
} |
} |
| 324 |
|
|
| 325 |
|
|
| 326 |
class PHPGettextAdmin |
class PHPGettextAdmin |
| 327 |
{ |
{ |
| 328 |
var $has_gettext = false; |
var $has_gettext = false; |
| 329 |
var $gettext_path = ''; |
var $gettext_path = ''; |
| 330 |
|
var $debug = false; |
| 331 |
|
|
| 332 |
function PHPGettextAdmin() |
function PHPGettextAdmin($debug = false) |
| 333 |
{ |
{ |
| 334 |
if (ini_get('open_basedir') || ini_get('safe_mode')) { |
if (ini_get('open_basedir') || ini_get('safe_mode')) { |
| 335 |
return $this->has_gettext = false; |
$this->has_gettext = false; |
| 336 |
|
return false; |
| 337 |
} |
} |
| 338 |
$cmd = 'which gettext'; |
$cmd = 'which gettext'; |
| 339 |
if (substr(strtoupper(PHP_OS), 0, 3) == 'WIN'){ |
if (substr(strtoupper(PHP_OS), 0, 3) == 'WIN'){ |
| 347 |
$this->gettext_path = $path; |
$this->gettext_path = $path; |
| 348 |
} |
} |
| 349 |
} |
} |
| 350 |
|
if ($debug) { |
| 351 |
|
$this->debug = $debug; |
| 352 |
|
} |
| 353 |
} |
} |
| 354 |
|
|
| 355 |
/** |
/** |
| 358 |
* @param unknown_type $domain |
* @param unknown_type $domain |
| 359 |
* @param unknown_type $langdir |
* @param unknown_type $langdir |
| 360 |
*/ |
*/ |
| 361 |
function message_format ($domain, $textdomain, $lang, $enc='utf-8') { |
function message_format ($domain, $textdomain, $lang, $enc='utf-8') |
| 362 |
|
{ |
| 363 |
|
$path = "$textdomain/$lang"; |
| 364 |
if ($this->has_gettext) { |
if ($this->has_gettext) { |
| 365 |
$cmd = "msgfmt -o $textdomain/$lang/LC_MESSAGES/$domain.mo $textdomain/$lang/$domain.po"; |
$cmd = "msgfmt -o $path/LC_MESSAGES/$domain.mo $path/$domain.po"; |
| 366 |
return $this->execute($cmd); |
return $this->execute($cmd); |
| 367 |
} |
} |
| 368 |
if ($this->has_gettext) { |
$catalog = new PHPGettext_catalog($domain, $textdomain); |
|
} |
|
|
$catalog = new PHPGettext_catalog($arr['domain'], $textdomain); |
|
| 369 |
$catalog->setproperty('mode', _MODE_PO_); |
$catalog->setproperty('mode', _MODE_PO_); |
| 370 |
$catalog->setproperty('lang', $lang); |
$catalog->setproperty('lang', $lang); |
| 371 |
$catalog->load(); |
$catalog->load(); |
| 379 |
* @param unknown_type $domain |
* @param unknown_type $domain |
| 380 |
* @param unknown_type $langdir |
* @param unknown_type $langdir |
| 381 |
*/ |
*/ |
| 382 |
function compile ($domain, $textdomain, $lang, $enc='utf-8') { |
function compile($lang, $textdomain, $enc='utf-8') { |
| 383 |
|
|
| 384 |
if ($this->has_gettext) { |
if ($this->has_gettext) { |
| 385 |
$cmd = "msgfmt -o $textdomain/$lang/LC_MESSAGES/$lang.mo". $textdomain.'/glossary/'.$lang.'_'.$enc.'.po'; |
$cmd = "msgfmt -o $textdomain/$lang/LC_MESSAGES/$lang.mo $textdomain/$lang/$lang.po"; |
| 386 |
return $this->execute($cmd); |
return $this->execute($cmd); |
| 387 |
} |
} |
| 388 |
|
$catalog = new PHPGettext_catalog($lang, $textdomain); |
|
$catalog = new PHPGettext_catalog($lang.$enc, $textdomain); |
|
| 389 |
$catalog->setproperty('mode', _MODE_PO_); |
$catalog->setproperty('mode', _MODE_PO_); |
| 390 |
$catalog->setproperty('lang', 'untranslated'); |
$catalog->setproperty('lang', $lang); |
| 391 |
$catalog->load(); |
$catalog->load(); |
| 392 |
$catalog->setproperty('mode', _MODE_MO_); |
$catalog->setproperty('mode', _MODE_MO_); |
| 393 |
$catalog->save(); |
$catalog->save(); |
| 394 |
return true; |
return true; |
| 395 |
} |
} |
| 396 |
|
|
| 397 |
/** |
/** |
| 398 |
* Enter description here... |
* Enter description here... |
| 399 |
* |
* |
| 400 |
* @param unknown_type $domain |
* @param unknown_type $domain |
| 401 |
* @param unknown_type $langdir |
* @param unknown_type $langdir |
| 402 |
*/ |
*/ |
| 403 |
function add_to_dict($domain, $textdomain, $lang, $enc='utf-8') { |
function initialize_translation ($domain, $textdomain, $lang, $enc='utf-8') |
| 404 |
|
{ |
| 405 |
if (!$this->has_gettext) return false; |
if (!$this->has_gettext) { |
| 406 |
|
return false; |
|
if (!is_dir("$textdomain/glossary/")) { |
|
|
mkdir("$textdomain/glossary/"); |
|
| 407 |
} |
} |
| 408 |
if (!file_exists($textdomain.'/glossary/'.$lang.'_'.$enc.'.po')) { |
set_time_limit(120); |
| 409 |
set_time_limit(360); |
$path = "$textdomain/$lang"; |
| 410 |
$create_dict = true; |
copy("$textdomain/untranslated/$domain.pot", "$path/ref.po"); |
| 411 |
$cmd = 'msgcat --use-first -o '.$textdomain.'/glossary/'.$lang.'_'.$enc.'.po '.$textdomain.'/'.$lang.'/'.$domain.'.po'; |
$cmd = "msgmerge --width=80 --compendium $textdomain/glossary/$lang.$enc.po -o $path/$domain.po $path/ref.po $textdomain/untranslated/$domain.pot"; |
|
$this->execute($cmd); |
|
|
} else { |
|
|
copy($textdomain.'/glossary/'.$lang.'_'.$enc.'.po', $textdomain.'/glossary/'.$lang.'_'.$enc.'.pot'); |
|
|
$cmd = 'msgcat --use-first -o '.$textdomain.'/glossary/'.$lang.'_'.$enc.'.po ' |
|
|
.$textdomain.'/glossary/'.$lang.'_'.$enc.'.po ' |
|
|
.$textdomain.'/'.$lang.'/'.$domain.'.po ' |
|
|
.$textdomain.'/untranslated/'.$domain.'.pot'; |
|
| 412 |
$this->execute($cmd); |
$this->execute($cmd); |
| 413 |
unlink($textdomain.'/glossary/'.$lang.'_'.$enc.'.pot'); |
unlink("$textdomain/$lang/ref.po"); |
|
} |
|
| 414 |
} |
} |
| 415 |
/** |
/** |
| 416 |
* Enter description here... |
* Enter description here... |
| 418 |
* @param unknown_type $domain |
* @param unknown_type $domain |
| 419 |
* @param unknown_type $langdir |
* @param unknown_type $langdir |
| 420 |
*/ |
*/ |
| 421 |
function auto_translate($domain, $textdomain, $lang, $enc='utf-8') |
function update_translation($domain, $textdomain, $lang, $enc='utf-8') |
| 422 |
{ |
{ |
| 423 |
copy("$textdomain/$lang/$domain.po", "$textdomain/$lang/$domain.pot"); |
$path = "$textdomain/$lang"; |
| 424 |
$cmd = "msgcat --use-first -o $textdomain/$lang/update.po $textdomain/$lang/$domain.po $textdomain/$lang/$lang.po"; |
if (!file_exists("$path/$domain.po")) { |
| 425 |
|
copy($textdomain."/untranslated/$domain.pot", "$path/$domain.po"); |
| 426 |
|
} |
| 427 |
|
copy("$path/$domain.po", "$path/$domain.pot"); |
| 428 |
|
$cmd = "msgcat --use-first -o $path/update.po $path/$domain.po $textdomain/glossary/$lang.$enc.po"; |
| 429 |
$this->execute($cmd); |
$this->execute($cmd); |
| 430 |
$cmd = "msgmerge --width=80 --compendium $textdomain/$lang/$lang.po -o $textdomain/$lang/$domain.po $textdomain/$lang/update.po $textdomain/$lang/$domain.pot"; |
$cmd = "msgmerge --width=80 --compendium $textdomain/glossary/$lang.$enc.po -o $textdomain/$lang/$domain.po $textdomain/$lang/update.po $textdomain/untranslated/$domain.pot"; |
| 431 |
$this->execute($cmd); |
$this->execute($cmd); |
| 432 |
unlink("$textdomain/$lang/update.po"); |
unlink("$textdomain/$lang/update.po"); |
| 433 |
unlink("$textdomain/$lang/$domain.pot"); |
unlink("$textdomain/$lang/$domain.pot"); |
| 438 |
* @param unknown_type $domain |
* @param unknown_type $domain |
| 439 |
* @param unknown_type $langdir |
* @param unknown_type $langdir |
| 440 |
*/ |
*/ |
| 441 |
function convert_encoding($domain, $textdomain, $lang, $from_charset, $to_charset) { |
function add_to_dict($domain, $textdomain, $lang, $enc='utf-8') { |
| 442 |
|
|
| 443 |
|
if (!$this->has_gettext) return false; |
| 444 |
|
|
| 445 |
|
$textdomain = rtrim($textdomain, '\/'); |
| 446 |
|
$path = "$textdomain/$lang"; |
| 447 |
|
if (!is_dir("$textdomain/glossary/")) { |
| 448 |
|
mkdir("$textdomain/glossary/"); |
| 449 |
|
} |
| 450 |
|
if (!file_exists("$textdomain/glossary/$lang.$enc.po")) { |
| 451 |
|
set_time_limit(360); |
| 452 |
|
$create_dict = true; |
| 453 |
|
$cmd = "msgcat --use-first -o $textdomain/glossary/$lang.$enc.po $path/$domain.po"; |
| 454 |
|
$this->execute($cmd); |
| 455 |
|
} else { |
| 456 |
|
copy("$textdomain/glossary/$lang.$enc.po", "$textdomain/glossary/$lang.$enc.pot"); |
| 457 |
|
$cmd = "msgcat --use-first -o $textdomain/glossary/$lang.$enc.po $textdomain/$lang/$domain.po $textdomain/glossary/$lang.$enc.po"; |
| 458 |
|
$this->execute($cmd); |
| 459 |
|
unlink("$textdomain/glossary/$lang.$enc.pot"); |
| 460 |
|
} |
| 461 |
|
} |
| 462 |
|
/** |
| 463 |
|
* Enter description here... |
| 464 |
|
* |
| 465 |
|
* @param unknown_type $domain |
| 466 |
|
* @param unknown_type $langdir |
| 467 |
|
*/ |
| 468 |
|
function convert_charset($domain, $textdomain, $lang, $from_charset, $to_charset) { |
| 469 |
|
|
| 470 |
$path = $textdomain.'/'.$lang; |
$path = "$textdomain/$lang"; |
| 471 |
if ($this->has_gettext) { |
if ($this->has_gettext) { |
| 472 |
$cmd = "msgconv --to-code=$to_charset -o $path/$domain.po $path/$domain.po"; |
$cmd = "msgconv --to-code=$to_charset -o $path/$domain.po $path/$domain.po"; |
| 473 |
$ret = $this->execute($cmd); |
$ret = $this->execute($cmd); |
| 478 |
return false; |
return false; |
| 479 |
} |
} |
| 480 |
|
|
| 481 |
$catalog = new PHPGettext_catalog($arr['domain'], $textdomain); |
$catalog = new PHPGettext_catalog($domain, $textdomain); |
| 482 |
$catalog->setproperty('mode', _MODE_PO_); |
$catalog->setproperty('mode', _MODE_PO_); |
| 483 |
$catalog->setproperty('lang', $lang); |
$catalog->setproperty('lang', $lang); |
| 484 |
$catalog->load(); |
$catalog->load(); |
| 494 |
|
|
| 495 |
|
|
| 496 |
/** |
/** |
|
* Enter description here... |
|
|
* |
|
|
* @param unknown_type $domain |
|
|
* @param unknown_type $langdir |
|
|
*/ |
|
|
function msgmerge ($args) { |
|
|
$cmd = "msgmerge "; |
|
|
return $this->execute($cmd.$args); |
|
|
} |
|
|
|
|
|
/** |
|
| 497 |
* Invoke the xgettext utility with $args |
* Invoke the xgettext utility with $args |
| 498 |
* the xgettext executable must be in PATH |
* the xgettext executable must be in PATH |
| 499 |
* |
* |
| 500 |
* @param string the commandline arguments to gettext |
* @param string the commandline arguments to gettext |
| 501 |
* @return unknown |
* @return unknown |
| 502 |
*/ |
*/ |
| 503 |
function xgettext($args) { |
function xgettext($domain, $textdomain, $php_sources, $lang='untranslated') { |
| 504 |
|
|
| 505 |
$cmd = "xgettext "; |
$cmd = "xgettext "; |
| 506 |
return $this->execute($cmd.$args); |
if (file_exists("$textdomain/$lang/$domain.pot")) $cmd .= '-j '; |
| 507 |
|
$cmd .= "-n -c --sort-by-file --keyword=T_ --keyword=Tn_:1,2 --keyword=Td_:2 --keyword=Tdn_:2,3 --output-dir=$textdomain/$lang -o $domain.pot"; |
| 508 |
|
if (count($php_sources) > 10) { |
| 509 |
|
$tmpfile = $textdomain.'/xgettext.txt'; |
| 510 |
|
$fp = fopen($tmpfile, "w"); |
| 511 |
|
fwrite($fp, implode("\r\n", $php_sources)); |
| 512 |
|
fclose($fp); |
| 513 |
|
$cmd = $cmd." --files-from=$tmpfile"; |
| 514 |
|
} else { |
| 515 |
|
$cmd = $cmd." ".implode(" ", $php_sources); |
| 516 |
|
} |
| 517 |
|
$ret = $this->execute($cmd); |
| 518 |
|
@unlink($tmpfile); |
| 519 |
|
return $ret; |
| 520 |
} |
} |
| 521 |
|
|
| 522 |
|
|
| 528 |
*/ |
*/ |
| 529 |
function execute($cmd) { |
function execute($cmd) { |
| 530 |
|
|
| 531 |
if (!$this) return false; |
if (!$this || !$this->has_gettext) return false; |
| 532 |
|
#$cmd = $this->gettext_path.DIRECTORY_SEPARATOR.escapeshellcmd($cmd); |
| 533 |
$cmd = escapeshellcmd($cmd); |
$cmd = escapeshellcmd($cmd); |
| 534 |
$return = 0; |
$return = 0; |
| 535 |
if (substr(strtoupper(PHP_OS), 0, 3) == 'WIN'){ |
if (substr(strtoupper(PHP_OS), 0, 3) == 'WIN'){ |
| 536 |
$fp = fopen("execute.bat", 'w+'); |
$fp = fopen("execute.bat", 'w+'); |
| 537 |
fwrite($fp, "@echo on\r\n $cmd"); |
fwrite($fp, "@echo on\r\n $cmd"); |
| 538 |
fclose($fp); |
fclose($fp); |
| 539 |
exec("execute.bat", $output, $return); |
exec("execute.bat", $output, $retval); |
| 540 |
unlink("execute.bat"); |
unlink("execute.bat"); |
| 541 |
} else { |
} else { |
| 542 |
$lastline = exec($cmd, $output, $return); |
$lastline = exec($cmd, $output, $retval); |
| 543 |
|
} |
| 544 |
|
if ($this->debug || $retval > 0) { |
| 545 |
|
$trace = debug_backtrace(); |
| 546 |
|
$msg = "<div style=\"border: thin solid silver; text-align:left;margin-left:10px\">"; |
| 547 |
|
$msg .= "<p><span style=\"font-weight:bold\">PHPGettextAdmin->execute('</span><i>$cmd</i><span style=\"font-weight:bold\">')</span><br/>in ".str_replace($_SERVER['DOCUMENT_ROOT'], '', $trace[1]['file']).":{$trace[1]['line']}</p>"; |
| 548 |
|
$msg .= "<p><i><b>trace:</b></i></p><ul>"; |
| 549 |
|
for ($a=1; $a < 3; $a++) { |
| 550 |
|
$called = isset($trace[$a]['class']) ? $trace[$a]['class'] : ''; |
| 551 |
|
$called .= $trace[$a]['type'].$trace[$a]['function']."(".@implode(', ',$trace[$a]['args']).")"; |
| 552 |
|
$msg .= "<li>$called in ".str_replace($_SERVER['DOCUMENT_ROOT'], '', $trace[$a]['file'])." : {$trace[$a]['line']}</li>"; |
| 553 |
|
} |
| 554 |
|
$msg .= "</ul>"; |
| 555 |
|
$msg .= "<p><i><b>return value:</b></i> $retval</p>"; |
| 556 |
|
$msg .= "<p><i><b>output:</b></i> </p><pre>{$output[1]}</pre>"; |
| 557 |
|
$msg .= "</div>"; |
| 558 |
|
echo $msg; |
| 559 |
} |
} |
|
#if ($return) |
|
|
dump(array($cmd, $output, $return)); |
|
| 560 |
return $output; |
return $output; |
| 561 |
} |
} |
| 562 |
} |
} |