diff options
author | Zolnai Tamás <zolnaitamas2000@gmail.com> | 2012-12-18 17:53:29 +0100 |
---|---|---|
committer | Zolnai Tamás <zolnaitamas2000@gmail.com> | 2012-12-19 15:49:53 +0100 |
commit | 95ea6cb21a7d7f4f163e642ba4b1e165a427a0d1 (patch) | |
tree | fb3807384aa67bb14c5c68ed3ad04ec0851edfe1 | |
parent | bee957fc48867aa1b98b8672b02a187a461f4e38 (diff) |
Fix localization of modified lists
Two cases:
1. The items of PairedList have unique id so it works well
when change order of items. Thus when there is no poentry
for some of the items than use the original strings.
2. The items of other lists have only an order number as id
so when order changes than id changes too, which means
poentries do not match with original items. To avoid
pointless lists fill the whole list with english items.
Actually it is a rare case when only the order change,
at most time it goes hand in hand with changing of count
so use that to decide when use original list. This whole
translation ignorance lasts until next po update.
Plus delete one call of MegreRest() function because
it was called twice for some macro defined strings.
Change-Id: I4b34a1831991608583f53e1885c4eb2aea605493
-rw-r--r-- | l10ntools/source/export.cxx | 221 |
1 files changed, 119 insertions, 102 deletions
diff --git a/l10ntools/source/export.cxx b/l10ntools/source/export.cxx index 13870da558a2..831d893f00fb 100644 --- a/l10ntools/source/export.cxx +++ b/l10ntools/source/export.cxx @@ -322,11 +322,8 @@ int Export::Execute( int nToken, const char * pToken ) if ( nToken != RSCDEFINELEND ) { // end of macro found, so destroy res. bDefine = sal_False; - if ( bMergeMode ) { - MergeRest( pResData ); - } - bNextMustBeDefineEOL = sal_False; Execute( LEVELDOWN, "" ); + bNextMustBeDefineEOL = sal_False; } else { // next line also in macro definition @@ -1686,125 +1683,145 @@ void Export::MergeRest( ResData *pResData, sal_uInt16 nMode ) std::size_t nMaxIndex = 0; if ( pList ) nMaxIndex = pList->GetSourceLanguageListEntryCount(); + + /** + * Check whether count of listentries match with count + * of translated items. If not than write origin items + * to the list to avoid mixed translations + * (exclude pairedlist) + */ + sal_Bool bTranslateList = true; + if( !bPairedList ){ + pResData->sId = OString::valueOf(static_cast<sal_Int32>(nMaxIndex)); + pEntrys = pMergeDataFile->GetPFormEntrys( pResData ); + if ( !pEntrys ) + bTranslateList = false; + pResData->sId = OString::valueOf(static_cast<sal_Int32>(nMaxIndex+1)); + pEntrys = pMergeDataFile->GetPFormEntrys( pResData ); + if ( pEntrys ) + bTranslateList = false; + pResData->sId = "1"; + } + pEntrys = pMergeDataFile->GetPFormEntrys( pResData ); - while( pEntrys && ( nLIndex < nMaxIndex )) { - rtl::OString sText; - sal_Bool bText; - bText = pEntrys->GetTransex3Text( sText, STRING_TYP_TEXT, sCur, sal_True ); - if( !bText ) - bText = pEntrys->GetTransex3Text( sText , STRING_TYP_TEXT, SOURCE_LANGUAGE , sal_False ); - - if ( bText && !sText.isEmpty()) + while(( nLIndex < nMaxIndex )) { + if ( nIdx == 1 ) { - if ( nIdx == 1 ) + rtl::OStringBuffer sHead; + if ( bNextMustBeDefineEOL ) + sHead.append(RTL_CONSTASCII_STRINGPARAM("\\\n\t")); + sHead.append(sSpace); + switch ( nT ) + { + case LIST_STRING: + sHead.append(RTL_CONSTASCII_STRINGPARAM("StringList ")); + break; + case LIST_FILTER: + sHead.append(RTL_CONSTASCII_STRINGPARAM("FilterList ")); + break; + case LIST_ITEM: + sHead.append(RTL_CONSTASCII_STRINGPARAM("ItemList ")); + break; + case LIST_PAIRED: + sHead.append(RTL_CONSTASCII_STRINGPARAM("PairedList ")); + break; + case LIST_UIENTRIES: + sHead.append(RTL_CONSTASCII_STRINGPARAM("UIEntries ")); + break; + } + sHead.append(RTL_CONSTASCII_STRINGPARAM("[ ")); + sHead.append(sCur); + sHead.append(RTL_CONSTASCII_STRINGPARAM(" ] ")); + if ( bDefine || bNextMustBeDefineEOL ) { - rtl::OStringBuffer sHead; - if ( bNextMustBeDefineEOL ) - sHead.append(RTL_CONSTASCII_STRINGPARAM("\\\n\t")); + sHead.append(RTL_CONSTASCII_STRINGPARAM("= \\\n")); sHead.append(sSpace); - switch ( nT ) - { - case LIST_STRING: - sHead.append(RTL_CONSTASCII_STRINGPARAM("StringList ")); - break; - case LIST_FILTER: - sHead.append(RTL_CONSTASCII_STRINGPARAM("FilterList ")); - break; - case LIST_ITEM: - sHead.append(RTL_CONSTASCII_STRINGPARAM("ItemList ")); - break; - case LIST_PAIRED: - sHead.append(RTL_CONSTASCII_STRINGPARAM("PairedList ")); - break; - case LIST_UIENTRIES: - sHead.append(RTL_CONSTASCII_STRINGPARAM("UIEntries ")); - break; - } - sHead.append(RTL_CONSTASCII_STRINGPARAM("[ ")); - sHead.append(sCur); - sHead.append(RTL_CONSTASCII_STRINGPARAM(" ] ")); - //} - if ( bDefine || bNextMustBeDefineEOL ) - { - sHead.append(RTL_CONSTASCII_STRINGPARAM("= \\\n")); - sHead.append(sSpace); - sHead.append(RTL_CONSTASCII_STRINGPARAM("\t{\\\n\t")); - } - else - { - sHead.append(RTL_CONSTASCII_STRINGPARAM("= \n")); - sHead.append(sSpace); - sHead.append(RTL_CONSTASCII_STRINGPARAM("\t{\n\t")); - } - WriteToMerged(sHead.makeStringAndClear() , true); + sHead.append(RTL_CONSTASCII_STRINGPARAM("\t{\\\n\t")); } - rtl::OString sLine; - if ( pList && (*pList)[ nLIndex ] ) - sLine = ( *(*pList)[ nLIndex ])[ SOURCE_LANGUAGE ]; - if ( sLine.isEmpty()) - sLine = sLastListLine; - - if ( sLastListLine.indexOf( '<' ) != -1 ) { - if (( nT != LIST_UIENTRIES ) && - (( sLine.indexOf( '{' ) == -1 ) || - ( sLine.indexOf( '{' ) >= sLine.indexOf( '"' ))) && - (( sLine.indexOf( '<' ) == -1 ) || - ( sLine.indexOf( '<' ) >= sLine.indexOf( '"' )))) - { - sLine = sLine.replaceFirst("\"", "< \"" ); - } + else + { + sHead.append(RTL_CONSTASCII_STRINGPARAM("= \n")); + sHead.append(sSpace); + sHead.append(RTL_CONSTASCII_STRINGPARAM("\t{\n\t")); } - - sal_Int32 nStart, nEnd; - nStart = sLine.indexOf( '"' ); - - rtl::OString sPostFix; - if( !bPairedList ){ - nEnd = sLine.lastIndexOf( '"' ); - sPostFix = sLine.copy( ++nEnd ); - sLine = sLine.copy(0, nStart); + WriteToMerged(sHead.makeStringAndClear() , true); + } + rtl::OString sLine; + if ( pList && (*pList)[ nLIndex ] ) + sLine = ( *(*pList)[ nLIndex ])[ SOURCE_LANGUAGE ]; + if ( sLine.isEmpty()) + sLine = sLastListLine; + + if ( sLastListLine.indexOf( '<' ) != -1 ) { + if (( nT != LIST_UIENTRIES ) && + (( sLine.indexOf( '{' ) == -1 ) || + ( sLine.indexOf( '{' ) >= sLine.indexOf( '"' ))) && + (( sLine.indexOf( '<' ) == -1 ) || + ( sLine.indexOf( '<' ) >= sLine.indexOf( '"' )))) + { + sLine = sLine.replaceFirst("\"", "< \"" ); } + } + if( bTranslateList ) + { + OString sText; + sal_Bool bText = false; + if ( pEntrys ) + bText = pEntrys->GetTransex3Text( sText, STRING_TYP_TEXT, sCur, sal_True ); + if ( bText && !sText.isEmpty() ) + { + sal_Int32 nStart, nEnd; + nStart = sLine.indexOf( '"' ); + + rtl::OString sPostFix; + if( !bPairedList ){ + nEnd = sLine.lastIndexOf( '"' ); + sPostFix = sLine.copy( ++nEnd ); + sLine = sLine.copy(0, nStart); + } - ConvertMergeContent( sText ); - // merge new res. in text line - if( bPairedList ){ - sLine = MergePairedList( sLine , sText ); - } - else{ - sLine += sText; - sLine += sPostFix; - } + ConvertMergeContent( sText ); - rtl::OString sText1( "\t" ); - sText1 += sLine; - if ( bDefine || bNextMustBeDefineEOL ) - sText1 += " ;\\\n"; - else - sText1 += " ;\n"; - sText1 += sSpace; - sText1 += "\t"; - WriteToMerged( sText1 ,true ); + // merge new res. in text line + if( bPairedList ){ + sLine = MergePairedList( sLine , sText ); + } + else{ + sLine += sText; + sLine += sPostFix; + } + } + } + rtl::OString sText1( "\t" ); + sText1 += sLine; + if ( bDefine || bNextMustBeDefineEOL ) + sText1 += " ;\\\n"; + else + sText1 += " ;\n"; + sText1 += sSpace; + sText1 += "\t"; + WriteToMerged( sText1 ,true ); + nIdx++; + if ( bTranslateList ) + { // Set matching pairedlist identifier if ( bPairedList ){ - nIdx++; ExportListEntry* pListE = ( ExportListEntry* )(*pResData->pPairedList)[ ( nIdx ) -1 ]; if( pListE ){ pResData->sId = GetPairedListID ( (*pListE)[ SOURCE_LANGUAGE ] ); } } else - pResData->sId = rtl::OString::valueOf(static_cast<sal_Int32>(++nIdx)); + pResData->sId = rtl::OString::valueOf(static_cast<sal_Int32>(nIdx)); + PFormEntrys *oldEntry = pEntrys; + pEntrys = pMergeDataFile->GetPFormEntrys( pResData ); + if( !pEntrys ) + pEntrys = oldEntry; } - else - break; - nLIndex ++; - PFormEntrys *oldEntry = pEntrys; - pEntrys = pMergeDataFile->GetPFormEntrys( pResData ); - if( !pEntrys ) - pEntrys = oldEntry; + nLIndex++; } if ( nIdx > 1 ) { rtl::OString sFooter; |