diff options
author | Andras Timar <atimar@suse.com> | 2011-09-30 23:47:55 +0200 |
---|---|---|
committer | Andras Timar <atimar@suse.com> | 2011-09-30 23:49:38 +0200 |
commit | a91a7567e7a2ee3db87b0f9a9523be3f55ac93b2 (patch) | |
tree | 026fcc3d011b90235f8925db0c31f593f556b1bb | |
parent | ca2235e871582fe3957d4d18173bb033d1384cd8 (diff) |
extract strings for l10n from description.xml files
Merging is to be implemented...
-rw-r--r-- | l10ntools/inc/tokens.h | 12 | ||||
-rw-r--r-- | l10ntools/source/xrmlex.l | 25 | ||||
-rw-r--r-- | l10ntools/source/xrmmerge.cxx | 105 |
3 files changed, 134 insertions, 8 deletions
diff --git a/l10ntools/inc/tokens.h b/l10ntools/inc/tokens.h index 8898f348b4dd..0c69d0e65621 100644 --- a/l10ntools/inc/tokens.h +++ b/l10ntools/inc/tokens.h @@ -98,6 +98,18 @@ #define XRM_TEXT_END 508 #define XML_TEXTCHAR 600 +/*------------------------------------------------------ */ +/*------------------------------------------------------ */ +/* Tokens for parsing description.xml files */ +/*------------------------------------------------------ */ +/*------------------------------------------------------ */ +#define DESC_DISPLAY_NAME_START 700 +#define DESC_DISPLAY_NAME_END 701 +#define DESC_TEXT_START 702 +#define DESC_TEXT_END 703 +#define DESC_EXTENSION_DESCRIPTION_START 704 +#define DESC_EXTENSION_DESCRIPTION_END 705 +#define DESC_EXTENSION_DESCRIPTION_SRC 706 #endif diff --git a/l10ntools/source/xrmlex.l b/l10ntools/source/xrmlex.l index de5b5dfa9a37..b7dccbd3d8f5 100644 --- a/l10ntools/source/xrmlex.l +++ b/l10ntools/source/xrmlex.l @@ -99,8 +99,33 @@ int bText=0; WorkOnTokenSet( XRM_TEXT_END, yytext ); } +"<display-name>" { + WorkOnTokenSet( DESC_DISPLAY_NAME_START , yytext ); +} + +"</display-name>" { + WorkOnTokenSet( DESC_DISPLAY_NAME_END, yytext ); +} +"<name "[^\>]*lang[^\>]*\> { + WorkOnTokenSet( DESC_TEXT_START , yytext ); +} + +"</name>" { + WorkOnTokenSet( DESC_TEXT_END, yytext ); +} +"<extension-description>" { + WorkOnTokenSet( DESC_EXTENSION_DESCRIPTION_START , yytext ); +} + +"</extension-description>" { + WorkOnTokenSet( DESC_EXTENSION_DESCRIPTION_END , yytext ); +} + +"<src "[^\>]*lang[^\>]*\> { + WorkOnTokenSet( DESC_EXTENSION_DESCRIPTION_SRC , yytext ); +} diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx index a17ecf2c34a6..8a0ca9881c22 100644 --- a/l10ntools/source/xrmmerge.cxx +++ b/l10ntools/source/xrmmerge.cxx @@ -37,6 +37,7 @@ #include "xrmmerge.hxx" #include "tokens.h" #include <iostream> +#include <fstream> #include <vector> using namespace std; @@ -59,12 +60,16 @@ sal_Bool bEnableExport; sal_Bool bMergeMode; sal_Bool bErrorLog; sal_Bool bUTF8; +sal_Bool bDisplayName; +sal_Bool bExtensionDescription; ByteString sPrj; ByteString sPrjRoot; ByteString sInputFileName; ByteString sActFileName; ByteString sOutputFile; ByteString sMergeSrc; +ByteString sLangAttribute; +ByteString sResourceType; String sUsedTempFile; XRMResParser *pParser = NULL; @@ -79,6 +84,8 @@ extern char *GetOutputFile( int argc, char* argv[]) bMergeMode = sal_False; bErrorLog = sal_True; bUTF8 = sal_True; + bDisplayName = sal_False; + bExtensionDescription = sal_False; sPrj = ""; sPrjRoot = ""; sInputFileName = ""; @@ -296,34 +303,115 @@ int XRMResParser::Execute( int nToken, char * pToken ) switch ( nToken ) { case XRM_TEXT_START:{ - //printf("->XRM_TEXT_START\n"); ByteString sNewLID = GetAttribute( rToken, "id" ); if ( sNewLID != sLID ) { - //EndOfText( sCurrentOpenTag, sCurrentCloseTag ); sLID = sNewLID; } bText = sal_True; sCurrentText = ""; sCurrentOpenTag = rToken; Output( rToken ); - //printf("<-XRM_TEXT_START\n"); } break; case XRM_TEXT_END: { sCurrentCloseTag = rToken; - //printf("->XRM_TEXT_END\n"); - ByteString sLang = GetAttribute( sCurrentOpenTag, "xml:lang" ); + sResourceType = ByteString ( "readmeitem" ); + sLangAttribute = ByteString ( "xml:lang" ); + ByteString sLang = GetAttribute( sCurrentOpenTag, sLangAttribute ); WorkOnText( sCurrentOpenTag, sCurrentText ); Output( sCurrentText ); EndOfText( sCurrentOpenTag, sCurrentCloseTag ); bText = sal_False; rToken = ByteString(""); sCurrentText = ByteString(""); - //printf("<-XRM_TEXT_END"); } break; + case DESC_DISPLAY_NAME_START:{ + bDisplayName = sal_True; + } + break; + + case DESC_DISPLAY_NAME_END:{ + bDisplayName = sal_False; + } + break; + + case DESC_TEXT_START:{ + if (bDisplayName) { + sLID = ByteString("dispname"); + bText = sal_True; + sCurrentText = ""; + sCurrentOpenTag = rToken; + Output( rToken ); + } + } + break; + + case DESC_TEXT_END: { + if (bDisplayName) { + sCurrentCloseTag = rToken; + sResourceType = ByteString ( "description" ); + sLangAttribute = ByteString ( "lang" ); + ByteString sLang = GetAttribute( sCurrentOpenTag, sLangAttribute ); + WorkOnText( sCurrentOpenTag, sCurrentText ); + Output( sCurrentText ); + EndOfText( sCurrentOpenTag, sCurrentCloseTag ); + bText = sal_False; + rToken = ByteString(""); + sCurrentText = ByteString(""); + } + } + break; + + case DESC_EXTENSION_DESCRIPTION_START: { + bExtensionDescription = sal_True; + } + break; + + case DESC_EXTENSION_DESCRIPTION_END: { + bExtensionDescription = sal_False; + } + break; + + case DESC_EXTENSION_DESCRIPTION_SRC: { + if (bExtensionDescription) { + sLID = ByteString("extdesc"); + sResourceType = ByteString ( "description" ); + sLangAttribute = ByteString ( "lang" ); + sCurrentOpenTag = rToken; + sCurrentText = ByteString(""); + Output( rToken ); + DirEntry aEntry( String( sInputFileName, RTL_TEXTENCODING_ASCII_US )); + aEntry.ToAbs(); + ByteString sDescFileName( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US ); + sDescFileName.SearchAndReplaceAll( "description.xml", "" ); + sDescFileName += GetAttribute( sCurrentOpenTag, "xlink:href" ); + ifstream::pos_type size; + char * memblock; + ifstream file (sDescFileName.GetBuffer(), ios::in|ios::binary|ios::ate); + if (file.is_open()) { + size = file.tellg(); + memblock = new char [size]; + file.seekg (0, ios::beg); + file.read (memblock, size); + file.close(); + sCurrentText = ByteString(memblock); + sCurrentText.SearchAndReplaceAll( "\n", "\\n" ); + delete[] memblock; + } + ByteString sLang = GetAttribute( sCurrentOpenTag, sLangAttribute ); + WorkOnText( sCurrentOpenTag, sCurrentText ); + sCurrentCloseTag = rToken; + Output( sCurrentText ); + EndOfText( sCurrentOpenTag, sCurrentCloseTag ); + rToken = ByteString(""); + sCurrentText = ByteString(""); + } + } + break; + default: if ( bText ) { sCurrentText += rToken; @@ -461,7 +549,7 @@ void XRMResExport::WorkOnText( ) /*****************************************************************************/ { - ByteString sLang( GetAttribute( rOpenTag, "xml:lang" )); + ByteString sLang( GetAttribute( rOpenTag, sLangAttribute )); if ( !pResData ) { @@ -498,7 +586,8 @@ void XRMResExport::EndOfText( ByteString sOutput( sPrj ); sOutput += "\t"; sOutput += sPath; sOutput += "\t0\t"; - sOutput += "readmeitem\t"; + sOutput += sResourceType; + sOutput += "\t"; sOutput += pResData->sId; // USE LID AS GID OR MERGE DON'T WORK //sOutput += pResData->sGId; |