diff options
author | Zolnai Tamás <zolnaitamas2000@gmail.com> | 2013-04-20 09:20:31 +0200 |
---|---|---|
committer | Zolnai Tamás <zolnaitamas2000@gmail.com> | 2013-04-21 18:57:17 +0200 |
commit | 36b3bcefcf13996610239f95b1dce9f291bde95d (patch) | |
tree | 4796801ca25a41422381fce137fee5c21f3fef64 /l10ntools/source | |
parent | 8560c2df78072533007b84b31fc930b82191e9a3 (diff) |
Some changes in qtz handling
Executalbes, which work one language, generat qtz by own.
(stringex,helpex,treex,propex)
So these executables can generate qtz without po file
when use them with qtz, call them with "-m" flag without parameter.
Change-Id: I56c34db7151dc3ef0ce1c85ed607719e4cbb5e92
Diffstat (limited to 'l10ntools/source')
-rw-r--r-- | l10ntools/source/common.cxx | 2 | ||||
-rw-r--r-- | l10ntools/source/helpex.cxx | 22 | ||||
-rw-r--r-- | l10ntools/source/helpmerge.cxx | 83 | ||||
-rw-r--r-- | l10ntools/source/merge.cxx | 33 | ||||
-rwxr-xr-x | l10ntools/source/po.cxx | 89 | ||||
-rw-r--r-- | l10ntools/source/propmerge.cxx | 46 | ||||
-rw-r--r-- | l10ntools/source/stringmerge.cxx | 56 | ||||
-rw-r--r-- | l10ntools/source/treemerge.cxx | 51 |
8 files changed, 218 insertions, 164 deletions
diff --git a/l10ntools/source/common.cxx b/l10ntools/source/common.cxx index 304f44c224bf..b143a7c8e4cf 100644 --- a/l10ntools/source/common.cxx +++ b/l10ntools/source/common.cxx @@ -37,6 +37,7 @@ bool handleArguments( else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-M" ) { nState = STATE_MERGESRC; // next token specifies the merge database + o_aHandledArgs.m_bMergeMode = true; } else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-L" ) { @@ -63,7 +64,6 @@ bool handleArguments( case STATE_MERGESRC: { o_aHandledArgs.m_sMergeSrc = OString( argv[i] ); - o_aHandledArgs.m_bMergeMode = true; } break; case STATE_LANGUAGES: diff --git a/l10ntools/source/helpex.cxx b/l10ntools/source/helpex.cxx index b1486553a67e..5c6156f95c86 100644 --- a/l10ntools/source/helpex.cxx +++ b/l10ntools/source/helpex.cxx @@ -40,7 +40,7 @@ void WriteUsage() << " Syntax: Helpex -[m]i FileIn -o FileOut [-m DataBase] [-l Lang]\n" << " FileIn + i: Source file (*.xhp)\n" << " FileIn + -mi: File including paths of source files" - << " (only for merge)" + << " (only for merge)\n" << " FileOut: Destination file (*.*) or files (in case of -mi)\n" << " DataBase: Mergedata (*.po)\n" << " Lang: Restrict the handled languages; one element of\n" @@ -79,8 +79,11 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { std::cerr << "Helpex error: cannot open input file\n"; return 1; } - MergeDataFile aMergeDataFile( - aArgs.m_sMergeSrc, OString(), false, false ); + MergeDataFile* pMergeDataFile = 0; + if( aArgs.m_sLanguage != "qtz") + { + pMergeDataFile = new MergeDataFile(aArgs.m_sMergeSrc, OString(), false, false ); + } std::string sTemp; aInput >> sTemp; while( !aInput.eof() ) @@ -91,23 +94,28 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { aArgs.m_sOutputFile + sXhpFile.copy( sXhpFile.lastIndexOf("/") )); if( !aParser.Merge( aArgs.m_sMergeSrc, sOutput, - aArgs.m_sLanguage, aMergeDataFile )) + aArgs.m_sLanguage, pMergeDataFile )) { hasNoError = false; } aInput >> sTemp; } aInput.close(); + delete pMergeDataFile; } else { HelpParser aParser( aArgs.m_sInputFile ); - MergeDataFile aMergeDataFile( - aArgs.m_sMergeSrc, aArgs.m_sInputFile, false, false ); + MergeDataFile* pMergeDataFile = 0; + if( aArgs.m_sLanguage != "qtz") + { + pMergeDataFile = new MergeDataFile(aArgs.m_sMergeSrc, aArgs.m_sInputFile, false, false ); + } hasNoError = aParser.Merge( aArgs.m_sMergeSrc, aArgs.m_sOutputFile, - aArgs.m_sLanguage, aMergeDataFile ); + aArgs.m_sLanguage, pMergeDataFile ); + delete pMergeDataFile; } } else diff --git a/l10ntools/source/helpmerge.cxx b/l10ntools/source/helpmerge.cxx index 71ad315a7b48..69bde372f75d 100644 --- a/l10ntools/source/helpmerge.cxx +++ b/l10ntools/source/helpmerge.cxx @@ -147,7 +147,7 @@ bool HelpParser::CreatePO( } bool HelpParser::Merge( const OString &rPOFile, const OString &rDestinationFile, - const OString& rLanguage , MergeDataFile& aMergeDataFile ) + const OString& rLanguage , MergeDataFile* pMergeDataFile ) { (void) rPOFile; @@ -159,12 +159,12 @@ bool HelpParser::Merge( const OString &rPOFile, const OString &rDestinationFile, //TODO: explicit BOM handling? XMLFile* xmlfile = ( aParser.Execute( sXmlFile, new XMLFile( OUString('0') ) ) ); - bool hasNoError = MergeSingleFile( xmlfile , aMergeDataFile , rLanguage , rDestinationFile ); + bool hasNoError = MergeSingleFile( xmlfile , pMergeDataFile , rLanguage , rDestinationFile ); delete xmlfile; return hasNoError; } -bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile& aMergeDataFile , const OString& sLanguage , +bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile* pMergeDataFile , const OString& sLanguage , OString const & sPath ) { file->Extract(); @@ -187,7 +187,7 @@ bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile& aMergeDataFile pResData.sGId = pos->first; pResData.sFilename = sHelpFile; - ProcessHelp( aLangHM , sLanguage, &pResData , aMergeDataFile ); + ProcessHelp( aLangHM , sLanguage, &pResData , pMergeDataFile ); } file->Write(sPath); @@ -195,7 +195,7 @@ bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile& aMergeDataFile } /* ProcessHelp Methode: search for en-US entry and replace it with the current language*/ -void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResData *pResData , MergeDataFile& aMergeDataFile ){ +void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResData *pResData , MergeDataFile* pMergeDataFile ){ XMLElement* pXMLElement = NULL; MergeEntrys *pEntrys = NULL; @@ -215,46 +215,51 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResDa sLId = pXMLElement->GetOldref(); pResData->sId = sLId; - pEntrys = aMergeDataFile.GetMergeEntrys( pResData ); - if( pEntrys != NULL) + OString sNewText; + OUString sNewdata; + OUString sSourceText( + pXMLElement->ToOUString(). + replaceAll( + OUString("\n"), + OUString()). + replaceAll( + OUString("\t"), + OUString())); + // re-add spaces to the beginning of translated string, + // important for indentation of Basic code examples + sal_Int32 nPreSpaces = 0; + sal_Int32 nLen = sSourceText.getLength(); + while ( (nPreSpaces < nLen) && (*(sSourceText.getStr()+nPreSpaces) == ' ') ) + nPreSpaces++; + if( sCur == "qtz" ) { - OString sNewText; - OUString sSourceText( - pXMLElement->ToOUString(). - replaceAll( - OUString("\n"), - OUString()). - replaceAll( - OUString("\t"), - OUString())); - // re-add spaces to the beginning of translated string, - // important for indentation of Basic code examples - sal_Int32 nPreSpaces = 0; - sal_Int32 nLen = sSourceText.getLength(); - while ( (nPreSpaces < nLen) && (*(sSourceText.getStr()+nPreSpaces) == ' ') ) - nPreSpaces++; - pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur , true ); - OUString sNewdata; - OUString sTemp = OStringToOUString(sNewText, RTL_TEXTENCODING_UTF8); - if (helper::isWellFormedXML(OUStringToOString(XMLUtil::QuotHTML(sTemp),RTL_TEXTENCODING_UTF8))) - { - sNewdata = sSourceText.copy(0,nPreSpaces) + sTemp; - } - else - { - sNewdata = sSourceText; - } - if (!sNewdata.isEmpty()) + const OString sOriginText = OUStringToOString(sSourceText, RTL_TEXTENCODING_UTF8); + sNewText = MergeEntrys::GetQTZText(*pResData, sOriginText); + sNewdata = OStringToOUString(sNewText, RTL_TEXTENCODING_UTF8); + } + else if( pMergeDataFile ) + { + pEntrys = pMergeDataFile->GetMergeEntrys( pResData ); + if( pEntrys != NULL) { - if( pXMLElement != NULL ) + pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur , true ); + OUString sTemp = OStringToOUString(sNewText, RTL_TEXTENCODING_UTF8); + if (helper::isWellFormedXML(OUStringToOString(XMLUtil::QuotHTML(sTemp),RTL_TEXTENCODING_UTF8))) { - XMLData *data = new XMLData( sNewdata , NULL , true ); // Add new one - pXMLElement->RemoveAndDeleteAllChildren(); - pXMLElement->AddChild( data ); - aLangHM->erase( sCur ); + sNewdata = sSourceText.copy(0,nPreSpaces) + sTemp; } } } + if (!sNewdata.isEmpty()) + { + if( pXMLElement != NULL ) + { + XMLData *data = new XMLData( sNewdata , NULL , true ); // Add new one + pXMLElement->RemoveAndDeleteAllChildren(); + pXMLElement->AddChild( data ); + aLangHM->erase( sCur ); + } + } else if( pResData == NULL ) { fprintf(stdout,"Can't find GID=%s LID=%s TYP=%s\n", diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index 1555adb1d9eb..401cba5f347c 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -187,6 +187,14 @@ sal_Bool MergeEntrys::GetText( OString &rReturn, } +OString MergeEntrys::GetQTZText(const ResData& rResData, const OString& rOrigText) +{ + const OString sFilename = rResData.sFilename.copy(rResData.sFilename.lastIndexOf("/")+1); + const OString sKey = + PoEntry::genKeyId(sFilename + rResData.sGId + rResData.sId + rResData.sResTyp + rOrigText); + return sKey + "||" + rOrigText; +} + // // class MergeData // @@ -278,9 +286,6 @@ MergeDataFile::MergeDataFile( OString sExText; OString sExQHText; OString sExTitle; - OString sQTZText; - OString sQTZQHText; - OString sQTZTitle; do { if( bInSameComp ) @@ -293,17 +298,14 @@ MergeDataFile::MergeDataFile( case PoEntry::TTEXT: sText = sTemp; sExText = aActPo.getMsgId(); - sQTZText = aActPo.getKeyId(); break; case PoEntry::TQUICKHELPTEXT: sQHText = sTemp; sExQHText = aActPo.getMsgId(); - sQTZQHText = aActPo.getKeyId(); break; case PoEntry::TTITLE: sTitle = sTemp; sExTitle = aActPo.getMsgId(); - sQTZTitle = aActPo.getKeyId(); break; } if( !lcl_ReadPoChecked(aNextPo, aPoInput, sPoFileName) ) @@ -325,8 +327,8 @@ MergeDataFile::MergeDataFile( InsertEntry( aActPo.getResourceType(), aActPo.getGroupId(), aActPo.getLocalId(), "qtz", - sQTZText + "||" + sExText, sQTZQHText + "||" + sExQHText, - sQTZTitle + "||" + sExTitle, aActPo.getSourceFile(), + sExText, sExQHText, + sExTitle, aActPo.getSourceFile(), bCaseSensitive ); } } @@ -374,7 +376,6 @@ MergeData *MergeDataFile::GetMergeData( ResData *pResData , bool bCaseSensitive return NULL; } - MergeEntrys *MergeDataFile::GetMergeEntrys( ResData *pResData ) { // search for requested MergeEntrys @@ -418,7 +419,19 @@ void MergeDataFile::InsertEntry( // insert the cur string MergeEntrys *pMergeEntrys = pData->GetMergeEntries(); - pMergeEntrys->InsertEntry( nLANG , rTEXT, rQHTEXT, rTITLE ); + if( nLANG =="qtz" ) + { + const OString sTemp = rInFilename + rGID + rLID + rTYP; + pMergeEntrys->InsertEntry( + nLANG, + rTEXT.isEmpty()? rTEXT : PoEntry::genKeyId(sTemp + rTEXT) + "||" + rTEXT, + rQHTEXT.isEmpty()? rQHTEXT : PoEntry::genKeyId(sTemp + rQHTEXT) + "||" + rQHTEXT, + rTITLE.isEmpty()? rTITLE : PoEntry::genKeyId(sTemp + rTITLE) + "||" + rTITLE ); + } + else + { + pMergeEntrys->InsertEntry( nLANG , rTEXT, rQHTEXT, rTITLE ); + } } OString MergeDataFile::CreateKey(const OString& rTYP, const OString& rGID, diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 34f3eeb10de7..030950a2fe42 100755 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -222,28 +222,6 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) //Class PoEntry -namespace -{ - //Generate KeyId - static OString lcl_GenKeyId(const OString& rGenerator) - { - boost::crc_32_type aCRC32; - aCRC32.process_bytes(rGenerator.getStr(), rGenerator.getLength()); - sal_uInt32 nCRC = aCRC32.checksum(); - ///Use simple ASCII characters, exclude I, l, 1 and O, 0 to avoid confusing IDs - static const OString sSymbols = - "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789"; - char sKeyId[6]; - for( short nKeyInd = 0; nKeyInd < 5; ++nKeyInd ) - { - sKeyId[nKeyInd] = sSymbols[(nCRC & 63) % sSymbols.getLength()]; - nCRC >>= 6; - } - sKeyId[5] = '\0'; - return OString(sKeyId); - } -} - //Default constructor PoEntry::PoEntry() : m_pGenPo( 0 ) @@ -290,8 +268,7 @@ PoEntry::PoEntry( m_pGenPo->setMsgId(rText); m_pGenPo->setExtractCom( ( !rHelpText.isEmpty() ? rHelpText + "\n" : OString( "" )) + - lcl_GenKeyId( - m_pGenPo->getReference() + sMsgCtxt + m_pGenPo->getMsgId() ) ); + genKeyId( m_pGenPo->getReference() + rGroupId + rLocalId + rResType + rText ) ); m_bIsInitialized = true; } @@ -435,6 +412,25 @@ bool PoEntry::IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2) rPo1.getResourceType() == rPo2.getResourceType() ); } +OString PoEntry::genKeyId(const OString& rGenerator) +{ + boost::crc_32_type aCRC32; + aCRC32.process_bytes(rGenerator.getStr(), rGenerator.getLength()); + sal_uInt32 nCRC = aCRC32.checksum(); + ///Use simple ASCII characters, exclude I, l, 1 and O, 0 to avoid confusing IDs + static const OString sSymbols = + "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789"; + char sKeyId[6]; + for( short nKeyInd = 0; nKeyInd < 5; ++nKeyInd ) + { + sKeyId[nKeyInd] = sSymbols[(nCRC & 63) % sSymbols.getLength()]; + nCRC >>= 6; + } + sKeyId[5] = '\0'; + return OString(sKeyId); +} + + //Class PoHeader namespace @@ -538,6 +534,26 @@ void PoOfstream::writeEntry( const PoEntry& rPoEntry ) //Class PoIfstream +namespace +{ + +static bool lcl_CheckInputEntry(const GenPoEntry& rEntry) +{ + const OString sMsgCtxt = rEntry.getMsgCtxt(); + const sal_Int32 nFirstEndLine = sMsgCtxt.indexOf('\n'); + const sal_Int32 nLastEndLine = sMsgCtxt.lastIndexOf('\n'); + const sal_Int32 nLastDot = sMsgCtxt.lastIndexOf('.'); + const OString sType = sMsgCtxt.copy( nLastDot + 1 ); + return !rEntry.getReference().isEmpty() && + nFirstEndLine > 0 && + (nLastEndLine == nFirstEndLine || nLastEndLine == sMsgCtxt.indexOf('\n',nFirstEndLine+1)) && + nLastDot - nLastEndLine > 1 && + (sType == "text" || sType == "quickhelptext" || sType == "title")&& + !rEntry.getMsgId().isEmpty(); +} + +} + PoIfstream::PoIfstream() : m_aInPut() , m_bEof( false ) @@ -592,31 +608,8 @@ void PoIfstream::readEntry( PoEntry& rPoEntry ) } else { - const OString sMsgCtxt = aGenPo.getMsgCtxt(); - const sal_Int32 nFirstEndLine = sMsgCtxt.indexOf('\n'); - const sal_Int32 nLastEndLine = sMsgCtxt.lastIndexOf('\n'); - const sal_Int32 nLastDot = sMsgCtxt.lastIndexOf('.'); - const OString sType = sMsgCtxt.copy( nLastDot + 1 ); - if( !aGenPo.getReference().isEmpty() && - nFirstEndLine > 0 && - (nLastEndLine == nFirstEndLine || - nLastEndLine == sMsgCtxt.indexOf('\n',nFirstEndLine+1)) && - nLastDot - nLastEndLine > 1 && - (sType == "text" || sType == "quickhelptext" || sType == "title")&& - !aGenPo.getMsgId().isEmpty() ) + if( lcl_CheckInputEntry(aGenPo) ) { - //Generate keyid if po file not includes it - const OString sExtractCom = aGenPo.getExtractCom(); - if( sExtractCom.isEmpty() || - ( sExtractCom.getLength() != 4 && - sExtractCom.indexOf("\n") == -1 ) ) - { - aGenPo.setExtractCom( - ( !sExtractCom.isEmpty() ? sExtractCom + "\n" : OString( "" )) + - lcl_GenKeyId( - aGenPo.getReference() + sMsgCtxt + - aGenPo.getMsgId() ) ); - } if( rPoEntry.m_pGenPo ) { *(rPoEntry.m_pGenPo) = aGenPo; diff --git a/l10ntools/source/propmerge.cxx b/l10ntools/source/propmerge.cxx index 386fa43f56ff..cdbe9d2243f8 100644 --- a/l10ntools/source/propmerge.cxx +++ b/l10ntools/source/propmerge.cxx @@ -166,19 +166,21 @@ void PropParser::Merge( const OString &rMergeSrc, const OString &rDestinationFil return; } - MergeDataFile aMergeDataFile( - rMergeSrc, m_sSource, false, m_sLang == "qtz" ); - - const std::vector<OString> vLanguages = aMergeDataFile.GetLanguages(); - if( m_sLang != "qtz" && vLanguages.size()>=2 && - vLanguages[vLanguages[0]!="qtz" ? 0 : 1] != m_sLang ) + MergeDataFile* pMergeDataFile = 0; + if( m_sLang != "qtz" ) { - std::cerr - << "Propex error: given language conflicts with " - << "language of Mergedata file: " - << m_sLang.getStr() << " - " - << vLanguages[vLanguages[0]!="qtz" ? 0 : 1].getStr() << std::endl; - return; + pMergeDataFile = new MergeDataFile( rMergeSrc, m_sSource, false, false ); + + const std::vector<OString> vLanguages = pMergeDataFile->GetLanguages(); + if( vLanguages.size()>=1 && vLanguages[0] != m_sLang ) + { + std::cerr + << "Propex error: given language conflicts with " + << "language of Mergedata file: " + << m_sLang.getStr() << " - " + << vLanguages[0].getStr() << std::endl; + return; + } } for( unsigned nIndex = 0; nIndex < m_vLines.size(); ++nIndex ) @@ -191,11 +193,22 @@ void PropParser::Merge( const OString &rMergeSrc, const OString &rDestinationFil const OString sID( sLine.copy( 0, sLine.indexOf("=") ).trim() ); ResData aResData( sID, m_sSource ); aResData.sResTyp = "property"; - MergeEntrys* pEntrys = aMergeDataFile.GetMergeEntrys( &aResData ); - if( pEntrys ) + OString sNewText; + if( m_sLang == "qtz" ) + { + const OString sOriginText = lcl_ConvertToUTF8(sLine.copy( nEqualSign + 1 ).trim()); + sNewText = MergeEntrys::GetQTZText(aResData, sOriginText); + } + else if( pMergeDataFile ) + { + MergeEntrys* pEntrys = pMergeDataFile->GetMergeEntrys( &aResData ); + if( pEntrys ) + { + pEntrys->GetText( sNewText, STRING_TYP_TEXT, m_sLang ); + } + } + if( !sNewText.isEmpty() ) { - OString sNewText; - pEntrys->GetText( sNewText, STRING_TYP_TEXT, m_sLang ); aDestination << OString(sID + "=").getStr(); lcl_PrintJavaStyle( sNewText, aDestination ); aDestination << std::endl; @@ -211,6 +224,7 @@ void PropParser::Merge( const OString &rMergeSrc, const OString &rDestinationFil } } aDestination.close(); + delete pMergeDataFile; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/l10ntools/source/stringmerge.cxx b/l10ntools/source/stringmerge.cxx index 40fe6c2439ce..6ceb4b7a401d 100644 --- a/l10ntools/source/stringmerge.cxx +++ b/l10ntools/source/stringmerge.cxx @@ -94,23 +94,21 @@ void StringParser::Merge( { assert( m_bIsInitialized ); - if( (m_sLang == "en-US") || (m_sLang == "qtz") ) + MergeDataFile* pMergeDataFile = 0; + if( m_sLang != "qtz" ) { - return; - } - - MergeDataFile aMergeDataFile( - rMergeSrc, static_cast<OString>( m_pSource->name ), false ); - const std::vector<OString> vLanguages = aMergeDataFile.GetLanguages(); - if( vLanguages.size()>=2 && - vLanguages[vLanguages[0]=="qtz" ? 1 : 0] != m_sLang ) - { - std::cerr - << "stringex error: given language conflicts with " - << "language of Mergedata file: " - << m_sLang.getStr() << " - " - << vLanguages[vLanguages[0]=="qtz" ? 1 : 0].getStr() << std::endl; - return; + pMergeDataFile = new MergeDataFile( + rMergeSrc, static_cast<OString>( m_pSource->name ), false, false ); + const std::vector<OString> vLanguages = pMergeDataFile->GetLanguages(); + if( vLanguages.size()>=1 && vLanguages[0] != m_sLang ) + { + std::cerr + << "stringex error: given language conflicts with " + << "language of Mergedata file: " + << m_sLang.getStr() << " - " + << vLanguages[0].getStr() << std::endl; + return; + } } xmlNodePtr pRootNode = xmlDocGetRootElement( m_pSource ); //<resource> @@ -126,13 +124,26 @@ void StringParser::Merge( static_cast<OString>(m_pSource->name) ); xmlFree( pID ); aResData.sResTyp = "string"; - MergeEntrys* pEntrys = - (&aMergeDataFile)->GetMergeEntrys( &aResData ); - if( pEntrys ) + OString sNewText; + if( m_sLang == "qtz" ) + { + xmlChar* pText = xmlNodeGetContent(pCurrent); + const OString sOriginText = + helper::unEscapeAll(helper::xmlStrToOString( pText ),"\\n""\\t","\n""\t"); + xmlFree( pText ); + sNewText = MergeEntrys::GetQTZText(aResData, sOriginText); + } + else if( pMergeDataFile ) + { + MergeEntrys* pEntrys = pMergeDataFile->GetMergeEntrys( &aResData ); + if( pEntrys ) + { + pEntrys->GetText( sNewText, STRING_TYP_TEXT, m_sLang ); + sNewText = helper::escapeAll(sNewText, "\n""\t""\'""\"","\\n""\\t""\\\'""\\\""); + } + } + if( !sNewText.isEmpty() ) { - OString sNewText; - pEntrys->GetText( sNewText, STRING_TYP_TEXT, m_sLang ); - sNewText = helper::escapeAll(sNewText, "\n""\t""\'""\"","\\n""\\t""\\\'""\\\""); xmlNodeSetContent( pCurrent, xmlEncodeSpecialChars( NULL, @@ -142,6 +153,7 @@ void StringParser::Merge( } } + delete pMergeDataFile; xmlSaveFile( rDestinationFile.getStr(), m_pSource ); xmlFreeDoc( m_pSource ); xmlCleanupParser(); diff --git a/l10ntools/source/treemerge.cxx b/l10ntools/source/treemerge.cxx index d80203df459a..2870a2e7b5b9 100644 --- a/l10ntools/source/treemerge.cxx +++ b/l10ntools/source/treemerge.cxx @@ -153,25 +153,39 @@ namespace { if( !xmlStrcmp(pCurrent->name, pNodeName) ) { - if( pMergeDataFile ) + if( rLang != "en-US" ) { + OString sNewText; xmlChar* pID = xmlGetProp(pCurrent, (const xmlChar*)("id")); ResData aResData( helper::xmlStrToOString( pID ), static_cast<OString>(io_pSource->name) ); xmlFree( pID ); aResData.sResTyp = helper::xmlStrToOString( pNodeName ); - MergeEntrys* pEntrys = - pMergeDataFile->GetMergeEntrys( &aResData ); - if( pEntrys ) + if( pMergeDataFile ) + { + MergeEntrys* pEntrys = + pMergeDataFile->GetMergeEntrys( &aResData ); + if( pEntrys ) + { + pEntrys->GetText( sNewText, STRING_TYP_TEXT, rLang ); + } + } + else if( rLang == "qtz" ) + { + xmlChar* pText = xmlGetProp(pCurrent, (const xmlChar*)("title")); + const OString sOriginText = helper::xmlStrToOString(pText); + xmlFree( pText ); + sNewText = MergeEntrys::GetQTZText(aResData, sOriginText); + } + if( !sNewText.isEmpty() ) { - OString sNewText; - pEntrys->GetText( sNewText, STRING_TYP_TEXT, rLang ); xmlSetProp( pCurrent, (const xmlChar*)("title"), (const xmlChar*)(sNewText.getStr())); } } + lcl_MergeLevel( io_pSource, pCurrent, (const xmlChar *)("node"), pMergeDataFile, rLang, rXhpRoot ); @@ -242,32 +256,27 @@ void TreeParser::Merge( assert( m_bIsInitialized ); const xmlNodePtr pRootNode = xmlDocGetRootElement( m_pSource ); - if( m_sLang == "en-US" ) - { - lcl_MergeLevel( - m_pSource, pRootNode, (const xmlChar *)("help_section"), - 0, m_sLang, rXhpRoot ); - } - else + MergeDataFile* pMergeDataFile = 0; + if( m_sLang != "qtz" && m_sLang != "en-US" ) { - MergeDataFile aMergeDataFile( + pMergeDataFile = new MergeDataFile( rMergeSrc, static_cast<OString>( m_pSource->name ), false, false ); - const std::vector<OString> vLanguages = aMergeDataFile.GetLanguages(); - if( vLanguages.size()>=2 && - vLanguages[vLanguages[0]=="qtz" ? 1 : 0] != m_sLang ) + const std::vector<OString> vLanguages = pMergeDataFile->GetLanguages(); + if( vLanguages.size()>=1 && vLanguages[0] != m_sLang ) { std::cerr << "Treex error: given language conflicts with " << "language of Mergedata file: " << m_sLang.getStr() << " - " - << vLanguages[vLanguages[0]=="qtz" ? 1 : 0].getStr() << std::endl; + << vLanguages[0].getStr() << std::endl; return; } - lcl_MergeLevel( - m_pSource, pRootNode, (const xmlChar *)("help_section"), - &aMergeDataFile, m_sLang, rXhpRoot ); } + lcl_MergeLevel( + m_pSource, pRootNode, (const xmlChar *)("help_section"), + pMergeDataFile, m_sLang, rXhpRoot ); + delete pMergeDataFile; xmlSaveFile( rDestinationFile.getStr(), m_pSource ); xmlFreeDoc( m_pSource ); xmlCleanupParser(); |