public static function init($cacheFile, $isDebug = false) { if (is_file($cacheFile) && $isDebug == false) { $content = file_get_contents($cacheFile); $GLOBALS['SETTINGS']['LANG'] = unserialize($content); } else { $pp = new POParser(); $GLOBALS['SETTINGS']['LANG'] = array(); foreach ($GLOBALS['SETTINGS']['LOCALE_PATHS'] as $langFile) { //dosya yoksa devam et if (!is_file($langFile)) { continue; } $res = $pp->parse($langFile); foreach ($res[1] as $entry) { if (isset($entry['msgid'])) { $GLOBALS['SETTINGS']['LANG'][self::encode_lang_key($entry['msgid'])] = $entry; } } } if (is_writable($cacheFile)) { file_put_contents($cacheFile, serialize($GLOBALS['SETTINGS']['LANG'])); } } }
function main($argc, $argv) { $this->stderrh = fopen('php://stderr', 'w'); $this->parseArguments($argc, $argv); $MsgStore = new DBPoMsgStore(); if ($this->doInstall) { $this->install($this->force); exit(0); } if ($this->catalogue_name) { $MsgStore->init($this->catalogue_name); } if ($this->infile) { if (!$this->catalogue_name) { die("Please provide a catalogue name\n"); } $POParser = new POParser($MsgStore); $POParser->parseEntriesFromStream(fopen($this->infile, 'r')); if ($this->clean) { $POParser->cleanDatabase(fopen($this->infile, 'r')); } $this->echo_stderr(sprintf("%s parsed and saved\n", $this->infile)); exit(0); } if ($this->outfile) { if (!$this->catalogue_name) { die("Please provide a catalogue name\n"); } $POParser = new POParser($MsgStore); $POParser->writePoFileToStream(fopen($this->outfile, 'w')); $this->echo_stderr("{$this->outfile} successfully written\n\n"); exit(0); } $this->usage(); }
public function loadPoFile($fileName) { $parser = new POParser(); try { $this->translationArray = $parser->parse($fileName); $this->loadTranslationArray(); } catch (Exception $e) { $this->translationArray = array(); } }
/** * Generate a php file from the php */ public function po2php() { $options = $_GET; // Get languages if (isset($options['lang'])) { if (is_dir(APPPATH . 'i18n/po/po-' . $options['lang'])) { $languages = array($options['lang']); } else { die('Language "' . $options['lang'] . '" not present'); } } else { $i18ndir = dir(APPPATH . 'i18n/po/'); $languages = array(); while (false !== ($entry = $i18ndir->read())) { if ($entry == '.' or $entry == '..' or substr($entry, 0, 3) != 'po-' or substr($entry, 0, 1) == '.') { continue; } if (is_dir(APPPATH . 'i18n/po/' . $entry)) { $languages[] = str_replace('po-', '', $entry); } } } $parser = new POParser(); // foreach ($languages as $language) { if (strtolower($language) == strtolower($this->source_language)) { continue; } // Get language files $files = array(); if (isset($options['group'])) { $path = APPPATH . "i18n/po/po-{$language}/{$options['group']}.po"; if (file_exists($path)) { $files[] = $path; } } else { $i18ndir = dir(APPPATH . 'i18n/po/po-' . $language); while (false !== ($entry = $i18ndir->read())) { if ($entry == '.' or $entry == '..') { continue; } if (substr($entry, -3, 3) == '.po') { $files[] = APPPATH . 'i18n/po/po-' . $language . '/' . $entry; } } } // Get source translations foreach ($files as $path) { $group = pathinfo($path, PATHINFO_FILENAME); list($header, $entries) = $parser->parse($path); $lang = $this->__build_lang_array($entries, $group); $content = new View('i18n/lang_file'); $content->header = $header; $content->lang = $lang; $content->language = $language; $content->group = $group; //echo $content; $this->__write_php_file($language, $group, $content); echo sprintf("Generate php lang file for %s : %s\n", $language, $group); } } $this->after(); }
<?php /** * Utility script that converts a PO file to PHP array i18n files * @copyright Copyright (c) 2014-2016 Benjamin BALET * @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0 * @link https://github.com/bbalet/jorani * @since 0.3.0 */ require "POParser.php"; $target = "vietnamese"; $copyright = "<?php\n/**\n * Translation file\n * @copyright Copyright (c) 2014-2016 Benjamin BALET\n * @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0\n * @link https://github.com/bbalet/jorani\n * @since 0.4.5\n * @author See list on Transifex https://www.transifex.com/jorani/\n */\n\n"; //Load and parse the PO file $parser = new POParser(); $messages = $parser->parse($target . '.po'); $lenPO = count($messages[1]); //Scan all translation files $files = scandir($target); foreach ($files as $file) { if (strpos($file, 'php') !== false) { $path = join_paths($target, $file); $ci18n = file_get_contents($path); //Analyse CI i18n files containing the translations (key/value) //$lang['calendar_individual_title'] = 'My calendar'; $pattern = "\$lang\\['(.*)'\\] = '(.*)';\$"; $out = array(); preg_match_all($pattern, $ci18n, $out, PREG_PATTERN_ORDER); $lenI18N = count($out[0]); for ($jj = 0; $jj < $lenI18N; $jj++) { for ($ii = 0; $ii < $lenPO; $ii++) { $po2ci = str_replace('\\"', '"', $messages[1][$ii]['msgid']);
"a \\" quote" msgstr "" #: standard input:116 input:1115 input:1205 #: input:1838 input:1868 #~ msgid "Password" #~ "xxx" #~ msgstr "Mot de passe:" #~ "xxx" FILE; StringStreamController::createRef('reference', $easy_file); $fh = fopen('string://reference', 'r'); $store = new TempPoMsgStore(); $t = new Tester(); $parser = new POParser($store); $parser->parseEntriesFromStream($fh); $objects = $store->read(); $t->assertTrue($objects[1]); $t->assertTrue($objects[0]); $t->assertFalse($objects[10]); $t->assertTrue($objects[0]['msgid']); $t->assertTrue($objects[0]['msgstr']); $t->assertFalse($objects[0]['should_not_exist']); $t->assertEquals($objects[0]['msgid'], 'Password'); $t->assertEquals($objects[0]['msgstr'], 'Mot de passe:'); $t->assertEquals($objects[1]['msgid'], "Hard idfoo bar\na \" quote"); $t->assertEquals($objects[2]['msgid'], 'Passwordxxx'); $t->assertEquals($objects[2]['msgstr'], 'Mot de passe:xxx'); $t->assertTrue($objects[2]['is_obsolete']); $t1 = "dog";