diff options
Diffstat (limited to 'l10ntools')
-rw-r--r-- | l10ntools/Executable_localize.mk | 1 | ||||
-rw-r--r-- | l10ntools/Executable_propex.mk | 1 | ||||
-rw-r--r-- | l10ntools/Executable_ulfex.mk | 1 | ||||
-rw-r--r-- | l10ntools/inc/export.hxx | 2 | ||||
-rw-r--r-- | l10ntools/inc/helper.hxx | 5 | ||||
-rwxr-xr-x | l10ntools/inc/po.hxx | 3 | ||||
-rw-r--r-- | l10ntools/inc/xrmmerge.hxx | 3 | ||||
-rw-r--r-- | l10ntools/source/export.cxx | 85 | ||||
-rw-r--r-- | l10ntools/source/helper.cxx | 43 | ||||
-rw-r--r-- | l10ntools/source/merge.cxx | 14 | ||||
-rwxr-xr-x | l10ntools/source/po.cxx | 100 | ||||
-rw-r--r-- | l10ntools/source/stringmerge.cxx | 7 | ||||
-rw-r--r-- | l10ntools/source/xrmmerge.cxx | 29 |
13 files changed, 99 insertions, 195 deletions
diff --git a/l10ntools/Executable_localize.mk b/l10ntools/Executable_localize.mk index b673289d9d4e..cdc323a36386 100644 --- a/l10ntools/Executable_localize.mk +++ b/l10ntools/Executable_localize.mk @@ -45,6 +45,7 @@ $(eval $(call gb_Executable_add_exception_objects,localize,\ $(eval $(call gb_Executable_use_externals,localize,\ boost_headers \ + libxml2 \ )) # vim:set noet sw=4 ts=4: diff --git a/l10ntools/Executable_propex.mk b/l10ntools/Executable_propex.mk index c5bb06ddbdd4..c359061fd094 100644 --- a/l10ntools/Executable_propex.mk +++ b/l10ntools/Executable_propex.mk @@ -30,6 +30,7 @@ $(eval $(call gb_Executable_add_exception_objects,propex,\ $(eval $(call gb_Executable_use_externals,propex,\ boost_headers \ + libxml2 \ )) # vim: set noet sw=4 ts=4: diff --git a/l10ntools/Executable_ulfex.mk b/l10ntools/Executable_ulfex.mk index bd7b7a5c1877..0212d7db96ca 100644 --- a/l10ntools/Executable_ulfex.mk +++ b/l10ntools/Executable_ulfex.mk @@ -46,6 +46,7 @@ $(eval $(call gb_Executable_add_exception_objects,ulfex,\ $(eval $(call gb_Executable_use_externals,ulfex,\ boost_headers \ + libxml2 \ )) # vim:set noet sw=4 ts=4: diff --git a/l10ntools/inc/export.hxx b/l10ntools/inc/export.hxx index 9575dcda564e..0a2c10ef3532 100644 --- a/l10ntools/inc/export.hxx +++ b/l10ntools/inc/export.hxx @@ -240,6 +240,7 @@ private: void ResData2Output( PFormEntrys *pEntry, sal_uInt16 nType, const OString& rTextType ); void MergeRest( ResData *pResData, sal_uInt16 nMode = MERGE_MODE_NORMAL ); void ConvertMergeContent( OString &rText ); + void ConvertExportContent( OString &rText ); void WriteToMerged(const OString &rText , bool bSDFContent); void SetChildWithText(); @@ -296,7 +297,6 @@ public: bTitleFirst[ rId ] = true; } sal_Bool GetText( OString &rReturn, sal_uInt16 nTyp, const OString &nLangIndex, sal_Bool bDel = sal_False ); - sal_Bool GetTransex3Text( OString &rReturn, sal_uInt16 nTyp, const OString &nLangIndex, sal_Bool bDel = sal_False ); }; diff --git a/l10ntools/inc/helper.hxx b/l10ntools/inc/helper.hxx index 1292f44ec957..9ec399647c49 100644 --- a/l10ntools/inc/helper.hxx +++ b/l10ntools/inc/helper.hxx @@ -25,6 +25,11 @@ namespace helper { +OString escapeAll( + const OString& rText, const OString& rUnEscaped, const OString& rEscaped ); +OString unEscapeAll( + const OString& rText, const OString& rEscaped, const OString& rUnEscaped ); + OString QuotHTML( const OString &rString ); OString UnQuotHTML( const OString& rString ); diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index 5ffad8e48554..26bbedf94623 100755 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -61,9 +61,6 @@ public: OString getMsgStr() const; bool isFuzzy() const; OString getKeyId() const; - void setMsgId(const OString& rMsgId); - void setMsgStr(const OString& rMsgStr); - void setFuzzy(const bool bFuzzy); static bool IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2); diff --git a/l10ntools/inc/xrmmerge.hxx b/l10ntools/inc/xrmmerge.hxx index ca6a820c4dc4..9e5fbae65d07 100644 --- a/l10ntools/inc/xrmmerge.hxx +++ b/l10ntools/inc/xrmmerge.hxx @@ -59,9 +59,6 @@ protected: OString GetGID() { return sGID; } OString GetLID() { return sLID; } - void ConvertStringToDBFormat( OString &rString ); - void ConvertStringToXMLFormat( OString &rString ); - public: XRMResParser(); virtual ~XRMResParser(); diff --git a/l10ntools/source/export.cxx b/l10ntools/source/export.cxx index d5ee143954e8..a61cf135335a 100644 --- a/l10ntools/source/export.cxx +++ b/l10ntools/source/export.cxx @@ -22,6 +22,7 @@ #include <cstddef> #include <cstring> +#include "helper.hxx" #include "boost/scoped_ptr.hpp" #include <stdio.h> #include <stdlib.h> @@ -954,6 +955,11 @@ sal_Bool Export::WriteData( ResData *pResData, sal_Bool bCreateNew ) if (sXText.isEmpty()) sXText = "-"; + ConvertExportContent(sXText); + ConvertExportContent(sXHText); + ConvertExportContent(sXQHText); + ConvertExportContent(sXTitle); + common::writePoEntry( "Transex3", *aOutput.mPo, global::inputPathname, pResData->sResTyp, sGID, sLID, sXHText, sXText); @@ -1070,6 +1076,7 @@ sal_Bool Export::WriteExportList(ResData *pResData, ExportList *pExportList, if( sText == "\\\"" ) sText = "\""; } + ConvertExportContent(sText); common::writePoEntry( "Transex3", *aOutput.mPo, global::inputPathname, rTyp, sGID, sLID, OString(), sText); @@ -1316,68 +1323,28 @@ void Export::ConvertMergeContent( OString &rText ) /*****************************************************************************/ { sal_Bool bNoOpen = ( rText.indexOf( "\\\"" ) != 0 ); - sal_Bool bNoClose = !rText.endsWithL(RTL_CONSTASCII_STRINGPARAM("\\\"")); - OStringBuffer sNew; - for ( sal_Int32 i = 0; i < rText.getLength(); i++ ) - { - OString sChar( rText[i]); - if (sChar.equalsL(RTL_CONSTASCII_STRINGPARAM("\\"))) - { - if (( i + 1 ) < rText.getLength()) - { - sal_Char cNext = rText[i + 1]; - if ( cNext == '\"' ) - { - sChar = OString('\"'); - i++; - } - else if ( cNext == 'n' ) - { - sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\n")); - i++; - } - else if ( cNext == 't' ) - { - sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\t")); - i++; - } - else if ( cNext == '\'' ) - { - sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\\'")); - i++; - } - else - { - sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\\\")); - } - } - else - { - sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\\\")); - } - } - else if (sChar.equalsL(RTL_CONSTASCII_STRINGPARAM("\""))) - { - sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\\"")); - } - else if (sChar.equalsL(RTL_CONSTASCII_STRINGPARAM(""))) - { - sChar = OString(RTL_CONSTASCII_STRINGPARAM("\\0x7F")); - } - sNew.append(sChar); - } + sal_Bool bNoClose = !rText.endsWith("\\\""); - rText = sNew.makeStringAndClear(); - if ( bNoOpen ) { - OString sTmp( rText ); - rText = "\""; - rText += sTmp; - } + rText = rText.replaceAll("\\\"'","\'"); /// Temporary: until PO files contain escaped single quotes + /// (Maybe next PO update solve this) + rText = + helper::escapeAll( + rText.replaceAll("","\\0x7F"), + "\n""\t""\\""\"","\\n""\\t""\\\\""\\\""); + + if ( bNoOpen ) + rText = "\"" + rText; + if ( bNoClose ) rText += "\""; } +void Export::ConvertExportContent( OString& rText ) +{ + rText = helper::unEscapeAll(rText,"\\n""\\t""\\\\""\\\"","\n""\t""\\""\""); +} + sal_Bool Export::PrepareTextToMerge(OString &rText, sal_uInt16 nTyp, OString &rLangIndex, ResData *pResData) { @@ -1539,7 +1506,7 @@ sal_Bool Export::PrepareTextToMerge(OString &rText, sal_uInt16 nTyp, } OString sContent; - pEntrys->GetTransex3Text(sContent, nTyp, rLangIndex); + pEntrys->GetText(sContent, nTyp, rLangIndex); if (sContent.isEmpty() && !rLangIndex.equalsIgnoreAsciiCase("en-US")) { rText = sOrigText; @@ -1573,7 +1540,7 @@ void Export::ResData2Output( PFormEntrys *pEntry, sal_uInt16 nType, const OStrin sCur = aLanguages[ n ]; OString sText; - sal_Bool bText = pEntry->GetTransex3Text( sText, nType, sCur , sal_True ); + sal_Bool bText = pEntry->GetText( sText, nType, sCur , sal_True ); if ( bText && !sText.isEmpty() && sText != "-" ) { OString sOutput; if ( bNextMustBeDefineEOL) { @@ -1772,7 +1739,7 @@ void Export::MergeRest( ResData *pResData, sal_uInt16 nMode ) OString sText; sal_Bool bText = false; if ( pEntrys ) - bText = pEntrys->GetTransex3Text( sText, STRING_TYP_TEXT, sCur, sal_True ); + bText = pEntrys->GetText( sText, STRING_TYP_TEXT, sCur, sal_True ); if ( bText && !sText.isEmpty() ) { sal_Int32 nStart, nEnd; diff --git a/l10ntools/source/helper.cxx b/l10ntools/source/helper.cxx index 69163d0e38ae..6c3a04559078 100644 --- a/l10ntools/source/helper.cxx +++ b/l10ntools/source/helper.cxx @@ -11,6 +11,49 @@ namespace helper { +OString escapeAll( + const OString& rText, const OString& rUnEscaped, const OString& rEscaped ) +{ + assert( rEscaped.getLength() == 2*rUnEscaped.getLength() ); + OStringBuffer sReturn; + for ( sal_Int32 nIndex = 0; nIndex < rText.getLength(); ++nIndex ) + { + sal_Int32 nUnEscapedOne = rUnEscaped.indexOf(rText[nIndex]); + if( nUnEscapedOne != -1 ) + { + sReturn.append(rEscaped.copy(nUnEscapedOne*2,2)); + } + else + sReturn.append(rText[nIndex]); + } + return sReturn.makeStringAndClear(); +} + + +OString unEscapeAll( + const OString& rText, const OString& rEscaped, const OString& rUnEscaped) +{ + assert( rEscaped.getLength() == 2*rUnEscaped.getLength() ); + OStringBuffer sReturn; + const sal_Int32 nLength = rText.getLength(); + for ( sal_Int32 nIndex = 0; nIndex < nLength; ++nIndex ) + { + if( rText[nIndex] == '\\' && nIndex+1 < nLength ) + { + sal_Int32 nEscapedOne = rEscaped.indexOf(rText.copy(nIndex,2)); + if( nEscapedOne != -1 ) + { + sReturn.append(rUnEscaped[nEscapedOne/2]); + ++nIndex; + } + } + else + sReturn.append(rText[nIndex]); + } + return sReturn.makeStringAndClear(); +} + + OString QuotHTML(const OString &rString) { OStringBuffer sReturn; diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index d3bd71b04196..3487030b52a9 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -165,20 +165,6 @@ ResData::~ResData() // class PFormEntrys // -sal_Bool PFormEntrys::GetTransex3Text( OString &rReturn, - sal_uInt16 nTyp, const OString &nLangIndex, sal_Bool bDel ) -{ - sal_Bool rc = GetText( rReturn , nTyp , nLangIndex , bDel ); - for( sal_Int32 idx = 0; idx < rReturn.getLength(); idx++ ) - { - if( rReturn[idx] == '\"' && ( idx >= 1 ) && rReturn[idx-1] == '\\' ) - { - rReturn = rReturn.replaceAt( idx-1, 1, OString() ); - } - } - return rc; -} -/*****************************************************************************/ sal_Bool PFormEntrys::GetText( OString &rReturn, sal_uInt16 nTyp, const OString &nLangIndex, sal_Bool bDel ) { diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index bbfe0633bab6..34f3eeb10de7 100755 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -19,9 +19,7 @@ #include <boost/crc.hpp> #include "po.hxx" - -#define POESCAPED OString("\\n\\t\\r\\\\\\\"") -#define POUNESCAPED OString("\n\t\r\\\"") +#include "helper.hxx" /** Container of po entry @@ -85,49 +83,16 @@ public: namespace { - //Escape text - static OString lcl_EscapeText(const OString& rText, - const OString& rUnEscaped= POUNESCAPED, - const OString& rEscaped = POESCAPED) - { - assert( rEscaped.getLength() == 2*rUnEscaped.getLength() ); - OString sResult = rText; - int nCount = 0; - for(sal_Int32 nIndex=0; nIndex<rText.getLength(); ++nIndex) - { - sal_Int32 nActChar = rUnEscaped.indexOf(rText[nIndex]); - if(nActChar!=-1) - sResult = sResult.replaceAt((nIndex)+(nCount++),1, - rEscaped.copy(2*nActChar,2)); - } - return sResult; - } - - //Unescape text - static OString lcl_UnEscapeText(const OString& rText, - const OString& rEscaped = POESCAPED, - const OString& rUnEscaped = POUNESCAPED) - { - assert( rEscaped.getLength() == 2*rUnEscaped.getLength() ); - OString sResult = rText; - int nCount = 0; - for(sal_Int32 nIndex=0; nIndex<rText.getLength()-1; ++nIndex) - { - sal_Int32 nActChar = rEscaped.indexOf(rText.copy(nIndex,2)); - if(nActChar % 2 == 0) - sResult = sResult.replaceAt((nIndex++)-(nCount++),2, - rUnEscaped.copy(nActChar/2,1)); - } - return sResult; - } - //Convert a normal string to msg/po output string static OString lcl_GenMsgString(const OString& rString) { if ( rString.isEmpty() ) return "\"\""; - OString sResult = "\"" + lcl_EscapeText(rString) + "\""; + OString sResult = + "\"" + + helper::escapeAll(rString,"\n""\t""\r""\\""\"","\\n""\\t""\\r""\\\\""\\\"") + + "\""; sal_Int32 nIndex = 0; while((nIndex=sResult.indexOf("\\n",nIndex))!=-1) { @@ -148,7 +113,11 @@ namespace //Convert msg string to normal form static OString lcl_GenNormString(const OString& rString) { - return lcl_UnEscapeText(rString.copy(1,rString.getLength()-2)); + return + helper::unEscapeAll( + rString.copy(1,rString.getLength()-2), + "\\n""\\t""\\r""\\\\""\\\"", + "\n""\t""\r""\\""\""); } } @@ -273,26 +242,6 @@ namespace sKeyId[5] = '\0'; return OString(sKeyId); } - - //Unescape merge string - static OString lcl_UnEscapeMergeText( - const OString& rText,const bool bHelpText = false ) - { - if ( bHelpText ) - return rText; - else - return lcl_UnEscapeText(rText,"\\n\\t\\r","\n\t\r"); - } - - //Escape to get merge string - static OString lcl_EscapeMergeText( - const OString& rText,const bool bHelpText = false ) - { - if ( bHelpText ) - return rText; - else - return lcl_EscapeText(rText,"\n\t\r","\\n\\t\\r"); - } } //Default constructor @@ -338,15 +287,12 @@ PoEntry::PoEntry( only three element*/ } m_pGenPo->setMsgCtxt(sMsgCtxt); - m_pGenPo->setMsgId( - lcl_UnEscapeMergeText( - rText,rSourceFile.endsWith(".xhp"))); + m_pGenPo->setMsgId(rText); m_pGenPo->setExtractCom( ( !rHelpText.isEmpty() ? rHelpText + "\n" : OString( "" )) + lcl_GenKeyId( m_pGenPo->getReference() + sMsgCtxt + m_pGenPo->getMsgId() ) ); m_bIsInitialized = true; - } //Destructor @@ -468,35 +414,15 @@ OString PoEntry::getKeyId() const OString PoEntry::getMsgId() const { assert( m_bIsInitialized ); - return - lcl_EscapeMergeText( - m_pGenPo->getMsgId(), getSourceFile().endsWith(".xhp") ); + return m_pGenPo->getMsgId(); } //Get translated string in merge format OString PoEntry::getMsgStr() const { assert( m_bIsInitialized ); - return - lcl_EscapeMergeText( - m_pGenPo->getMsgStr(), getSourceFile().endsWith(".xhp") ); - -} + return m_pGenPo->getMsgStr(); -//Set translated string when input is in merge format -void PoEntry::setMsgStr(const OString& rMsgStr) -{ - assert( m_bIsInitialized ); - m_pGenPo->setMsgStr( - lcl_UnEscapeMergeText( - rMsgStr,getSourceFile().endsWith(".xhp"))); -} - -//Set fuzzy flag -void PoEntry::setFuzzy(const bool bFuzzy) -{ - assert( m_bIsInitialized ); - m_pGenPo->setFuzzy(bFuzzy); } //Check whether po-s belong to the same localization component diff --git a/l10ntools/source/stringmerge.cxx b/l10ntools/source/stringmerge.cxx index b81ea71f4d05..bc2057aae1ab 100644 --- a/l10ntools/source/stringmerge.cxx +++ b/l10ntools/source/stringmerge.cxx @@ -70,11 +70,12 @@ void StringParser::Extract( const OString& rPOFile ) { xmlChar* pID = xmlGetProp(pCurrent, (const xmlChar*)("name")); xmlChar* pText = xmlNodeGetContent(pCurrent); - + const OString sTemp = + helper::unEscapeAll(helper::xmlStrToOString( pText ),"\\n""\\t","\n""\t"); common::writePoEntry( "Stringex", aPOStream, m_pSource->name, "string", helper::xmlStrToOString( pID ), OString(), OString(), - helper::xmlStrToOString( pText )); + sTemp); xmlFree( pID ); xmlFree( pText ); @@ -131,7 +132,7 @@ void StringParser::Merge( { OString sNewText; pEntrys->GetText( sNewText, STRING_TYP_TEXT, m_sLang ); - sNewText = sNewText.replaceAll("\'","\\\'").replaceAll("\"","\\\""); + sNewText = helper::escapeAll(sNewText, "\n""\t""\'""\"","\\n""\\t""\\\'""\\\""); xmlNodeSetContent( pCurrent, xmlEncodeSpecialChars( NULL, diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx index 04fccfbf9484..458beacc5f28 100644 --- a/l10ntools/source/xrmmerge.cxx +++ b/l10ntools/source/xrmmerge.cxx @@ -313,20 +313,6 @@ void XRMResParser::Error( const OString &rError ) yyerror(( char * ) rError.getStr()); } -/*****************************************************************************/ -void XRMResParser::ConvertStringToDBFormat( OString &rString ) -/*****************************************************************************/ -{ - rString = rString.trim().replaceAll("\t", "\\t"); -} - -/*****************************************************************************/ -void XRMResParser::ConvertStringToXMLFormat( OString &rString ) -/*****************************************************************************/ -{ - rString = rString.replaceAll("\\t", "\t"); -} - // // class XMLResExport // @@ -377,7 +363,7 @@ void XRMResExport::WorkOnDesc( file.read (memblock, size); file.close(); memblock[size] = '\0'; - rText = OString(memblock).replaceAll("\n", "\\n"); + rText = OString(memblock); delete[] memblock; } WorkOnText( rOpenTag, rText ); @@ -395,13 +381,9 @@ void XRMResExport::WorkOnText( if ( !pResData ) { - OString sPlatform( "" ); - pResData = new ResData( sPlatform, GetGID() ); + pResData = new ResData( OString(), GetGID() ); } - - OString sText(rText); - ConvertStringToDBFormat(sText); - pResData->sText[sLang] = sText; + pResData->sText[sLang] = rText; } /*****************************************************************************/ @@ -418,8 +400,7 @@ void XRMResExport::EndOfText( { sCur = aLanguages[ n ]; - OString sAct( - pResData->sText[sCur].replaceAll("\x0A", OString())); + OString sAct = pResData->sText[sCur]; if( !sAct.isEmpty() ) common::writePoEntry( @@ -528,7 +509,6 @@ void XRMResMerge::WorkOnDesc( } OString sOutputDescFile( sOutputFile.copy(0, i + 1) + sLocDescFilename); - sText = sText.replaceAll("\\n", "\n"); ofstream file(sOutputDescFile.getStr()); if (file.is_open()) { file << sText.getStr(); @@ -573,7 +553,6 @@ void XRMResMerge::WorkOnText( helper::isWellFormedXML( sContent )) { rText = sContent; - ConvertStringToXMLFormat( rText ); } } } |