public function uploadLanguage($dyn_uid) { if (!isset($_FILES["LANGUAGE"])) { throw new Exception(G::LoadTranslation("ID_ERROR_UPLOADING_FILENAME")); } if (pathinfo($_FILES["LANGUAGE"]["name"], PATHINFO_EXTENSION) != "po") { throw new Exception(G::LoadTranslation("ID_FILE_UPLOAD_INCORRECT_EXTENSION")); } $translation = array(); G::LoadSystem('i18n_po'); $i18n = new i18n_PO($_FILES["LANGUAGE"]["tmp_name"]); $i18n->readInit(); while ($rowTranslation = $i18n->getTranslation()) { array_push($translation, $rowTranslation); } $name = $_FILES["LANGUAGE"]["name"]; $name = explode(".", $name); if (isset($name[1]) && isset($name[2]) && $name[1] . "." . $name[2] === "en.po") { return; } $content = $i18n->getHeaders(); $content["File-Name"] = $_FILES["LANGUAGE"]["name"]; $content["Labels"] = $translation; $con = Propel::getConnection(DynaformPeer::DATABASE_NAME); $con->begin(); $oPro = DynaformPeer::retrieveByPk($dyn_uid); $dyn_labels = new stdClass(); if ($oPro->getDynLabel() !== null && $oPro->getDynLabel() !== "") { $dyn_labels = G::json_decode($oPro->getDynLabel()); } $dyn_labels->$name[count($name) - 2] = $content; $oPro->setDynLabel(G::json_encode($dyn_labels)); $oPro->save(); $con->commit(); }
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; } }
function getInfoFromPOFile($file) { G::loadClass('i18n_po'); $POFile = new i18n_PO($file); $POFile->readInit(); $POHeaders = $POFile->getHeaders(); if ($POHeaders['X-Poedit-Country'] != '.') { $country = self::getTranslationMetaByCountryName($POHeaders['X-Poedit-Country']); } else { $country = '.'; } $language = self::getTranslationMetaByLanguageName($POHeaders['X-Poedit-Language']); if ($language !== false) { if ($country !== false) { if ($country != '.') { $LOCALE = $language['LAN_ID'] . '-' . $country['IC_UID']; } else { if ($country == '.') { //this a trsnlation file with a language international, no country name was set $LOCALE = $language['LAN_ID']; } else { throw new Exception('PO File Error: "' . $file . '" has a invalid country definition!'); } } } else { throw new Exception('PO File Error: "' . $file . '" has a invalid country definition!'); } } else { throw new Exception('PO File Error: "' . $file . '" has a invalid language definition!'); } $countItems = 0; try { while ($rowTranslation = $POFile->getTranslation()) { $countItems++; } } catch (Exception $e) { $countItems = '-'; } return array('LOCALE' => $LOCALE, 'HEADERS' => $POHeaders, 'COUNT' => $countItems); }
public function import($sLanguageFile, $updateXml = true, $updateDB = true) { try { G::LoadSystem('i18n_po'); $POFile = new i18n_PO($sLanguageFile); $POFile->readInit(); $POHeaders = $POFile->getHeaders(); /*getting the PO Language definition*/ $langName = $POHeaders['X-Poedit-Language']; //find the lang id $language = new Language(); $langRecord = $language->findByLanName($langName); if (!isset($langRecord['LAN_ID'])) { //if the language doesn't exist abort throw new Exception('The .po file has a invalid X-Poedit-Language definition!'); } $languageID = $langRecord['LAN_ID']; /*getting the PO Language definition*/ $countryName = $POHeaders['X-Poedit-Country']; if ($countryName != '.') { $isoCountry = new IsoCountry(); $countryRecord = $isoCountry->findByIcName($countryName); if (!isset($countryRecord['IC_UID'])) { //if the language doesn't exist abort throw new Exception('The .po file has a invalid X-Poedit-Country definition!'); } $countryID = $countryRecord['IC_UID']; //define locale $LOCALE = "{$languageID}-{$countryID}"; } else { $LOCALE = $languageID; } $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) { $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 (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]; // it is a Sql insert on TRANSLATIONS TAble if ($identifier == 'TRANSLATION') { if ($updateDB) { list($category, $id) = explode('/', $context); $result = $oTranslation->addTranslation($category, $id, $LOCALE, trim(stripcslashes(str_replace(chr(10), '', $rowTranslation['msgstr'])))); if ($result['codError'] == 0) { $countItemsSuccess++; } else { $errorMsg .= $id . ': ' . $result['message'] . "\n"; } } } else { if ($updateXml) { $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_XMLFORM . $xmlForm)) { $errorMsg .= 'file doesn\'t exist: ' . PATH_XMLFORM . $xmlForm . "\n"; continue; } if (count($match) < 4) { $near = isset($rowTranslation['msgid']) ? $rowTranslation['msgid'] : (isset($rowTranslation['msgstr']) ? $rowTranslation['msgstr'] : ''); $errorMsg .= "Invalid Translation reference: \"{$reference}\", near -> " . $near . "\n"; continue; } G::LoadSystem('dynaformhandler'); $dynaform = new dynaFormHandler(PATH_XMLFORM . $xmlForm); $fieldName = $match[2]; $codes = explode('-', $reference); if (sizeof($codes) == 2) { //is a normal node $dynaform->addChilds($fieldName, array($LOCALE => stripcslashes(str_replace(chr(10), '', $rowTranslation['msgstr'])))); } else { if (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($LOCALE => NULL), $childNode); } } $countItemsSuccess++; } } } $oLanguage = new Language(); $oLanguage->update(array('LAN_ID' => $languageID, 'LAN_ENABLED' => '1')); $trn = new Translation(); $trn->generateFileTranslation($LOCALE); $trn->addTranslationEnvironment($LOCALE, $POHeaders, $countItemsSuccess); $content = new Content(); $content->regenerateContent($languageID); //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; } }