Ejemplo n.º 1
0
 /**
  * Function LoadTranslationPlugins
  * It generates a global Translation variable for plugins
  *
  * Per script
  *
  * @author Brayan Pereyra <cochalo>. <*****@*****.**>
  * @access public
  * @param  string lang
  * @param  array list plugins active
  * @return void
  */
 public function LoadTranslationPlugins($lang = SYS_LANG, $listPluginsActive)
 {
     if (!is_array($listPluginsActive)) {
         return null;
     }
     foreach ($listPluginsActive['_aPluginDetails'] as $key => $value) {
         $namePlugin = trim($key);
         $translation = array();
         if (!file_exists(PATH_LANGUAGECONT . $namePlugin . '.en')) {
             Translation::generateFileTranslationPlugin($namePlugin, 'en');
         }
         if ($lang != 'en' && !file_exists(PATH_LANGUAGECONT . $namePlugin . '.' . $lang)) {
             Translation::generateFileTranslationPlugin($namePlugin, $lang);
         }
         if (file_exists(PATH_LANGUAGECONT . $namePlugin . '.' . $lang)) {
             eval('global $translation' . $namePlugin . ';');
             require_once PATH_LANGUAGECONT . $namePlugin . '.' . $lang;
         } else {
             if (file_exists(PATH_LANGUAGECONT . $namePlugin . '.en')) {
                 eval('global $translation' . $namePlugin . ';');
                 require_once PATH_LANGUAGECONT . $namePlugin . '.en';
             }
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 public function updateLanguagePlugin($plugin, $idLanguage)
 {
     if (!file_exists(PATH_PLUGINS . $plugin)) {
         throw new Exception('The plugin ' . $plugin . ' not exist');
         die;
     }
     if (!file_exists(PATH_PLUGINS . $plugin . PATH_SEP . 'translations' . PATH_SEP . 'translations.php')) {
         throw new Exception('Translations.php not exist in plugin ' . $plugin);
     }
     if (!file_exists(PATH_PLUGINS . $plugin . PATH_SEP . 'translations' . PATH_SEP . $plugin . '.' . $idLanguage . '.po')) {
         throw new Exception('The file ' . $plugin . '.' . $idLanguage . '.po not exists');
         die;
     }
     $languageFile = PATH_PLUGINS . $plugin . PATH_SEP . 'translations' . PATH_SEP . $plugin . '.' . $idLanguage . '.po';
     try {
         G::LoadSystem('i18n_po');
         $POFile = new i18n_PO($languageFile);
         $POFile->readInit();
         $POHeaders = $POFile->getHeaders();
         $oTranslation = new Translation();
         $countItems = 0;
         $countItemsSuccess = 0;
         $errorMsg = '';
         while ($rowTranslation = $POFile->getTranslation()) {
             $countItems++;
             if (!isset($POFile->translatorComments[0]) || !isset($POFile->translatorComments[1]) || !isset($POFile->references[0])) {
                 throw new Exception('The .po file doesn\'t have valid directives for Processmaker!');
             }
             foreach ($POFile->translatorComments as $a => $aux) {
                 $identifier = '';
                 $context = '';
                 $aux = trim($aux);
                 if ($aux == 'TRANSLATION') {
                     $identifier = $aux;
                 } else {
                     $var = explode('/', $aux);
                     if ($var[0] == 'LABEL') {
                         $context = $aux;
                     }
                     if ($var[0] == 'JAVASCRIPT') {
                         $context = $aux;
                     }
                 }
                 if ($identifier == '' && $context == '') {
                     $context = $aux;
                 }
                 if (preg_match('/^([\\w-]+)\\/([\\w-]+\\/*[\\w-]*\\.xml\\?)/', $aux, $match)) {
                     $identifier = $aux;
                 } else {
                     if (preg_match('/^([\\w-]+)\\/([\\w-]+\\/*[\\w-]*\\.xml$)/', $aux, $match)) {
                         $context = $aux;
                     }
                 }
             }
             $reference = $POFile->references[0];
             if ($identifier != 'TRANSLATION') {
                 $xmlForm = $context;
                 //erik: expresion to prevent and hable correctly dropdown values like -1, -2 etc.
                 preg_match('/^([\\w_]+)\\s-\\s([\\w_]+)\\s*-*\\s*([\\w\\W]*)$/', $reference, $match);
                 if (!file_exists(PATH_PLUGINS . $plugin . PATH_SEP . $xmlForm)) {
                     $errorMsg .= 'file doesn\'t exist: ' . PATH_PLUGINS . $plugin . $xmlForm . "\n";
                     continue;
                 }
                 if (count($match) < 4) {
                     $near = isset($rowTranslation['msgid']) ? $rowTranslation['msgid'] : (isset($rowTranslation['msgstr']) ? $rowTranslation['msgstr'] : '');
                     $errorMsg .= "Invalid Translation reference: \"{$reference}\",  near -> " . strip_tags($near) . "\n";
                     continue;
                 }
                 G::LoadSystem('dynaformhandler');
                 $dynaform = new dynaFormHandler(PATH_PLUGINS . $plugin . PATH_SEP . $xmlForm);
                 $fieldName = $match[2];
                 $codes = explode('-', $reference);
                 if (sizeof($codes) == 2) {
                     //is a normal node
                     $dynaform->addChilds($fieldName, array($idLanguage => stripcslashes(str_replace(chr(10), '', $rowTranslation['msgstr']))));
                 } elseif (sizeof($codes) > 2) {
                     //is a node child for a language node
                     $name = $match[3] == "''" ? '' : $match[3];
                     $childNode = array(array('name' => 'option', 'value' => $rowTranslation['msgstr'], 'attributes' => array('name' => $name)));
                     $dynaform->addChilds($fieldName, array($idLanguage => null), $childNode);
                 }
                 $countItemsSuccess++;
             }
         }
         $trn = new Translation();
         $trn->generateFileTranslationPlugin($plugin, $idLanguage);
         $trn->addTranslationEnvironmentPlugins($plugin, $idLanguage, $POHeaders, $countItemsSuccess);
         $languageID = isset($languageID) ? $languageID : $idLanguage;
         //fill the results
         $results = new stdClass();
         $results->recordsCount = $countItems;
         $results->recordsCountSuccess = $countItemsSuccess;
         $results->lang = $languageID;
         $results->headers = $POHeaders;
         $results->errMsg = $errorMsg;
         return $results;
     } catch (Exception $oError) {
         throw $oError;
     }
 }