Fixed translation upgrade.

This commit is contained in:
Alexandre Rosenfeld
2011-02-02 15:42:12 +00:00
parent b8e1e6ef13
commit 1781d7cc9f
4 changed files with 31 additions and 20 deletions

View File

@@ -160,9 +160,11 @@ function run_info($args, $opts) {
function run_workspace_upgrade($args, $opts) {
$workspaces = get_workspaces_from_args($args);
$first = true;
foreach ($workspaces as $workspace) {
try {
$workspace->upgrade();
$workspace->upgrade($first);
$first = false;
} catch (Exception $e) {
echo "Errors upgrading workspace " . info($workspace->name) . ": " . error($e->getMessage()) . "\n";
}
@@ -171,12 +173,12 @@ function run_workspace_upgrade($args, $opts) {
function run_translation_upgrade($args, $opts) {
$workspaces = get_workspaces_from_args($args);
$updateXml = true;
$first = true;
foreach ($workspaces as $workspace) {
try {
echo "Upgrading translation for " . pakeColor::colorize($workspace->name, "INFO") . "\n";
$workspace->upgradeTranslation($updateXml);
$updateXml = false;
$workspace->upgradeTranslation($first);
$first = false;
} catch (Exception $e) {
echo "Errors upgrading translation of workspace " . info($workspace->name) . ": " . error($e->getMessage()) . "\n";
}
@@ -185,7 +187,6 @@ function run_translation_upgrade($args, $opts) {
function run_cacheview_upgrade($args, $opts) {
$workspaces = get_workspaces_from_args($args);
$updateXml = true;
foreach ($workspaces as $workspace) {
try {
echo "Upgrading cache view for " . pakeColor::colorize($workspace->name, "INFO") . "\n";

View File

@@ -243,7 +243,7 @@ class languages {
}
public function importLanguage($sLanguageFile, $updateXml = true)
public function importLanguage($sLanguageFile, $updateXml = true, $updateDB = true)
{
try {
G::LoadSystem('i18n_po');
@@ -294,16 +294,17 @@ class languages {
$reference = $POFile->references[0];
if( $identifier == 'TRANSLATION') {
list($category, $id) = explode('/', $context);
$result = $oTranslation->addTranslation(
$category,
$id,
$LOCALE,
trim(str_replace(chr(10), '', stripslashes($rowTranslation['msgstr'])))
);
if( $result['codError'] == 0 )
$countItemsSuccess++;
if ($updateDB) {
list($category, $id) = explode('/', $context);
$result = $oTranslation->addTranslation(
$category,
$id,
$LOCALE,
trim(str_replace(chr(10), '', stripslashes($rowTranslation['msgstr'])))
);
if( $result['codError'] == 0 )
$countItemsSuccess++;
}
} else if( $updateXml ){
$xmlForm = $context;
$codes = explode('-', $reference);

View File

@@ -150,7 +150,7 @@ class System {
public static function listPoFiles() {
$folders = glob(PATH_CORE . '/content/translations/*');
$items = glob(PATH_CORE . '/content/*.po');
$items = glob(PATH_CORE . '/content/translations/*.po');
foreach ($folders as $folder) {
if (is_dir($folder)) {
$add = glob($folder . "/*.po");

View File

@@ -256,14 +256,23 @@ class workspaceTools {
*
* @param bool $updateXml if true, update the xmlforms
*/
public function upgradeTranslation($updateXml = true) {
public function upgradeTranslation($first = true) {
$this->initPropel(true);
G::LoadClass('languages');
G::LoadThirdParty('pear/json', 'class.json');
$languages = new languages();
foreach (System::listPoFiles() as $poFile) {
CLI::logging("Updating language ".basename($poFile)."\n");
$languages->importLanguage($poFile, $updateXml);
$poName = basename($poFile);
$names = explode(".", basename($poFile));
$extension = array_pop($names);
$langid = array_pop($names);
if (strcasecmp($langid, "en") == 0) {
CLI::logging("Updating database translations with $poName\n");
$languages->importLanguage($poFile, false, true);
} else if ($first) {
CLI::logging("Updating XML form translations with $poName\n");
$languages->importLanguage($poFile, true, false);
}
}
}