function generateFileTranslation($languageId = '') { $translation = array(); $translationJS = array(); if ($languageId === '') { $languageId = defined('SYS_LANG') ? SYS_LANG : 'en'; } $c = new Criteria(); $c->add(TranslationPeer::TRN_LANG, $languageId); $c->addAscendingOrderByColumn('TRN_CATEGORY'); $c->addAscendingOrderByColumn('TRN_ID'); $tranlations = TranslationPeer::doSelect($c); $cacheFile = PATH_LANGUAGECONT . "translation." . $languageId; $cacheFileJS = PATH_CORE . 'js' . PATH_SEP . 'labels' . PATH_SEP . $languageId . ".js"; foreach ($tranlations as $key => $row) { if ($row->getTrnCategory() === 'LABEL') { $translation[$row->getTrnId()] = $row->getTrnValue(); } if ($row->getTrnCategory() === 'JAVASCRIPT') { $translationJS[$row->getTrnId()] = $row->getTrnValue(); } } try { if (!is_dir(dirname($cacheFile))) { G::mk_dir(dirname($cacheFile)); } if (!is_dir(dirname($cacheFileJS))) { G::mk_dir(dirname($cacheFileJS)); } $f = fopen($cacheFile, 'w+'); fwrite($f, "<?php\n"); fwrite($f, '$translation =' . 'unserialize(\'' . addcslashes(serialize($translation), '\\\'') . "');\n"); fwrite($f, "?>"); fclose($f); $json = new Services_JSON(); $f = fopen($cacheFileJS, 'w'); fwrite($f, "var G_STRINGS =" . $json->encode($translationJS) . ";\n"); fclose($f); $res['cacheFile'] = $cacheFile; $res['cacheFileJS'] = $cacheFileJS; $res['rows'] = count($translation); $res['rowsJS'] = count($translationJS); return $res; } catch (Exception $e) { echo $e->getMessage(); } }
public function generateFileTranslationMafe () { $translation = Array (); $c = new Criteria(); $c->add( TranslationPeer::TRN_ID, '%ID_MAFE_%', Criteria::LIKE ); $c->addAscendingOrderByColumn( 'TRN_CATEGORY' ); $c->addAscendingOrderByColumn( 'TRN_ID' ); //$c->addAscendingOrderByColumn( 'TRN_LANG' ); $tranlations = TranslationPeer::doSelect( $c ); $mafeFolder = PATH_HTML . "translations"; $cacheFileMafe = PATH_HTML . "translations" . PATH_SEP. 'translationsMafe' . ".js"; foreach ($tranlations as $key => $row) { if ($row->getTrnCategory() === 'LABEL') { $translation[$row->getTrnLang()][$row->getTrnId()] = $row->getTrnValue(); } } try { G::verifyPath($mafeFolder, true); if (! is_dir( dirname( $cacheFileMafe ) )) { G::mk_dir( dirname( $cacheFileMafe ) ); } $f = fopen( $cacheFileMafe, 'w' ); if ($f == false) { error_log("Error: Cannot write into cacheFileMafe: $cacheFileMafe\n"); } else { fwrite( $f, "var __TRANSLATIONMAFE = " . Bootstrap::json_encode( $translation ) . ";\n"); fclose( $f ); } $res['cacheFileMafe'] = $cacheFileMafe; $res['languague'] = count($cacheFileMafe); $res['rowsMafeJS'] = count( $translation ); return $res; } catch (Exception $e) { echo $e->getMessage(); } }
function run_create_poedit_file($task, $args) { // the environment for poedit always is Development define('G_ENVIRONMENT', G_DEV_ENV); //the output language .po file $lgOutId = isset($args[0]) ? $args[0] : 'en'; $countryOutId = isset($args[1]) ? strtoupper($args[1]) : 'US'; $verboseFlag = isset($args[2]) ? $args[2] == true : false; require_once "propel/Propel.php"; require_once "classes/model/Translation.php"; require_once "classes/model/Language.php"; require_once "classes/model/IsoCountry.php"; Propel::init(PATH_CORE . "config/databases.php"); $configuration = Propel::getConfiguration(); $connectionDSN = $configuration['datasources']['propel']['connection']; printf("using DSN Connection %s \n", pakeColor::colorize($connectionDSN, 'INFO')); printf("checking Language table \n"); $c = new Criteria(); $c->add(LanguagePeer::LAN_ENABLED, "1"); $c->addor(LanguagePeer::LAN_ENABLED, "0"); $languages = LanguagePeer::doSelect($c); $langs = array(); $lgIndex = 0; $findLang = false; $langDir = 'english'; $langId = 'en'; foreach ($languages as $rowid => $row) { $lgIndex++; $langs[$row->getLanId()] = $row->getLanName(); if ($lgOutId != '' && $lgOutId == $row->getLanId()) { $findLang = true; $langDir = strtolower($row->getLanName()); $langId = $row->getLanId(); } } printf("read %s entries from language table\n", pakeColor::colorize($lgIndex, 'INFO')); printf("checking iso_country table \n"); $c = new Criteria(); $c->add(IsoCountryPeer::IC_UID, NULL, Criteria::ISNOTNULL); $countries = IsoCountryPeer::doSelect($c); $countryIndex = 0; $findCountry = false; $countryDir = 'UNITED STATES'; $countryId = 'US'; foreach ($countries as $rowid => $row) { $countryIndex++; if ($countryOutId != '' && $countryOutId == $row->getICUid()) { $findCountry = true; $countryDir = strtoupper($row->getICName()); $countryId = $row->getICUid(); } } printf("read %s entries from iso_country table\n", pakeColor::colorize($countryIndex, 'INFO')); if ($findLang == false && $lgOutId != '') { printf("%s \n", pakeColor::colorize("'{$lgOutId}' is not a valid language ", 'ERROR')); die; } else { printf("language: %s\n", pakeColor::colorize($langDir, 'INFO')); } if ($findCountry == false && $countryOutId != '') { printf("%s \n", pakeColor::colorize("'{$countryOutId}' is not a valid country ", 'ERROR')); die; } else { printf("country: [%s] %s\n", pakeColor::colorize($countryId, 'INFO'), pakeColor::colorize($countryDir, 'INFO')); } if ($findCountry && $countryId != '') { $poeditOutFile = PATH_CORE . 'content' . PATH_SEP . 'translations' . PATH_SEP . $langDir . PATH_SEP . MAIN_POFILE . '.' . $langId . '_' . $countryId . '.po'; } else { $poeditOutFile = PATH_CORE . 'content' . PATH_SEP . 'translations' . PATH_SEP . $langDir . PATH_SEP . MAIN_POFILE . '.' . $langId . '.po'; } printf("poedit file: %s\n", pakeColor::colorize($poeditOutFile, 'INFO')); $poeditOutPathInfo = pathinfo($poeditOutFile); G::verifyPath($poeditOutPathInfo['dirname'], true); $lf = "\n"; $fp = fopen($poeditOutFile, 'w'); fprintf($fp, "msgid \"\" \n"); fprintf($fp, "msgstr \"\" \n"); fprintf($fp, "\"Project-Id-Version: %s\\n\"\n", PO_SYSTEM_VERSION); fprintf($fp, "\"POT-Creation-Date: \\n\"\n"); fprintf($fp, "\"PO-Revision-Date: %s \\n\"\n", date('Y-m-d H:i+0100')); fprintf($fp, "\"Last-Translator: Fernando Ontiveros<*****@*****.**>\\n\"\n"); fprintf($fp, "\"Language-Team: Colosa Developers Team <*****@*****.**>\\n\"\n"); fprintf($fp, "\"MIME-Version: 1.0 \\n\"\n"); fprintf($fp, "\"Content-Type: text/plain; charset=utf-8 \\n\"\n"); fprintf($fp, "\"Content-Transfer_Encoding: 8bit\\n\"\n"); fprintf($fp, "\"X-Poedit-Language: %s\\n\"\n", ucwords($langDir)); fprintf($fp, "\"X-Poedit-Country: %s\\n\"\n", $countryDir); fprintf($fp, "\"X-Poedit-SourceCharset: utf-8\\n\"\n"); printf("checking translation table\n"); $c = new Criteria(); $c->add(TranslationPeer::TRN_LANG, "en"); $translation = TranslationPeer::doSelect($c); $trIndex = 0; $trError = 0; $langIdOut = $langId; //the output language, later we'll include the country too. $arrayLabels = array(); foreach ($translation as $rowid => $row) { $keyid = 'TRANSLATION/' . $row->getTrnCategory() . '/' . $row->getTrnId(); if (trim($row->getTrnValue()) == '') { printf("warning the key %s is empty.\n", pakeColor::colorize($keyid, 'ERROR')); $trError++; } else { $trans = TranslationPeer::retrieveByPK($row->getTrnCategory(), $row->getTrnId(), $langIdOut); if (is_null($trans)) { $msgStr = $row->getTrnValue(); } else { $msgStr = $trans->getTrnValue(); } $msgid = $row->getTrnValue(); if (in_array($msgid, $arrayLabels)) { $newMsgid = '[' . $row->getTrnCategory() . '/' . $row->getTrnId() . '] ' . $msgid; printf("duplicated key %s is renamed to %s.\n", pakeColor::colorize($msgid, 'ERROR'), pakeColor::colorize($newMsgid, 'INFO')); $trError++; $msgid = $newMsgid; } $arrayLabels[] = $msgid; sort($arrayLabels); $trIndex++; fprintf($fp, "\n"); fprintf($fp, "#: %s \n", $keyid); //fprintf ( $fp, "#, php-format \n" ); fprintf($fp, "# %s \n", strip_quotes($keyid)); fprintf($fp, "msgid \"%s\" \n", strip_quotes($msgid)); fprintf($fp, "msgstr \"%s\" \n", strip_quotes($msgStr)); } } printf("checking xmlform\n"); printf("using directory %s \n", pakeColor::colorize(PATH_XMLFORM, 'INFO')); G::LoadThirdParty('pear/json', 'class.json'); G::LoadThirdParty('smarty/libs', 'Smarty.class'); G::LoadSystem('xmlDocument'); G::LoadSystem('xmlform'); G::LoadSystem('xmlformExtension'); G::LoadSystem('form'); $langIdOut = $langId; //the output language, later we'll include the country too. $exceptionFields = array('javascript', 'hidden', 'phpvariable', 'private', 'toolbar', 'xmlmenu', 'toolbutton', 'cellmark', 'grid'); $xmlfiles = pakeFinder::type('file')->name('*.xml')->in(PATH_XMLFORM); $xmlIndex = 0; $xmlError = 0; $fieldsIndexTotal = 0; $exceptIndexTotal = 0; foreach ($xmlfiles as $xmlfileComplete) { $xmlIndex++; $xmlfile = str_replace(PATH_XMLFORM, '', $xmlfileComplete); //english version of dynaform $form = new Form($xmlfile, '', 'en'); $englishLabel = array(); foreach ($form->fields as $nodeName => $node) { if (trim($node->label) != '') { $englishLabel[$node->name] = $node->label; } } unset($form->fields); unset($form->tree); unset($form); //in this second pass, we are getting the target language labels $form = new Form($xmlfile, '', $langIdOut); $fieldsIndex = 0; $exceptIndex = 0; foreach ($form->fields as $nodeName => $node) { if (is_object($node) && isset($englishLabel[$node->name])) { $msgid = trim($englishLabel[$node->name]); $node->label = trim(str_replace(chr(10), '', $node->label)); } else { $msgid = ''; } if (trim($msgid) != '' && !in_array($node->type, $exceptionFields)) { //$msgid = $englishLabel [ $node->name ]; $keyid = $xmlfile . '?' . $node->name; if (in_array($msgid, $arrayLabels)) { $newMsgid = '[' . $keyid . '] ' . $msgid; if ($verboseFlag) { printf("duplicated key %s is renamed to %s.\n", pakeColor::colorize($msgid, 'ERROR'), pakeColor::colorize($newMsgid, 'INFO')); } $xmlError++; $msgid = $newMsgid; } $arrayLabels[] = $msgid; sort($arrayLabels); $comment1 = $xmlfile; $comment2 = $node->type . ' - ' . $node->name; fprintf($fp, "\n"); fprintf($fp, "#: %s \n", $keyid); // fprintf ( $fp, "#, php-format \n" ); fprintf($fp, "# %s \n", strip_quotes($comment1)); fprintf($fp, "# %s \n", strip_quotes($comment2)); fprintf($fp, "msgid \"%s\" \n", strip_quotes($msgid)); fprintf($fp, "msgstr \"%s\" \n", strip_quotes($node->label)); //fprintf ( $fp, "msgstr \"%s\" \n", strip_quotes( utf8_encode( trim($node->label) ) )); $fieldsIndex++; $fieldsIndexTotal++; } else { if (is_object($node) && !in_array($node->type, $exceptionFields)) { if (isset($node->value) && strpos($node->value, 'G::LoadTranslation') !== false) { $exceptIndex++; //print ($node->value); } else { printf("Error: xmlform %s has no english definition for %s [%s]\n", pakeColor::colorize($xmlfile, 'ERROR'), pakeColor::colorize($node->name, 'INFO'), pakeColor::colorize($node->type, 'INFO')); $xmlError++; } } else { $exceptIndex++; if ($verboseFlag) { printf("%s %s in %s\n", $node->type, pakeColor::colorize($node->name, 'INFO'), pakeColor::colorize($xmlfile, 'INFO')); } } } } unset($form->fields); unset($form->tree); unset($form); printf("xmlform: %s has %s fields and %s exceptions \n", pakeColor::colorize($xmlfile, 'INFO'), pakeColor::colorize($fieldsIndex, 'INFO'), pakeColor::colorize($exceptIndex, 'INFO')); $exceptIndexTotal += $exceptIndex; } fclose($fp); printf("added %s entries from translation table\n", pakeColor::colorize($trIndex, 'INFO')); printf("added %s entries from %s xmlforms \n", pakeColor::colorize($fieldsIndexTotal, 'INFO'), pakeColor::colorize($xmlIndex, 'INFO')); if ($trError > 0) { printf("there are %s errors in tranlation table\n", pakeColor::colorize($trError, 'ERROR')); } if ($xmlError > 0) { printf("there are %s errors and %s exceptions in xmlforms\n", pakeColor::colorize($xmlError, 'ERROR'), pakeColor::colorize($exceptIndexTotal, 'ERROR')); } exit(0); //to do: leer los html templates }
/** * Retrieve object using using composite pkey values. * @param string $trn_category @param string $trn_id @param string $trn_lang * @param Connection $con * @return Translation */ public static function retrieveByPK($trn_category, $trn_id, $trn_lang, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } $criteria = new Criteria(); $criteria->add(TranslationPeer::TRN_CATEGORY, $trn_category); $criteria->add(TranslationPeer::TRN_ID, $trn_id); $criteria->add(TranslationPeer::TRN_LANG, $trn_lang); $v = TranslationPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }
/** * Retrieve object using using composite pkey values. * @param string $language_id * @param string $string_key * @param PropelPDO $con * @return Translation */ public static function retrieveByPK($language_id, $string_key, PropelPDO $con = null) { $_instancePoolKey = serialize(array((string) $language_id, (string) $string_key)); if (null !== ($obj = TranslationPeer::getInstanceFromPool($_instancePoolKey))) { return $obj; } if ($con === null) { $con = Propel::getConnection(TranslationPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $criteria = new Criteria(TranslationPeer::DATABASE_NAME); $criteria->add(TranslationPeer::LANGUAGE_ID, $language_id); $criteria->add(TranslationPeer::STRING_KEY, $string_key); $v = TranslationPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }