2010-12-02 23:34:41 +00:00
|
|
|
<?php
|
2017-08-14 16:13:46 -04:00
|
|
|
|
|
|
|
|
use ProcessMaker\Core\System;
|
|
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
class Language extends BaseLanguage
|
|
|
|
|
{
|
2015-04-22 17:01:34 -04:00
|
|
|
private static $arrayRecord = array();
|
|
|
|
|
|
2013-03-13 12:34:23 -04:00
|
|
|
private $exceptionFields = array ('','javascript','hidden','phpvariable','private','toolbar','xmlmenu','toolbutton','cellmark','grid','CheckboxTable');
|
2012-10-19 10:24:29 -04:00
|
|
|
|
2012-10-20 16:52:15 -04:00
|
|
|
public function load ($sLanUid)
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$oRow = LanguagePeer::retrieveByPK( $sLanUid );
|
|
|
|
|
if (! is_null( $oRow )) {
|
|
|
|
|
$aFields = $oRow->toArray( BasePeer::TYPE_FIELDNAME );
|
|
|
|
|
$this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
|
|
|
|
|
$this->setNew( false );
|
|
|
|
|
return $aFields;
|
|
|
|
|
} else {
|
|
|
|
|
throw (new Exception( 'This row doesn\'t exist!' ));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
throw ($oError);
|
2011-05-09 15:50:31 -04:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-20 16:52:15 -04:00
|
|
|
public function update ($aFields)
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
$oConnection = Propel::getConnection( LanguagePeer::DATABASE_NAME );
|
|
|
|
|
try {
|
|
|
|
|
$oConnection->begin();
|
|
|
|
|
$this->load( $aFields['LAN_ID'] );
|
|
|
|
|
$this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
|
|
|
|
|
if ($this->validate()) {
|
|
|
|
|
$iResult = $this->save();
|
|
|
|
|
$oConnection->commit();
|
|
|
|
|
return $iResult;
|
2011-05-09 15:50:31 -04:00
|
|
|
} else {
|
2012-10-19 10:24:29 -04:00
|
|
|
$oConnection->rollback();
|
|
|
|
|
throw (new Exception( 'Failed Validation in class ' . get_class( $this ) . '.' ));
|
2011-05-09 15:50:31 -04:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$oConnection->rollback();
|
|
|
|
|
throw ($e);
|
2012-08-21 16:06:22 -04:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
2012-10-20 16:52:15 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
//SELECT LAN_ID, LAN_NAME FROM LANGUAGE WHERE LAN_ENABLED = '1' ORDER BY LAN_WEIGHT DESC
|
2012-10-20 16:52:15 -04:00
|
|
|
public function getActiveLanguages ()
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
$oCriteria = new Criteria( 'workflow' );
|
|
|
|
|
$oCriteria->addSelectColumn( LanguagePeer::LAN_ID );
|
|
|
|
|
$oCriteria->addSelectColumn( LanguagePeer::LAN_NAME );
|
|
|
|
|
$oCriteria->add( LanguagePeer::LAN_ENABLED, '1' );
|
|
|
|
|
$oCriteria->addDescendingOrderByColumn( LanguagePeer::LAN_WEIGHT );
|
|
|
|
|
|
|
|
|
|
$oDataset = ContentPeer::doSelectRS( $oCriteria );
|
|
|
|
|
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
|
|
|
|
|
|
|
|
|
$oContent = new Content();
|
|
|
|
|
$rows = Array ();
|
|
|
|
|
while ($oDataset->next()) {
|
|
|
|
|
array_push( $rows, $oDataset->getRow() );
|
2011-05-09 15:50:31 -04:00
|
|
|
}
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
return $rows;
|
|
|
|
|
}
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-20 16:52:15 -04:00
|
|
|
public function findById ($LAN_ID)
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
2013-01-23 12:34:42 -04:00
|
|
|
if (strpos($LAN_ID, '_') !== false) {
|
2016-03-17 16:25:09 -04:00
|
|
|
$aux = explode('_', $LAN_ID);
|
2013-01-23 12:34:42 -04:00
|
|
|
$LAN_ID = $aux[0];
|
|
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
$oCriteria = new Criteria( 'workflow' );
|
2013-01-07 12:44:13 -04:00
|
|
|
$oCriteria->addSelectColumn( LanguagePeer::LAN_ID );
|
2012-10-19 10:24:29 -04:00
|
|
|
$oCriteria->addSelectColumn( LanguagePeer::LAN_NAME );
|
|
|
|
|
$oCriteria->add( LanguagePeer::LAN_ID, $LAN_ID );
|
|
|
|
|
$oDataset = LanguagePeer::doSelectRS( $oCriteria );
|
|
|
|
|
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
return $oDataset->getRow();
|
|
|
|
|
}
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-20 16:52:15 -04:00
|
|
|
public function findByLanName ($LAN_NAME)
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
$oCriteria = new Criteria( 'workflow' );
|
|
|
|
|
$oCriteria->addSelectColumn( LanguagePeer::LAN_ID );
|
|
|
|
|
$oCriteria->addSelectColumn( LanguagePeer::LAN_NAME );
|
|
|
|
|
$oCriteria->add( LanguagePeer::LAN_NAME, $LAN_NAME, Criteria::LIKE );
|
|
|
|
|
$oDataset = LanguagePeer::doSelectRS( $oCriteria );
|
|
|
|
|
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
return $oDataset->getRow();
|
|
|
|
|
}
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2015-04-22 17:01:34 -04:00
|
|
|
public function findLocationByLanId($languageId)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
if (!isset(self::$arrayRecord[$languageId])) {
|
|
|
|
|
$criteria = new Criteria("workflow");
|
|
|
|
|
|
|
|
|
|
$criteria->addSelectColumn(LanguagePeer::LAN_LOCATION);
|
|
|
|
|
$criteria->add(LanguagePeer::LAN_ID, $languageId, Criteria::LIKE);
|
|
|
|
|
|
|
|
|
|
$rsCriteria = LanguagePeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
|
|
|
|
|
self::$arrayRecord[$languageId] = $rsCriteria->getRow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$record = self::$arrayRecord[$languageId];
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return $record;
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2013-12-16 12:15:41 -04:00
|
|
|
}
|
2015-04-22 17:01:34 -04:00
|
|
|
|
2017-10-17 16:18:26 -04:00
|
|
|
/**
|
2012-10-19 10:24:29 -04:00
|
|
|
* Import a language file
|
|
|
|
|
*
|
2017-10-17 16:18:26 -04:00
|
|
|
* @param string $languageFile
|
|
|
|
|
* @param bool $updateXml
|
|
|
|
|
* @param bool $updateDB
|
|
|
|
|
* @param bool $generateMafe
|
|
|
|
|
* @return Object
|
|
|
|
|
* @throws Exception
|
2012-10-19 10:24:29 -04:00
|
|
|
*/
|
2017-10-17 16:18:26 -04:00
|
|
|
public function import($languageFile, $updateXml = true, $updateDB = true, $generateMafe = true)
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2017-10-17 16:18:26 -04:00
|
|
|
$translation = new Translation();
|
2015-09-15 11:50:23 -04:00
|
|
|
try {
|
2017-10-17 16:18:26 -04:00
|
|
|
//We get all MichelangeloFE and PMDynaform translatable labels.
|
|
|
|
|
$labels = array_merge(self::getLabelsMafe(), self::getLabelsPMDynaform());
|
|
|
|
|
foreach ($labels as $label) {
|
|
|
|
|
$translation->addTranslation('LABEL', 'ID_MAFE_' . G::encryptOld($label), 'en', $label);
|
2015-09-15 11:50:23 -04:00
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
error_log($e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-17 16:18:26 -04:00
|
|
|
$POFile = new i18n_PO($languageFile);
|
2012-10-19 10:24:29 -04:00
|
|
|
$POFile->readInit();
|
|
|
|
|
$POHeaders = $POFile->getHeaders();
|
|
|
|
|
|
|
|
|
|
/*getting the PO Language definition*/
|
|
|
|
|
$langName = $POHeaders['X-Poedit-Language'];
|
|
|
|
|
//find the lang id
|
|
|
|
|
$language = new Language();
|
2017-10-17 16:18:26 -04:00
|
|
|
$langRecord = $language->findByLanName($langName);
|
2012-10-19 10:24:29 -04:00
|
|
|
|
2017-10-17 16:18:26 -04:00
|
|
|
if (!isset($langRecord['LAN_ID'])) {
|
|
|
|
|
$langRecord = $language->findById($langName);
|
|
|
|
|
if (!isset($langRecord['LAN_ID'])) {
|
2013-01-07 12:44:13 -04:00
|
|
|
//if the language doesn't exist abort
|
2017-10-17 16:18:26 -04:00
|
|
|
throw new Exception('The .po file has a invalid X-Poedit-Language definition!');
|
2013-01-07 12:44:13 -04:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$languageID = $langRecord['LAN_ID'];
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
/*getting the PO Language definition*/
|
|
|
|
|
$countryName = $POHeaders['X-Poedit-Country'];
|
|
|
|
|
if ($countryName != '.') {
|
|
|
|
|
$isoCountry = new IsoCountry();
|
2017-10-17 16:18:26 -04:00
|
|
|
$countryRecord = $isoCountry->findByIcName($countryName);
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2017-10-17 16:18:26 -04:00
|
|
|
if (!isset($countryRecord['IC_UID'])) {
|
2012-10-19 10:24:29 -04:00
|
|
|
//if the language doesn't exist abort
|
2017-10-17 16:18:26 -04:00
|
|
|
throw new Exception('The .po file has a invalid X-Poedit-Country definition!');
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$countryID = $countryRecord['IC_UID'];
|
|
|
|
|
//define locale
|
|
|
|
|
$LOCALE = "$languageID-$countryID";
|
|
|
|
|
} else {
|
|
|
|
|
$LOCALE = $languageID;
|
|
|
|
|
}
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$countItems = 0;
|
|
|
|
|
$countItemsSuccess = 0;
|
|
|
|
|
$errorMsg = '';
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
while ($rowTranslation = $POFile->getTranslation()) {
|
2017-10-17 16:18:26 -04:00
|
|
|
$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!');
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
foreach ($POFile->translatorComments as $a => $aux) {
|
2017-10-17 16:18:26 -04:00
|
|
|
$aux = trim($aux);
|
2012-10-19 10:24:29 -04:00
|
|
|
if ($aux == 'TRANSLATION') {
|
|
|
|
|
$identifier = $aux;
|
|
|
|
|
} else {
|
2017-10-17 16:18:26 -04:00
|
|
|
$var = explode('/', $aux);
|
2012-10-19 10:24:29 -04:00
|
|
|
if ($var[0] == 'LABEL') {
|
|
|
|
|
$context = $aux;
|
|
|
|
|
}
|
|
|
|
|
if ($var[0] == 'JAVASCRIPT') {
|
|
|
|
|
$context = $aux;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-17 16:18:26 -04:00
|
|
|
if (preg_match('/^([\w-]+)\/([\w-]+\/*[\w-]*\.xml\?)/', $aux, $match)) {
|
2012-10-19 10:24:29 -04:00
|
|
|
$identifier = $aux;
|
|
|
|
|
} else {
|
2017-10-17 16:18:26 -04:00
|
|
|
if (preg_match('/^([\w-]+)\/([\w-]+\/*[\w-]*\.xml$)/', $aux, $match)) {
|
2012-10-19 10:24:29 -04:00
|
|
|
$context = $aux;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$reference = $POFile->references[0];
|
|
|
|
|
|
|
|
|
|
// it is a Sql insert on TRANSLATIONS TAble
|
|
|
|
|
if ($identifier == 'TRANSLATION') {
|
|
|
|
|
if ($updateDB) {
|
2017-10-17 16:18:26 -04:00
|
|
|
list ($category, $id) = explode('/', $context);
|
|
|
|
|
$result = $translation->addTranslation($category, $id, $LOCALE, trim(stripcslashes(str_replace(chr(10), '', $rowTranslation['msgstr']))));
|
2012-10-19 10:24:29 -04:00
|
|
|
if ($result['codError'] == 0) {
|
2017-10-17 16:18:26 -04:00
|
|
|
$countItemsSuccess++;
|
2012-10-19 10:24:29 -04:00
|
|
|
} else {
|
|
|
|
|
$errorMsg .= $id . ': ' . $result['message'] . "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // is a Xml update
|
|
|
|
|
elseif ($updateXml) {
|
|
|
|
|
$xmlForm = $context;
|
|
|
|
|
//erik: expresion to prevent and hable correctly dropdown values like -1, -2 etc.
|
2017-10-17 16:18:26 -04:00
|
|
|
preg_match('/^([\w_]+)\s-\s([\w_]+)\s*-*\s*([\w\W]*)$/', $reference, $match);
|
2012-10-19 10:24:29 -04:00
|
|
|
|
2017-10-17 16:18:26 -04:00
|
|
|
if (!file_exists(PATH_XMLFORM . $xmlForm)) {
|
2012-10-19 10:24:29 -04:00
|
|
|
$errorMsg .= 'file doesn\'t exist: ' . PATH_XMLFORM . $xmlForm . "\n";
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-17 16:18:26 -04:00
|
|
|
if (count($match) < 4) {
|
|
|
|
|
$near = isset($rowTranslation['msgid']) ? $rowTranslation['msgid'] : (isset($rowTranslation['msgstr']) ? $rowTranslation['msgstr'] : '');
|
2012-12-07 17:01:37 -04:00
|
|
|
$errorMsg .= "Invalid Translation reference: \"$reference\", near -> " . strip_tags($near) . "\n";
|
2012-10-19 10:24:29 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-15 16:26:02 +00:00
|
|
|
|
2017-10-17 16:18:26 -04:00
|
|
|
$dynaform = new DynaformHandler(PATH_XMLFORM . $xmlForm);
|
2012-10-19 10:24:29 -04:00
|
|
|
$fieldName = $match[2];
|
|
|
|
|
|
2017-10-17 16:18:26 -04:00
|
|
|
$codes = explode('-', $reference);
|
2012-10-19 10:24:29 -04:00
|
|
|
|
2017-10-17 16:18:26 -04:00
|
|
|
if (sizeof($codes) == 2) {
|
2012-10-19 10:24:29 -04:00
|
|
|
//is a normal node
|
2017-10-17 16:18:26 -04:00
|
|
|
$dynaform->addChilds($fieldName, Array($LOCALE => stripcslashes(str_replace(chr(10), '', $rowTranslation['msgstr']))
|
|
|
|
|
));
|
|
|
|
|
} elseif (sizeof($codes) > 2) {
|
2012-10-19 10:24:29 -04:00
|
|
|
//is a node child for a language node
|
|
|
|
|
$name = $match[3] == "''" ? '' : $match[3];
|
2017-10-17 16:18:26 -04:00
|
|
|
$childNode = Array(Array('name' => 'option', 'value' => $rowTranslation['msgstr'], 'attributes' => Array('name' => $name
|
2012-10-19 10:24:29 -04:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2017-10-17 16:18:26 -04:00
|
|
|
$dynaform->addChilds($fieldName, Array($LOCALE => null
|
|
|
|
|
), $childNode);
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
2017-10-17 16:18:26 -04:00
|
|
|
$countItemsSuccess++;
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
|
|
|
|
}
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2017-10-17 16:18:26 -04:00
|
|
|
$language = new Language();
|
|
|
|
|
$language->update(array('LAN_ID' => $languageID, 'LAN_ENABLED' => '1'
|
|
|
|
|
));
|
2012-10-19 10:24:29 -04:00
|
|
|
|
2013-04-17 14:45:58 -04:00
|
|
|
if ($updateXml) {
|
|
|
|
|
$trn = new Translation();
|
2017-10-17 16:18:26 -04:00
|
|
|
$trn->generateFileTranslation($LOCALE);
|
|
|
|
|
$trn->addTranslationEnvironment($LOCALE, $POHeaders, $countItemsSuccess);
|
2013-04-17 14:45:58 -04:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
|
2014-04-10 12:30:51 -04:00
|
|
|
if ($generateMafe) {
|
|
|
|
|
$trn = new Translation();
|
|
|
|
|
$trn->generateFileTranslationMafe();
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
//fill the results
|
|
|
|
|
$results = new stdClass();
|
|
|
|
|
$results->recordsCount = $countItems;
|
|
|
|
|
$results->recordsCountSuccess = $countItemsSuccess;
|
|
|
|
|
$results->lang = $languageID;
|
|
|
|
|
$results->headers = $POHeaders;
|
|
|
|
|
$results->errMsg = $errorMsg;
|
|
|
|
|
|
2017-10-17 16:18:26 -04:00
|
|
|
G::auditLog("UploadLanguage", "Language: " . $languageID);
|
2014-10-07 15:58:46 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
return $results;
|
2017-10-17 16:18:26 -04:00
|
|
|
} catch (Exception $error) {
|
|
|
|
|
throw ($error);
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
2011-05-09 15:50:31 -04:00
|
|
|
}
|
|
|
|
|
|
2017-10-17 16:18:26 -04:00
|
|
|
/**
|
|
|
|
|
* Export language to Download
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2012-10-20 16:52:15 -04:00
|
|
|
public function export ()
|
2012-10-19 10:24:29 -04:00
|
|
|
{
|
2017-10-17 16:18:26 -04:00
|
|
|
$translation = new Translation();
|
2015-06-29 16:51:59 -04:00
|
|
|
try {
|
2017-10-17 16:18:26 -04:00
|
|
|
//We get all MichelangeloFE and PMDynaform translatable labels.
|
|
|
|
|
$labels = array_merge(self::getLabelsMafe(), self::getLabelsPMDynaform());
|
|
|
|
|
foreach ($labels as $label) {
|
|
|
|
|
$translation->addTranslation('LABEL', 'ID_MAFE_' . G::encryptOld($label), 'en', $label);
|
2015-06-29 16:51:59 -04:00
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
error_log($e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
//creating the .po file
|
|
|
|
|
$sPOFile = PATH_CORE . 'content' . PATH_SEP . 'translations' . PATH_SEP . MAIN_POFILE . '.' . $_GET['LOCALE'] . '.po';
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$poFile = new i18n_PO( $sPOFile );
|
|
|
|
|
$poFile->buildInit();
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$language = new Language();
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$locale = $_GET['LOCALE'];
|
|
|
|
|
$_TARGET_LANG = $_GET['LOCALE'];
|
|
|
|
|
$_BASE_LANG = 'en';
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
if (strpos( $locale, Translation::$localeSeparator ) !== false) {
|
|
|
|
|
list ($LAN_ID, $IC_UID) = explode( Translation::$localeSeparator, $_GET['LOCALE'] );
|
|
|
|
|
$iCountry = new IsoCountry();
|
|
|
|
|
$iCountryRecord = $iCountry->findById( $IC_UID );
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
if (! isset( $iCountryRecord['IC_UID'] )) {
|
|
|
|
|
throw new Exception( "Country Target ID '{$_GET['LAN_ID']}' doesn't exist!" );
|
|
|
|
|
}
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$sCountry = $iCountryRecord['IC_NAME'];
|
2011-05-09 15:50:31 -04:00
|
|
|
} else {
|
2012-10-19 10:24:29 -04:00
|
|
|
$LAN_ID = $locale;
|
|
|
|
|
$sCountry = $IC_UID = '';
|
2011-05-09 15:50:31 -04:00
|
|
|
}
|
|
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$langRecord = $language->findById( $LAN_ID );
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
if (! isset( $langRecord['LAN_NAME'] )) {
|
|
|
|
|
throw new Exception( "Language Target ID \"{$LAN_ID}\" doesn't exist!" );
|
|
|
|
|
}
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$sLanguage = $langRecord['LAN_NAME'];
|
|
|
|
|
|
|
|
|
|
//setting headers
|
2017-08-14 16:13:46 -04:00
|
|
|
$poFile->addHeader( 'Project-Id-Version', 'ProcessMaker ' . System::getVersion() );
|
2012-10-19 10:24:29 -04:00
|
|
|
$poFile->addHeader( 'POT-Creation-Date', '' );
|
|
|
|
|
$poFile->addHeader( 'PO-Revision-Date', date( 'Y-m-d H:i:s' ) );
|
|
|
|
|
$poFile->addHeader( 'Last-Translator', '' );
|
|
|
|
|
$poFile->addHeader( 'Language-Team', 'Colosa Developers Team <developers@colosa.com>' );
|
|
|
|
|
$poFile->addHeader( 'MIME-Version', '1.0' );
|
|
|
|
|
$poFile->addHeader( 'Content-Type', 'text/plain; charset=utf-8' );
|
|
|
|
|
$poFile->addHeader( 'Content-Transfer_Encoding', '8bit' );
|
|
|
|
|
$poFile->addHeader( 'X-Poedit-Language', ucwords( $sLanguage ) );
|
|
|
|
|
$poFile->addHeader( 'X-Poedit-Country', ucwords( $sCountry ) );
|
|
|
|
|
$poFile->addHeader( 'X-Poedit-SourceCharset', 'utf-8' );
|
|
|
|
|
$poFile->addHeader( 'Content-Transfer-Encoding', '8bit' );
|
|
|
|
|
|
|
|
|
|
$aLabels = array ();
|
|
|
|
|
$aMsgids = array ('' => true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// selecting all translations records of base language 'en' on TRANSLATIONS table
|
|
|
|
|
$oCriteria = new Criteria( 'workflow' );
|
|
|
|
|
$oCriteria->addSelectColumn( TranslationPeer::TRN_CATEGORY );
|
|
|
|
|
$oCriteria->addSelectColumn( TranslationPeer::TRN_ID );
|
|
|
|
|
$oCriteria->addSelectColumn( TranslationPeer::TRN_VALUE );
|
|
|
|
|
$oCriteria->add( TranslationPeer::TRN_LANG, 'en' );
|
|
|
|
|
$oDataset = TranslationPeer::doSelectRS( $oCriteria );
|
|
|
|
|
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
|
|
|
|
|
|
|
|
|
$targetLangRecords = array ();
|
|
|
|
|
// retrieve the translation for the target language
|
|
|
|
|
if ($LAN_ID != 'en') {
|
|
|
|
|
// only if it is different language than base language 'en'
|
|
|
|
|
$c = new Criteria( 'workflow' );
|
|
|
|
|
$c->addSelectColumn( TranslationPeer::TRN_CATEGORY );
|
|
|
|
|
$c->addSelectColumn( TranslationPeer::TRN_ID );
|
|
|
|
|
$c->addSelectColumn( TranslationPeer::TRN_VALUE );
|
|
|
|
|
$c->add( TranslationPeer::TRN_LANG, $_GET['LOCALE'] );
|
|
|
|
|
$ds = TranslationPeer::doSelectRS( $c );
|
|
|
|
|
$ds->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
|
|
|
|
|
|
|
|
|
while ($ds->next()) {
|
|
|
|
|
$row = $ds->getRow();
|
|
|
|
|
$targetLangRecords[$row['TRN_CATEGORY'] . '/' . $row['TRN_ID']] = $row['TRN_VALUE'];
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
// get the respective translation for each english label
|
|
|
|
|
while ($oDataset->next()) {
|
|
|
|
|
$aRow1 = $oDataset->getRow();
|
|
|
|
|
$trnCategory = trim( $aRow1['TRN_CATEGORY'] );
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
# Validation, validate that the TRN_CATEGORY contains valid characteres
|
|
|
|
|
preg_match( "/^[0-9a-zA-Z_-]+/", $trnCategory, $sTestResult );
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
// IF the translations id "TRN_ID" has invalid characteres or has not accepted categories
|
|
|
|
|
if ($sTestResult[0] !== $trnCategory || ($trnCategory != 'LABEL' && $trnCategory != 'JAVASCRIPT')) {
|
2017-10-17 16:18:26 -04:00
|
|
|
$translation->remove( $aRow1['TRN_CATEGORY'], $aRow1['TRN_ID'], 'en' ); //remove not accepted translations
|
2012-10-19 10:24:29 -04:00
|
|
|
continue; //jump to next iteration
|
|
|
|
|
}
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
// retrieve the translation for the target language
|
|
|
|
|
if ($LAN_ID != 'en') {
|
|
|
|
|
// only if it is different language than base language 'en'
|
|
|
|
|
if (isset( $targetLangRecords[$aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID']] )) {
|
|
|
|
|
$msgstr = $targetLangRecords[$aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID']] != '' ? $targetLangRecords[$aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID']] : $aRow1['TRN_VALUE'];
|
|
|
|
|
} else {
|
|
|
|
|
$msgstr = $aRow1['TRN_VALUE'];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//if not just copy the same
|
|
|
|
|
$msgstr = $aRow1['TRN_VALUE'];
|
|
|
|
|
}
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$msgid = trim( $aRow1['TRN_VALUE'] );
|
|
|
|
|
$msgstr = trim( $msgstr );
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
if (isset( $aMsgids[$msgid] )) {
|
|
|
|
|
$msgid = '[' . $aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID'] . '] ' . $msgid;
|
|
|
|
|
}
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$poFile->addTranslatorComment( 'TRANSLATION' );
|
|
|
|
|
$poFile->addTranslatorComment( $aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID'] );
|
|
|
|
|
$poFile->addReference( $aRow1['TRN_CATEGORY'] . '/' . $aRow1['TRN_ID'] );
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$poFile->addTranslation( stripcslashes( $msgid ), stripcslashes( $msgstr ) );
|
|
|
|
|
$aMsgids[$msgid] = true;
|
|
|
|
|
}
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
//$timer->setMarker('end making 1th .po from db');
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
//find all xml files into PATH_XMLFORM
|
|
|
|
|
$aXMLForms = glob( PATH_XMLFORM . '*/*.xml' );
|
|
|
|
|
//from a sublevel to
|
|
|
|
|
$aXMLForms2 = glob( PATH_XMLFORM . '*/*/*.xml' );
|
|
|
|
|
$aXMLForms = array_merge( $aXMLForms, $aXMLForms2 );
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$aEnglishLabel = array ();
|
|
|
|
|
$aOptions = array ();
|
|
|
|
|
$nodesNames = Array ();
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2017-02-15 16:26:02 +00:00
|
|
|
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
foreach ($aXMLForms as $xmlFormPath) {
|
|
|
|
|
$xmlFormFile = str_replace( chr( 92 ), '/', $xmlFormPath );
|
|
|
|
|
$xmlFormFile = str_replace( PATH_XMLFORM, '', $xmlFormPath );
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2017-08-08 16:45:49 -04:00
|
|
|
$dynaForm = new DynaformHandler( $xmlFormPath );
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$dynaNodes = $dynaForm->getFields();
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
//get all fields of each xmlform
|
|
|
|
|
foreach ($dynaNodes as $oNode) {
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$sNodeName = $oNode->nodeName;
|
|
|
|
|
//$arrayNode = $dynaForm->getArray($oNode, Array('type', $_BASE_LANG, $_BASE_LANG));
|
|
|
|
|
$arrayNode = $dynaForm->getArray( $oNode );
|
|
|
|
|
//if has not native language translation
|
2013-03-13 12:34:23 -04:00
|
|
|
if (! isset( $arrayNode[$_BASE_LANG] ) || ! isset( $arrayNode['type'] ) || (isset( $arrayNode['type'] ) && in_array( $arrayNode['type'], $this->exceptionFields ))) {
|
2012-10-19 10:24:29 -04:00
|
|
|
continue; //just continue with the next node
|
|
|
|
|
}
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
// Getting the Base Origin Text
|
|
|
|
|
if (! is_array( $arrayNode[$_BASE_LANG] )) {
|
|
|
|
|
$originNodeText = trim( $arrayNode[$_BASE_LANG] );
|
|
|
|
|
} else {
|
|
|
|
|
$langNode = $arrayNode[$_BASE_LANG][0];
|
|
|
|
|
$originNodeText = $langNode['__nodeText__'];
|
|
|
|
|
}
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
// Getting the Base Target Text
|
|
|
|
|
if (isset( $arrayNode[$_TARGET_LANG] )) {
|
|
|
|
|
if (! is_array( $arrayNode[$_TARGET_LANG] )) {
|
|
|
|
|
$targetNodeText = trim( $arrayNode[$_TARGET_LANG] );
|
|
|
|
|
} else {
|
|
|
|
|
$langNode = $arrayNode[$_TARGET_LANG][0];
|
|
|
|
|
$targetNodeText = $langNode['__nodeText__'];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$targetNodeText = $originNodeText;
|
|
|
|
|
}
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$nodeName = $arrayNode['__nodeName__'];
|
|
|
|
|
$nodeType = $arrayNode['type'];
|
2012-08-21 16:06:22 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
$msgid = $originNodeText;
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
// if the nodeName already exists in the po file, we need to create other msgid
|
|
|
|
|
if (isset( $aMsgids[$msgid] )) {
|
|
|
|
|
$msgid = '[' . $xmlFormFile . '?' . $nodeName . '] ' . $originNodeText;
|
2011-05-09 15:50:31 -04:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
$poFile->addTranslatorComment( $xmlFormFile . '?' . $nodeName );
|
|
|
|
|
$poFile->addTranslatorComment( $xmlFormFile );
|
|
|
|
|
$poFile->addReference( $nodeType . ' - ' . $nodeName );
|
|
|
|
|
$poFile->addTranslation( stripslashes( $msgid ), stripslashes( $targetNodeText ) );
|
|
|
|
|
|
|
|
|
|
$aMsgids[$msgid] = true;
|
|
|
|
|
|
|
|
|
|
//if this node has options child nodes
|
|
|
|
|
if (isset( $arrayNode[$_BASE_LANG] ) && isset( $arrayNode[$_BASE_LANG][0] ) && isset( $arrayNode[$_BASE_LANG][0]['option'] )) {
|
|
|
|
|
|
|
|
|
|
$originOptionNode = $arrayNode[$_BASE_LANG][0]['option']; //get the options
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$targetOptionExists = false;
|
|
|
|
|
if (isset( $arrayNode[$_TARGET_LANG] ) && isset( $arrayNode[$_TARGET_LANG][0] ) && isset( $arrayNode[$_TARGET_LANG][0]['option'] )) {
|
|
|
|
|
$targetOptionNode = $arrayNode[$_TARGET_LANG][0]['option'];
|
|
|
|
|
$targetOptionExists = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! is_array( $originOptionNode )) {
|
|
|
|
|
if (is_string( $originOptionNode )) {
|
|
|
|
|
$poFile->addTranslatorComment( $xmlFormFile . '?' . $nodeName . '-' . $originOptionNode );
|
|
|
|
|
$poFile->addTranslatorComment( $xmlFormFile );
|
|
|
|
|
$poFile->addReference( $nodeType . ' - ' . $nodeName . ' - ' . $originOptionNode );
|
|
|
|
|
$poFile->addTranslation( stripslashes( $msgid ), stripslashes( $originOptionNode ) );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
foreach ($originOptionNode as $optionNode) {
|
|
|
|
|
$optionName = $optionNode['name'];
|
|
|
|
|
$originOptionValue = $optionNode['__nodeText__'];
|
|
|
|
|
|
|
|
|
|
if ($targetOptionExists) {
|
|
|
|
|
|
|
|
|
|
$targetOptionValue = getMatchDropdownOptionValue( $optionName, $targetOptionNode );
|
|
|
|
|
if ($targetOptionValue === false) {
|
|
|
|
|
$targetOptionValue = $originOptionValue;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$targetOptionValue = $originOptionValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$msgid = '[' . $xmlFormFile . '?' . $nodeName . '-' . $optionName . ']';
|
|
|
|
|
$poFile->addTranslatorComment( $xmlFormFile . '?' . $nodeName . '-' . $optionName );
|
|
|
|
|
$poFile->addTranslatorComment( $xmlFormFile );
|
|
|
|
|
$poFile->addReference( $nodeType . ' - ' . $nodeName . ' - ' . $optionName );
|
|
|
|
|
$poFile->addTranslation( $msgid, stripslashes( $targetOptionValue ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} //end foreach
|
|
|
|
|
}
|
2014-10-10 12:19:34 -04:00
|
|
|
G::auditLog("ExportLanguage", "Language: ".$_GET['LOCALE']);
|
2012-10-19 10:24:29 -04:00
|
|
|
G::streamFile( $sPOFile, true );
|
|
|
|
|
}
|
2017-10-17 16:18:26 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Labels MAFE (Michelangelo Project)
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function getLabelsMafe()
|
|
|
|
|
{
|
|
|
|
|
$labels = [];
|
|
|
|
|
$buildhash = PATH_HTML . "lib/buildhash";
|
|
|
|
|
if (!file_exists($buildhash)) {
|
|
|
|
|
throw new RuntimeException("Unable to generate labels for MAFE!.\nMissing file '{$buildhash}'.");
|
|
|
|
|
}
|
|
|
|
|
$buildhash = file_get_contents($buildhash);
|
|
|
|
|
|
|
|
|
|
$michelangeloFE = PATH_HTML . "lib/js";
|
2018-05-11 14:30:50 -04:00
|
|
|
$array = glob($michelangeloFE . '/' . '*' . $buildhash . '*', GLOB_BRACE);
|
|
|
|
|
$pathFileMafe = array_pop($array);
|
2017-10-17 16:18:26 -04:00
|
|
|
if (file_exists($pathFileMafe) && is_readable($pathFileMafe)) {
|
|
|
|
|
$labels = self::readLabelsDirectory($pathFileMafe, true);
|
|
|
|
|
}
|
|
|
|
|
return $labels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Labels PMDynaform (PMDynaform Project)
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function getLabelsPMDynaform()
|
|
|
|
|
{
|
|
|
|
|
$labels = [];
|
|
|
|
|
$pathFilePMDynaform = PATH_HTML . "lib/pmdynaform/build/js/PMDynaform.js";
|
|
|
|
|
if (file_exists($pathFilePMDynaform) && is_readable($pathFilePMDynaform)) {
|
|
|
|
|
$labels = self::readLabelsDirectory($pathFilePMDynaform, true);
|
|
|
|
|
}
|
|
|
|
|
return $labels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* We read all labels
|
|
|
|
|
* @param $path
|
|
|
|
|
* @param bool $unique
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function readLabelsDirectory($path, $unique = false)
|
|
|
|
|
{
|
|
|
|
|
$labels = [];
|
|
|
|
|
if (is_file($path)) {
|
|
|
|
|
$info = pathinfo($path);
|
|
|
|
|
if (strtolower($info["extension"]) === "js") {
|
|
|
|
|
$file = file_get_contents($path);
|
|
|
|
|
//search string 'xx\'xx\'xx'.translate()
|
|
|
|
|
$labels = array_merge($labels, self::readLabelsFile($file, "'"));
|
|
|
|
|
//search string "xx\"xx\"xx".translate()
|
|
|
|
|
$labels = array_merge($labels, self::readLabelsFile($file, "\""));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($unique) {
|
|
|
|
|
$labels = array_unique($labels);
|
|
|
|
|
}
|
|
|
|
|
return $labels;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-18 09:54:30 -04:00
|
|
|
public function updateLanguagePlugin ($plugin, $idLanguage)
|
2013-03-12 16:44:17 -04:00
|
|
|
{
|
|
|
|
|
if (!file_exists(PATH_PLUGINS . $plugin)) {
|
|
|
|
|
throw new Exception( 'The plugin ' . $plugin . ' not exist' );
|
|
|
|
|
die();
|
|
|
|
|
}
|
2013-03-18 09:54:30 -04:00
|
|
|
if (!file_exists(PATH_PLUGINS . $plugin . PATH_SEP . 'translations' . PATH_SEP . 'translations.php')) {
|
|
|
|
|
throw new Exception( 'Translations.php not exist in plugin ' . $plugin);
|
2013-03-15 15:37:22 -04:00
|
|
|
}
|
2013-03-18 09:54:30 -04:00
|
|
|
if (!file_exists(PATH_PLUGINS . $plugin . PATH_SEP . 'translations' . PATH_SEP . $plugin . '.' . $idLanguage . '.po')) {
|
2013-03-13 12:34:23 -04:00
|
|
|
throw new Exception( 'The file ' . $plugin . '.' . $idLanguage . '.po not exists' );
|
2013-03-12 16:44:17 -04:00
|
|
|
die();
|
|
|
|
|
}
|
2013-03-18 09:54:30 -04:00
|
|
|
$languageFile = PATH_PLUGINS . $plugin . PATH_SEP . 'translations' . PATH_SEP . $plugin . '.' . $idLanguage . '.po' ;
|
2013-03-12 16:44:17 -04:00
|
|
|
try {
|
2017-02-15 16:26:02 +00:00
|
|
|
|
2013-03-12 16:44:17 -04:00
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-15 16:26:02 +00:00
|
|
|
|
2017-08-08 16:45:49 -04:00
|
|
|
$dynaform = new DynaformHandler( PATH_PLUGINS . $plugin . PATH_SEP . $xmlForm );
|
2013-03-12 16:44:17 -04:00
|
|
|
$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 );
|
2013-08-20 16:43:01 -04:00
|
|
|
$languageID = (isset($languageID)) ? $languageID : $idLanguage;
|
2013-03-12 16:44:17 -04:00
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-18 09:54:30 -04:00
|
|
|
public function createLanguagePlugin ($plugin, $idLanguage)
|
2013-03-12 16:44:17 -04:00
|
|
|
{
|
2013-03-18 09:54:30 -04:00
|
|
|
if (!file_exists(PATH_PLUGINS . $plugin . PATH_SEP . 'translations' . PATH_SEP . 'translations.php')) {
|
2013-03-15 15:37:22 -04:00
|
|
|
throw new Exception( 'Translation.php not exist in plugin ' . $plugin);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-12 16:44:17 -04:00
|
|
|
$language = new Language();
|
|
|
|
|
|
|
|
|
|
$locale = $language;
|
2013-03-13 12:34:23 -04:00
|
|
|
$targetLang = $idLanguage;
|
|
|
|
|
$baseLang = 'en';
|
2013-03-12 16:44:17 -04:00
|
|
|
|
2013-03-26 12:17:50 -04:00
|
|
|
$aLabels = array ();
|
|
|
|
|
$aMsgids = array ('' => true
|
|
|
|
|
);
|
|
|
|
|
include PATH_PLUGINS . $plugin . PATH_SEP . 'translations'. PATH_SEP . 'translations.php';
|
|
|
|
|
$translatedText = array();
|
|
|
|
|
|
2013-03-26 15:01:53 -04:00
|
|
|
if (file_exists( PATH_LANGUAGECONT . $plugin . "." . $idLanguage)) {
|
2013-03-26 12:17:50 -04:00
|
|
|
//reading the .po file
|
2013-03-26 15:01:53 -04:00
|
|
|
include PATH_LANGUAGECONT . $plugin . "." . $idLanguage;
|
|
|
|
|
eval('$translatedText = $translation'.$plugin.';');
|
2013-03-26 12:17:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//creating the .po file
|
|
|
|
|
$sPOFile = PATH_PLUGINS . $plugin . PATH_SEP . 'translations' . PATH_SEP . $plugin . '.' . $idLanguage . '.po';
|
|
|
|
|
$poFile = new i18n_PO( $sPOFile );
|
|
|
|
|
$poFile->buildInit();
|
|
|
|
|
|
2013-03-12 16:44:17 -04:00
|
|
|
//setting headers
|
|
|
|
|
$poFile->addHeader( 'Project-Id-Version', $plugin );
|
|
|
|
|
$poFile->addHeader( 'POT-Creation-Date', '' );
|
|
|
|
|
$poFile->addHeader( 'PO-Revision-Date', date( 'Y-m-d H:i:s' ) );
|
|
|
|
|
$poFile->addHeader( 'Last-Translator', '' );
|
|
|
|
|
$poFile->addHeader( 'Language-Team', 'Colosa Developers Team <developers@colosa.com>' );
|
|
|
|
|
$poFile->addHeader( 'MIME-Version', '1.0' );
|
|
|
|
|
$poFile->addHeader( 'Content-Type', 'text/plain; charset=utf-8' );
|
|
|
|
|
$poFile->addHeader( 'Content-Transfer_Encoding', '8bit' );
|
|
|
|
|
$poFile->addHeader( 'X-Poedit-Language', ucwords( $idLanguage ) );
|
|
|
|
|
$poFile->addHeader( 'X-Poedit-SourceCharset', 'utf-8' );
|
|
|
|
|
$poFile->addHeader( 'Content-Transfer-Encoding', '8bit' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($translations as $id => $translation) {
|
|
|
|
|
$msgid = trim( $translation);
|
|
|
|
|
$msgstr = trim( $translation );
|
2013-03-26 12:17:50 -04:00
|
|
|
foreach ($translatedText as $key => $value) {
|
|
|
|
|
if ($id == $key) {
|
|
|
|
|
$msgstr = trim( $value );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-03-12 16:44:17 -04:00
|
|
|
$poFile->addTranslatorComment( 'TRANSLATION' );
|
|
|
|
|
$poFile->addTranslatorComment( 'LABEL/' . $id );
|
|
|
|
|
$poFile->addReference( 'LABEL/'. $id );
|
|
|
|
|
|
|
|
|
|
$poFile->addTranslation( stripcslashes( $msgid ), stripcslashes( $msgstr ) );
|
|
|
|
|
$aMsgids[$msgid] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$aXMLForms = glob( PATH_PLUGINS . $plugin . PATH_SEP . '*.xml' );
|
|
|
|
|
$aXMLForms2 = glob( PATH_PLUGINS . $plugin . PATH_SEP . '*/*.xml' );
|
|
|
|
|
$aXMLForms = array_merge( $aXMLForms, $aXMLForms2 );
|
|
|
|
|
$aXMLForms3 = glob( PATH_PLUGINS . $plugin . PATH_SEP . '*/*/*.xml' );
|
|
|
|
|
$aXMLForms = array_merge( $aXMLForms, $aXMLForms3 );
|
|
|
|
|
$aEnglishLabel = array ();
|
|
|
|
|
$aOptions = array ();
|
|
|
|
|
$nodesNames = Array ();
|
|
|
|
|
|
2017-02-15 16:26:02 +00:00
|
|
|
|
2013-03-12 16:44:17 -04:00
|
|
|
|
|
|
|
|
foreach ($aXMLForms as $xmlFormPath) {
|
|
|
|
|
$xmlFormFile = str_replace( chr( 92 ), '/', $xmlFormPath );
|
|
|
|
|
$xmlFormFile = str_replace( PATH_PLUGINS . $plugin . PATH_SEP , '', $xmlFormPath );
|
2017-08-08 16:45:49 -04:00
|
|
|
$dynaForm = new DynaformHandler( $xmlFormPath );
|
2013-03-12 16:44:17 -04:00
|
|
|
$dynaNodes = $dynaForm->getFields();
|
|
|
|
|
//get all fields of each xmlform
|
|
|
|
|
foreach ($dynaNodes as $oNode) {
|
|
|
|
|
$sNodeName = $oNode->nodeName;
|
|
|
|
|
$arrayNode = $dynaForm->getArray( $oNode );
|
|
|
|
|
//if has not native language translation
|
2013-03-13 12:34:23 -04:00
|
|
|
if (! isset( $arrayNode[$baseLang] ) || ! isset( $arrayNode['type'] ) || (isset( $arrayNode['type'] ) && in_array( $arrayNode['type'], $this->exceptionFields ))) {
|
2013-03-12 16:44:17 -04:00
|
|
|
continue; //just continue with the next node
|
|
|
|
|
}
|
|
|
|
|
// Getting the Base Origin Text
|
2013-03-13 12:34:23 -04:00
|
|
|
if (! is_array( $arrayNode[$baseLang] )) {
|
|
|
|
|
$originNodeText = trim( $arrayNode[$baseLang] );
|
2013-03-12 16:44:17 -04:00
|
|
|
} else {
|
2013-03-13 12:34:23 -04:00
|
|
|
$langNode = $arrayNode[$baseLang][0];
|
2013-03-12 16:44:17 -04:00
|
|
|
$originNodeText = $langNode['__nodeText__'];
|
|
|
|
|
}
|
|
|
|
|
// Getting the Base Target Text
|
2013-03-13 12:34:23 -04:00
|
|
|
if (isset( $arrayNode[$targetLang] )) {
|
|
|
|
|
if (! is_array( $arrayNode[$targetLang] )) {
|
|
|
|
|
$targetNodeText = trim( $arrayNode[$targetLang] );
|
2013-03-12 16:44:17 -04:00
|
|
|
} else {
|
2013-03-13 12:34:23 -04:00
|
|
|
$langNode = $arrayNode[$targetLang][0];
|
2013-03-12 16:44:17 -04:00
|
|
|
$targetNodeText = $langNode['__nodeText__'];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$targetNodeText = $originNodeText;
|
|
|
|
|
}
|
|
|
|
|
$nodeName = $arrayNode['__nodeName__'];
|
|
|
|
|
$nodeType = $arrayNode['type'];
|
|
|
|
|
$msgid = $originNodeText;
|
|
|
|
|
// if the nodeName already exists in the po file, we need to create other msgid
|
|
|
|
|
if (isset( $aMsgids[$msgid] )) {
|
|
|
|
|
$msgid = '[' . $xmlFormFile . '?' . $nodeName . '] ' . $originNodeText;
|
|
|
|
|
}
|
|
|
|
|
$poFile->addTranslatorComment( $xmlFormFile . '?' . $nodeName );
|
|
|
|
|
$poFile->addTranslatorComment( $xmlFormFile );
|
|
|
|
|
$poFile->addReference( $nodeType . ' - ' . $nodeName );
|
|
|
|
|
$poFile->addTranslation( stripslashes( $msgid ), stripslashes( $targetNodeText ) );
|
|
|
|
|
|
|
|
|
|
$aMsgids[$msgid] = true;
|
|
|
|
|
//if this node has options child nodes
|
2013-03-13 12:34:23 -04:00
|
|
|
if (isset( $arrayNode[$baseLang] ) && isset( $arrayNode[$baseLang][0] ) && isset( $arrayNode[$baseLang][0]['option'] )) {
|
|
|
|
|
$originOptionNode = $arrayNode[$baseLang][0]['option']; //get the options
|
2013-03-12 16:44:17 -04:00
|
|
|
$targetOptionExists = false;
|
2013-03-13 12:34:23 -04:00
|
|
|
if (isset( $arrayNode[$targetLang] ) && isset( $arrayNode[$targetLang][0] ) && isset( $arrayNode[$targetLang][0]['option'] )) {
|
|
|
|
|
$targetOptionNode = $arrayNode[$targetLang][0]['option'];
|
2013-03-12 16:44:17 -04:00
|
|
|
$targetOptionExists = true;
|
|
|
|
|
}
|
|
|
|
|
if (! is_array( $originOptionNode )) {
|
|
|
|
|
if (is_string( $originOptionNode )) {
|
|
|
|
|
$poFile->addTranslatorComment( $xmlFormFile . '?' . $nodeName . '-' . $originOptionNode );
|
|
|
|
|
$poFile->addTranslatorComment( $xmlFormFile );
|
|
|
|
|
$poFile->addReference( $nodeType . ' - ' . $nodeName . ' - ' . $originOptionNode );
|
|
|
|
|
$poFile->addTranslation( stripslashes( $msgid ), stripslashes( $originOptionNode ) );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
foreach ($originOptionNode as $optionNode) {
|
|
|
|
|
$optionName = $optionNode['name'];
|
|
|
|
|
$originOptionValue = $optionNode['__nodeText__'];
|
|
|
|
|
if ($targetOptionExists) {
|
|
|
|
|
$targetOptionValue = getMatchDropdownOptionValue( $optionName, $targetOptionNode );
|
|
|
|
|
if ($targetOptionValue === false) {
|
|
|
|
|
$targetOptionValue = $originOptionValue;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$targetOptionValue = $originOptionValue;
|
|
|
|
|
}
|
|
|
|
|
$msgid = '[' . $xmlFormFile . '?' . $nodeName . '-' . $optionName . ']';
|
|
|
|
|
$poFile->addTranslatorComment( $xmlFormFile . '?' . $nodeName . '-' . $optionName );
|
|
|
|
|
$poFile->addTranslatorComment( $xmlFormFile );
|
|
|
|
|
$poFile->addReference( $nodeType . ' - ' . $nodeName . ' - ' . $optionName );
|
|
|
|
|
$poFile->addTranslation( $msgid, stripslashes( $targetOptionValue ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} //end foreach
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-29 16:51:59 -04:00
|
|
|
|
2015-09-17 12:18:41 -04:00
|
|
|
public static function readLabelsFile($file, $sep)
|
2015-06-29 16:51:59 -04:00
|
|
|
{
|
|
|
|
|
$labels = array();
|
|
|
|
|
$k = 0;
|
|
|
|
|
$j = 0;
|
|
|
|
|
while ($j !== false) {
|
2015-06-30 08:46:30 -04:00
|
|
|
$j = strpos($file, $sep . ".translate(", $k);
|
2015-06-29 16:51:59 -04:00
|
|
|
if ($j !== false) {
|
|
|
|
|
$k = $j + 1;
|
|
|
|
|
$label = "";
|
|
|
|
|
$j--;
|
|
|
|
|
$c = substr($file, $j, 1);
|
|
|
|
|
while (($c !== $sep || substr($file, $j - 1, 2) === "\\" . $sep) && $j > 0) {
|
|
|
|
|
$label = $c . $label;
|
|
|
|
|
$j--;
|
|
|
|
|
$c = substr($file, $j, 1);
|
|
|
|
|
}
|
|
|
|
|
if ($label !== "") {
|
|
|
|
|
if ($sep === "'") {
|
|
|
|
|
$label = str_replace("\'", "'", $label);
|
|
|
|
|
}
|
|
|
|
|
if ($sep === '"') {
|
|
|
|
|
$label = str_replace('\"', '"', $label);
|
|
|
|
|
}
|
|
|
|
|
array_push($labels, $label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $labels;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 12:42:37 -04:00
|
|
|
function loadByCode($langId) {
|
|
|
|
|
try {
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->addSelectColumn( LanguagePeer::LAN_NAME );
|
|
|
|
|
$oCriteria->add(LanguagePeer::LAN_ID, $langId);
|
|
|
|
|
$oDataset = LanguagePeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
$aRow = $oDataset->getRow();
|
|
|
|
|
$aRow['LANGUAGE_NAME'] = $aRow['LAN_NAME'];
|
|
|
|
|
if (is_array($aRow)) {
|
|
|
|
|
return $aRow;
|
|
|
|
|
} else {
|
|
|
|
|
throw (new Exception("The language '$langId' doesn\'t exist!"));
|
|
|
|
|
}
|
|
|
|
|
} catch( exception $oError ) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
}
|
|
|
|
|
// Language
|
2011-05-09 15:50:31 -04:00
|
|
|
|
2012-10-19 10:24:29 -04:00
|
|
|
function getMatchDropdownOptionValue ($name, $options)
|
|
|
|
|
{
|
|
|
|
|
foreach ($options as $option) {
|
|
|
|
|
if ($name == $option['name']) {
|
|
|
|
|
return $option['__nodeText__'];
|
2011-05-09 15:50:31 -04:00
|
|
|
}
|
2011-05-09 17:40:31 -04:00
|
|
|
}
|
2012-10-19 10:24:29 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|