<?php { } function _p($string) { } function _r($string) { } class Babel { const className = 'Babel'; const classVersion = '1.0.0'; const classRelase = 1140634709; const classVendor = 'Vertis'; const classVendorURL = 'www.vertis.com.pl'; var $errno = 0; var $errstr = null; var $error = false; var $mo_dir = 'i18n'; private $translations_size = 0; private $mo_file = null; private $mo_position = 0; private $mo_length = 0; private $mo_order = 'V'; private $mo_info = null; public function mo($filename) { $this->errno = 0; $this->error = false; $this->mo_position = 0; $path = $this->mo_dir.DIRECTORY_SEPARATOR.$filename; { $this->_err(1, "class5.Babel : File $path not found"); return false; } { $this->_err(2, "class5.Babel : File $path is not readable"); return false; } if ($this->_fix_endian()) { $this->_translate(); return true; } $this->_err(3, "class5.Babel : $path is not *.mo file"); return false; } public function translate($string) { if ($this->translations_size == 0) { return $string; } { return $this->translations[$string]; } else { return $string; } } private function _translate() { $count = $this->mo_info[2] * 2; $this->_seek($this->mo_info[3]); $this->_seek($this->mo_info[4]); for ($i = 0; $i < $this->mo_info[2]; $i++) { $j = $i*2 + 1; $this->_seek($this->mo_originals[$j+1]); $original = $this->_read($this->mo_originals[$j]); $this->_seek($this->mo_translated[$j+1]); $translation = $this->_read($this->mo_translated[$j]); $this->translations[$original] = $translation; } } private function _fix_endian() { $val01 = (int)-569244523; $val02 = (int)-1794895138; if ($unpacked[1] == $val01) { $this->mo_order = 'N'; return true; } if ($unpacked[1] == $val02) { $this->mo_order = 'V'; return true; } return false; } private function _read($bytes) { $this->mo_position += $bytes; if ($this->mo_length < $this->mo_position) { $this->mo_position = $this->mo_length; } return $data; } private function _seek($pos) { $this->mo_position = $pos; if ($this->mo_length < $this->mo_position) { $this->mo_position = $this->mo_length; } return $this->mo_position; } private function _err($errno, $errstr) { $this->errno = $errno; $this->errstr = $errstr; if (BABEL_DEBUG == 1) { } } public function __construct() { { 'relase' => self::classRelase, 'vendor' => self::classVendor, 'vendorURL' => self::classVendorURL, 'copies' => 1); } else { $_inited_modules[self::className]['copies']++; } } } ?>
Klasa PHP5
<?php require_once('libs/class5.babel.php'); $lang = new Babel; $lang -> mo_dir = 'i18n'; $lang -> mo('pl.mo'); // $lang -> mo('pl2.mo'); mozna dolaczyc nastepny _p('Welcome on EclipseX'); ?>
Przyklad zastosowania
Kod
Witamy w EclipseX
Witamy w EclipseX
Please login
Witamy w EclipseX
Please login
Wynik
Pliki mo/po : http://www.vertis.com.pl/i18n/
Klasa do pobrania : http://www.vertis.com.pl/
-------- added
aha, w sposob banalny mozna wygenerowac plik *.mo z pliku php, uzywamy w skrypcie _r() i _p() potem :
xgettext -L php php.php -o lang.po --keyword=_p --keyword=_r
i wuala
