Add file translation Mafe

This commit is contained in:
Marco Antonio Nina
2014-04-10 12:30:51 -04:00
parent d4c2700c75
commit 0c28857ab0
4 changed files with 62 additions and 5 deletions

View File

@@ -330,10 +330,10 @@ class workspaceTools
$extension = array_pop($names);
$langid = array_pop($names);
CLI::logging("Updating database translations with $poName\n");
Language::import($poFile, false, true);
Language::import($poFile, false, true, false);
if ($first) {
CLI::logging("Updating XML form translations with $poName\n");
Language::import($poFile, true, false);
Language::import($poFile, true, false, true);
}
}
}

View File

@@ -148,7 +148,7 @@ class Language extends BaseLanguage
* @param string $bXml
* @return void
*/
public function import ($sLanguageFile, $updateXml = true, $updateDB = true)
public function import ($sLanguageFile, $updateXml = true, $updateDB = true, $generateMafe = true)
{
try {
G::LoadSystem( 'i18n_po' );
@@ -288,6 +288,11 @@ class Language extends BaseLanguage
$trn->addTranslationEnvironment( $LOCALE, $POHeaders, $countItemsSuccess );
}
if ($generateMafe) {
$trn = new Translation();
$trn->generateFileTranslationMafe();
}
//fill the results
$results = new stdClass();
$results->recordsCount = $countItems;

View File

@@ -169,6 +169,7 @@ class Translation extends BaseTranslation
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" );
@@ -178,7 +179,7 @@ class Translation extends BaseTranslation
//$json = new Services_JSON(); DEPRECATED
$f = fopen( $cacheFileJS, 'w' );
if ($f == false) {
error_log("Error: Cannot write into cachefilejs: $cacheFileJS\n");
error_log("Error: Cannot write into cachefilejs: $cacheFileJS\n");
} else {
fwrite( $f, "var G_STRINGS =" . Bootstrap::json_encode( $translationJS ) . ";\n");
fclose( $f );
@@ -194,6 +195,55 @@ class Translation extends BaseTranslation
}
}
/* Load strings from a Database for labels MAFE.
*
*/
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 {
if (! is_dir( dirname( $mafeFolder ) )) {
G::mk_dir( dirname( $mafeFolder, 0777 ) );
}
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();
}
}
/**
* returns an array with
* codError 0 - no error, < 0 error

View File

@@ -63,8 +63,10 @@
</script>
<script type="text/javascript" src="/lib/js/mafe-{$buildhash}.js"></script>
{/if}
<!-- translations -->
<script type="text/javascript" src="/translations/translationsMafe.js"></script>
</head>
<body onresize="resizingFrame();">
<section class="navBar">