Esempio n. 1
0
 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']));
         }
     }
 }
Esempio n. 2
0
 public function loadPoFile($fileName)
 {
     $parser = new POParser();
     try {
         $this->translationArray = $parser->parse($fileName);
         $this->loadTranslationArray();
     } catch (Exception $e) {
         $this->translationArray = array();
     }
 }
Esempio n. 3
0
 /**
  * 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();
 }
Esempio n. 4
0
<?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']);