From 2fea6f45f56445ba0dfb09ab070e1e9615c5b9f1 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 21 Jul 2014 03:24:18 +0200 Subject: [PATCH] Make sure a correct hash is not used for untranslated strings. --HG-- branch : gsoc2014-dfighter --- .../translation_manager/uxt_editor.cpp | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/code/studio/src/plugins/translation_manager/uxt_editor.cpp b/code/studio/src/plugins/translation_manager/uxt_editor.cpp index 38f8fa76d..1ea22870d 100644 --- a/code/studio/src/plugins/translation_manager/uxt_editor.cpp +++ b/code/studio/src/plugins/translation_manager/uxt_editor.cpp @@ -62,10 +62,12 @@ public: UXTEditorPvt() { t = new QTableWidget(); + loadedFromWK = false; } QTableWidget *t; std::vector< STRING_MANAGER::TStringInfo > infos; + bool loadedFromWK; }; @@ -92,7 +94,7 @@ void UXTEditor::open( QString filename ) QString lang = getLang( filename ); infos.clear(); - STRING_MANAGER::loadStringFile( filename.toUtf8().constData(), infos, true ); + STRING_MANAGER::loadStringFile( filename.toUtf8().constData(), infos, false ); if( d_ptr->infos.size() == 0 ) { @@ -113,6 +115,8 @@ void UXTEditor::open( QString filename ) STRING_MANAGER::loadStringFile( fn.toUtf8().constData(), infos, true ); if( d_ptr->infos.size() == 0 ) return; + + d_ptr->loadedFromWK = true; } blockTableSignals( true ); @@ -168,8 +172,25 @@ void UXTEditor::saveAs( QString filename ) std::vector< STRING_MANAGER::TStringInfo >::const_iterator itr = d_ptr->infos.begin(); while( itr != d_ptr->infos.end() ) { + uint64 hash = 0; + + // If text2 is not empty we can assume the string was translated, so we store with the correct hash + // If text2 is empty, it wasn't translated so we can just use the old hash. + // Additionally, if the strings were loaded from the wk.uxt file, we use a hash of 0 so we know it was not translated + if( itr->Text2.empty() ) + { + if( d_ptr->loadedFromWK ) + hash = 0; + else + hash = itr->HashValue; + } + else + { + hash = NLMISC::CI18N::makeHash( itr->Text2 ); + } + QString hashLine = "// HASH_VALUE "; - hashLine += QString( NLMISC::CI18N::hashToString( itr->HashValue ).c_str() ).toUpper(); + hashLine += QString( NLMISC::CI18N::hashToString( hash ).c_str() ).toUpper(); hashLine += "\r\n"; QString idxLine = "// INDEX "; @@ -181,7 +202,12 @@ void UXTEditor::saveAs( QString filename ) trLine += itr->Identifier.c_str(); trLine += "\t"; trLine += "["; - trLine += itr->Text.toUtf8().c_str(); + + if( itr->Text2.empty() ) + trLine += itr->Text.toUtf8().c_str(); + else + trLine += itr->Text2.toUtf8().c_str(); + trLine += "]"; trLine += "\r\n"; @@ -282,7 +308,7 @@ void UXTEditor::onCellChanged( int row, int column ) info.Identifier = item->text().toUtf8().constData(); else if( column == 1 ) - info.Text = item->text().toUtf8().constData(); + info.Text2 = item->text().toUtf8().constData(); setWindowModified( true ); }