summaryrefslogtreecommitdiff
path: root/transex3
diff options
context:
space:
mode:
authorNils Fuhrmann <nf@openoffice.org>2001-05-30 11:10:22 +0000
committerNils Fuhrmann <nf@openoffice.org>2001-05-30 11:10:22 +0000
commita638164904ffe0573fa60e5c7852d54f96b4cfce (patch)
treeef63a4520a44942efa50ddbc578aedfa330d64df /transex3
parent31cc5f0ca04a990b1a6045f41cba10d2f829a921 (diff)
Multiple fixes and features for l10n framework #87136#
Diffstat (limited to 'transex3')
-rw-r--r--transex3/source/cfgmerge.cxx19
-rw-r--r--transex3/source/export.cxx6
-rw-r--r--transex3/source/export2.cxx41
-rw-r--r--transex3/source/lngmerge.cxx19
-rw-r--r--transex3/source/localize.cxx230
-rw-r--r--transex3/source/makefile.mk6
6 files changed, 287 insertions, 34 deletions
diff --git a/transex3/source/cfgmerge.cxx b/transex3/source/cfgmerge.cxx
index cc791eae0103..52b1dfbb1440 100644
--- a/transex3/source/cfgmerge.cxx
+++ b/transex3/source/cfgmerge.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: cfgmerge.cxx,v $
*
- * $Revision: 1.13 $
+ * $Revision: 1.14 $
*
- * last change: $Author: nf $ $Date: 2001-05-28 08:25:29 $
+ * last change: $Author: nf $ $Date: 2001-05-30 12:10:22 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -303,9 +303,18 @@ void CfgStackData::FillInFallbacks()
USHORT nFallbackIndex =
Export::GetLangIndex(
Export::GetFallbackLanguage( Export::LangId[ i ] ));
- if ( nFallbackIndex < LANGUAGES ) {
- if ( !sText[ i ].Len())
- sText[ i ] = sText[ nFallbackIndex ];
+ if (( nFallbackIndex < LANGUAGES ) && !sText[ i ].Len()) {
+ CharSet eSource =
+ Export::GetCharSet( Export::LangId[ nFallbackIndex ] );
+ CharSet eDest =
+ Export::GetCharSet( Export::LangId[ i ] );
+
+ ByteString sFallback =
+ UTF8Converter::ConvertToUTF8( sText[ nFallbackIndex ],
+ eSource );
+ sText[ i ] =
+ UTF8Converter::ConvertFromUTF8( sFallback,
+ eDest );
}
}
}
diff --git a/transex3/source/export.cxx b/transex3/source/export.cxx
index ec652d4f388a..4309c594d6c1 100644
--- a/transex3/source/export.cxx
+++ b/transex3/source/export.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: export.cxx,v $
*
- * $Revision: 1.13 $
+ * $Revision: 1.14 $
*
- * last change: $Author: nf $ $Date: 2001-05-28 08:25:29 $
+ * last change: $Author: nf $ $Date: 2001-05-30 12:10:22 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -1212,6 +1212,8 @@ USHORT Export::GetLangIndex( const ByteString &rLang )
return HEBREW_INDEX;
else if ( sLang == "CATALAN" )
return CATALAN_INDEX;
+ else if ( sLang == "EXTERN" )
+ return EXTERN_INDEX;
return nLangIndex;
}
diff --git a/transex3/source/export2.cxx b/transex3/source/export2.cxx
index 9d64bfb53019..9d67806fbc45 100644
--- a/transex3/source/export2.cxx
+++ b/transex3/source/export2.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: export2.cxx,v $
*
- * $Revision: 1.9 $
+ * $Revision: 1.10 $
*
- * last change: $Author: nf $ $Date: 2001-05-28 08:25:29 $
+ * last change: $Author: nf $ $Date: 2001-05-30 12:10:22 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -59,6 +59,7 @@
*
************************************************************************/
#include "export.hxx"
+#include "utf8conv.hxx"
//
// class ResData();
@@ -257,7 +258,7 @@ USHORT Export::GetLangByIsoLang( const ByteString &rIsoLang )
return HEBREW;
else if ( sLang == ByteString( CATALAN_ISO ).ToUpperAscii())
return CATALAN;
- else if ( sLang == sIsoCode99 )
+ else if ( sLang == ByteString( sIsoCode99 ).ToUpperAscii())
return EXTERN;
return 0xFFFF;
@@ -466,18 +467,27 @@ void Export::FillInFallbacks( ResData *pResData )
USHORT nFallbackIndex =
GetLangIndex( GetFallbackLanguage( LangId[ i ] ));
if ( nFallbackIndex < LANGUAGES ) {
+ CharSet eSource =
+ Export::GetCharSet( Export::LangId[ nFallbackIndex ] );
+ CharSet eDest =
+ Export::GetCharSet( Export::LangId[ i ] );
+
if ( !pResData->sText[ i ].Len())
- pResData->sText[ i ] =
- pResData->sText[ nFallbackIndex ];
+ pResData->sText[ i ] = UTF8Converter::ConvertFromUTF8(
+ UTF8Converter::ConvertToUTF8(
+ pResData->sText[ nFallbackIndex ], eSource ), eDest );
if ( !pResData->sHelpText[ i ].Len())
- pResData->sHelpText[ i ] =
- pResData->sHelpText[ nFallbackIndex ];
+ pResData->sHelpText[ i ] = UTF8Converter::ConvertFromUTF8(
+ UTF8Converter::ConvertToUTF8(
+ pResData->sHelpText[ nFallbackIndex ], eSource ), eDest );
if ( !pResData->sQuickHelpText[ i ].Len())
- pResData->sQuickHelpText[ i ] =
- pResData->sQuickHelpText[ nFallbackIndex ];
+ pResData->sQuickHelpText[ i ] = UTF8Converter::ConvertFromUTF8(
+ UTF8Converter::ConvertToUTF8(
+ pResData->sQuickHelpText[ nFallbackIndex ], eSource ), eDest );
if ( !pResData->sTitle[ i ].Len())
- pResData->sTitle[ i ] =
- pResData->sTitle[ nFallbackIndex ];
+ pResData->sTitle[ i ] = UTF8Converter::ConvertFromUTF8(
+ UTF8Converter::ConvertToUTF8(
+ pResData->sTitle[ nFallbackIndex ], eSource ), eDest );
if ( pResData->pStringList )
FillInListFallbacks(
@@ -501,9 +511,16 @@ void Export::FillInListFallbacks(
ExportList *pList, USHORT nSource, USHORT nFallback )
/*****************************************************************************/
{
+ CharSet eSource =
+ Export::GetCharSet( Export::LangId[ nFallback ] );
+ CharSet eDest =
+ Export::GetCharSet( Export::LangId[ nSource ] );
+
for ( ULONG i = 0; i < pList->Count(); i++ ) {
ExportListEntry *pEntry = pList->GetObject( i );
if ( !( *pEntry )[ nSource ].Len())
- ( *pEntry )[ nSource ] = ( *pEntry )[ nFallback ];
+ ( *pEntry )[ nSource ] = UTF8Converter::ConvertFromUTF8(
+ UTF8Converter::ConvertToUTF8(
+ ( *pEntry )[ nFallback ], eSource ), eDest );
}
}
diff --git a/transex3/source/lngmerge.cxx b/transex3/source/lngmerge.cxx
index 3218a31143a4..9b0aace0876a 100644
--- a/transex3/source/lngmerge.cxx
+++ b/transex3/source/lngmerge.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: lngmerge.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: nf $ $Date: 2001-05-28 08:25:29 $
+ * last change: $Author: nf $ $Date: 2001-05-30 12:10:22 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -113,9 +113,18 @@ void LngParser::FillInFallbacks( ByteString *Text )
USHORT nFallbackIndex =
Export::GetLangIndex(
Export::GetFallbackLanguage( Export::LangId[ i ] ));
- if ( nFallbackIndex < LANGUAGES ) {
- if ( !Text[ i ].Len())
- Text[ i ] = Text[ nFallbackIndex ];
+ if (( nFallbackIndex < LANGUAGES ) && !Text[ i ].Len()) {
+ CharSet eSource =
+ Export::GetCharSet( Export::LangId[ nFallbackIndex ] );
+ CharSet eDest =
+ Export::GetCharSet( Export::LangId[ i ] );
+
+ ByteString sFallback =
+ UTF8Converter::ConvertToUTF8( Text[ nFallbackIndex ],
+ eSource );
+ Text[ i ] =
+ UTF8Converter::ConvertFromUTF8( sFallback,
+ eDest );
}
}
}
diff --git a/transex3/source/localize.cxx b/transex3/source/localize.cxx
index be11e2f8aa46..18ef98c1d938 100644
--- a/transex3/source/localize.cxx
+++ b/transex3/source/localize.cxx
@@ -3,9 +3,9 @@
*
* $RCSfile: localize.cxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: nf $ $Date: 2001-05-28 12:38:01 $
+ * last change: $Author: nf $ $Date: 2001-05-30 12:10:22 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -61,6 +61,7 @@
************************************************************************/
#include "srciter.hxx"
+#include "export.hxx"
#include <bootstrp/appdef.hxx>
#include <bootstrp/command.hxx>
#include <stdio.h>
@@ -526,7 +527,9 @@ BOOL SourceTreeLocalizer::MergeSingleFile(
FileCopier aCopier( aOut, aEntry );
if( aCopier.Execute() != FSYS_ERR_OK )
- fprintf( stderr, "ERROR: Unable to write file %s\n", sFile.GetBuffer());
+ fprintf( stderr,
+ "ERROR: Unable to open file %s for modification!\n",
+ sFile.GetBuffer());
aOldCWD.SetCWD();
aOut.Kill();
@@ -604,6 +607,111 @@ BOOL SourceTreeLocalizer::Merge( const ByteString &rSourceFile )
return bReturn;
}
+#define STATE_NONE 0x0000
+#define STATE_EXPORT 0x0001
+#define STATE_MERGE 0x0002
+#define STATE_ISOCODE 0x0003
+#define STATE_LANGUAGES 0x0004
+#define STATE_FILENAME 0x0005
+
+/*****************************************************************************/
+void Help()
+/*****************************************************************************/
+{
+ fprintf( stdout,
+ "localize (c)2001 by Sun Microsystems\n"
+ "====================================\n" );
+ fprintf( stdout,
+ "As part of the L10N framework, localize extracts and merges translations\n"
+ "out of and into the whole source tree.\n\n"
+ "Syntax: localize -e|-m -i ISO-Code -l l1[=f1][,l2[=f2]][...] -f FileName\n"
+ "Parameter:\n"
+ "\t-e: Extract mode\n"
+ "\t-m: Merge mode\n"
+ "\tFileName: Output file when extract mode, input file when merge mode\n"
+ "\tl1...ln: supported languages\n"
+ "\tf1...fn: fallback languages for supported languages\n\n"
+ "\tISO-Code: The full qualified ISO language code for language 99 (en-US, de, ...)"
+ );
+
+ fprintf( stdout,
+ "Valid language codes for l1...ln and f1...fn are:\n" );
+
+ for ( USHORT i = 0; i < LANGUAGES; i++ ) {
+ ByteString sId;
+ if ( Export::LangId[ i ] < 10 ) {
+ sId = "0";
+ }
+ sId += ByteString::CreateFromInt32( Export::LangId[ i ] );
+ ByteString sLanguage( Export::LangName[ i ] );
+ fprintf( stdout,
+ "\t%s => %s\n",
+ sId.GetBuffer(),
+ sLanguage.GetBuffer()
+ );
+ }
+ fprintf( stdout,
+ "\nExample 1:\n"
+ "==========\n"
+ "localize -e -i de-CH -l 01,99=35 -f MyFile\n\n"
+ "All strings will be extracted for language 01 and language 99.\n"
+ "If 99 is empty, language 35 will be fallback.\n"
+ );
+ fprintf( stdout,
+ "\nExample 2:\n"
+ "==========\n"
+ "localize -m -i de-CH -l 99 -f MyFile\n\n"
+ "All strings in MyFile will be merged into language 99 in the\n"
+ "source code.\n"
+ );
+}
+
+/*****************************************************************************/
+int Error()
+/*****************************************************************************/
+{
+ Help();
+ return 1;
+}
+
+/*****************************************************************************/
+BOOL CheckLanguages( ByteString &rLanguages )
+/*****************************************************************************/
+{
+ BOOL bReturn = TRUE;
+
+ for ( USHORT i = 0; i < rLanguages.GetTokenCount( ',' ); i++ ) {
+ ByteString sCur = rLanguages.GetToken( i, ',' );
+ ByteString sLang = sCur.GetToken( 0, '=' );
+ USHORT nLang = ( USHORT ) sLang.ToInt32();
+
+ ByteString sFallback = sCur.GetToken( 1, '=' );
+ USHORT nFallback = ( USHORT ) sFallback.ToInt32();
+
+ if ( Export::GetLangIndex( nLang ) == 0xFFFF ) {
+ fprintf( stderr, "ERROR: Unknown language %s\n",
+ sLang.GetBuffer());
+ bReturn = FALSE;
+ }
+ else if ( sFallback.Len() && ( Export::GetLangIndex( nFallback )==0xFFFF )){
+ fprintf( stderr, "ERROR: Unknown fallback languges %s\n",
+ sFallback.GetBuffer());
+ bReturn = FALSE;
+ }
+ }
+
+ if ( bReturn ) {
+ if ( !rLanguages.Len()) {
+ rLanguages = "01,99=01";
+ }
+ if ( rLanguages.Search( "99" ) == STRING_NOTFOUND ) {
+ rLanguages += ",99=01";
+ }
+ }
+
+ return bReturn;
+}
+
/*****************************************************************************/
#if defined( UNX ) || defined( MAC )
int main( int argc, char *argv[] )
@@ -612,6 +720,69 @@ int _cdecl main( int argc, char *argv[] )
#endif
/*****************************************************************************/
{
+ USHORT nState = STATE_NONE;
+
+ BOOL bExport = FALSE;
+ BOOL bMerge = FALSE;
+
+ ByteString sIsoCode;
+ ByteString sLanguages;
+ ByteString sFileName;
+
+ for( int i = 1; i < argc; i++ ) {
+ if ( ByteString( argv[ i ]).ToUpperAscii() == "-E" ) {
+ nState = STATE_EXPORT;
+ if ( bMerge )
+ return Error();
+ bExport = TRUE;
+ }
+ else if ( ByteString( argv[ i ]).ToUpperAscii() == "-M" ) {
+ nState = STATE_MERGE;
+ if ( bExport )
+ return Error();
+ bMerge = TRUE;
+ }
+ else if ( ByteString( argv[ i ]).ToUpperAscii() == "-I" )
+ nState = STATE_ISOCODE;
+ else if ( ByteString( argv[ i ]).ToUpperAscii() == "-L" )
+ nState = STATE_LANGUAGES;
+ else if ( ByteString( argv[ i ]).ToUpperAscii() == "-F" )
+ nState = STATE_FILENAME;
+ else {
+ switch ( nState ) {
+ case STATE_NONE:
+ return Error();
+ break;
+ case STATE_ISOCODE:
+ if ( sIsoCode.Len())
+ return Error();
+ sIsoCode = ByteString( argv[ i ] );
+ nState = STATE_NONE;
+ break;
+ case STATE_LANGUAGES:
+ if ( sLanguages.Len())
+ return Error();
+ sLanguages = ByteString( argv[ i ] );
+ nState = STATE_NONE;
+ break;
+ case STATE_FILENAME:
+ if ( sFileName.Len())
+ return Error();
+ sFileName = ByteString( argv[ i ] );
+ nState = STATE_NONE;
+ break;
+
+ default:
+ return Error();
+ break;
+ }
+ }
+ }
+ if ( !bMerge && !bExport ) {
+ Help();
+ return 1;
+ }
+
ByteString sRoot( GetEnv( "SOLARVERSION" ));
DirEntry aRoot( String( sRoot, RTL_TEXTENCODING_ASCII_US ));
aRoot += DirEntry( String::CreateFromAscii( "src" ));
@@ -623,11 +794,56 @@ int _cdecl main( int argc, char *argv[] )
return 1;
}
+ if ( !CheckLanguages( sLanguages ))
+ return 2;
+
+ if ( !sIsoCode.Len()) {
+ fprintf( stderr, "ERROR: No ISO code given\n" );
+ return 3;
+ }
+
+ if ( !sFileName.Len()) {
+ fprintf( stderr, "ERROR: No filename given\n" );
+ return 3;
+ }
+
+ ByteString sMode( "merge" );
+ if ( bExport )
+ sMode = "extract";
+ fprintf( stdout,
+ "\n"
+ "=======================================================\n"
+ "Current settings:\n"
+ "=======================================================\n"
+ "Mode: %s\n"
+ "Workspace: %s\n"
+ "Source tree: %s\n"
+ "Languages: %s\n"
+ "ISO code (99): %s\n"
+ "Filename: %s\n"
+ "=======================================================\n"
+ "\n"
+ ,
+ sMode.GetBuffer(),
+ sVersion.GetBuffer(),
+ sRoot.GetBuffer(),
+ sLanguages.GetBuffer(),
+ sIsoCode.GetBuffer(),
+ sFileName.GetBuffer()
+ );
+
SourceTreeLocalizer aIter( sRoot, sVersion );
- aIter.SetLanguageRestriction( "01,99=35" );
- aIter.SetIsoCode99( "de-CH" );
-// aIter.Extract( "x:\\nf\\test.txt" );
- aIter.Merge( "x:\\nf\\test.txt" );
+ aIter.SetLanguageRestriction( sLanguages );
+ aIter.SetIsoCode99( sIsoCode );
+
+ if ( bExport )
+ aIter.Extract( sFileName );
+ else {
+ DirEntry aEntry( String( sFileName, RTL_TEXTENCODING_ASCII_US ));
+ if ( !aEntry.Exists())
+ return FALSE;
+ aIter.Merge( sFileName );
+ }
return 0;
}
diff --git a/transex3/source/makefile.mk b/transex3/source/makefile.mk
index e5f48da710b5..8b1af5ff816d 100644
--- a/transex3/source/makefile.mk
+++ b/transex3/source/makefile.mk
@@ -2,9 +2,9 @@
#
# $RCSfile: makefile.mk,v $
#
-# $Revision: 1.9 $
+# $Revision: 1.10 $
#
-# last change: $Author: nf $ $Date: 2001-05-22 14:11:52 $
+# last change: $Author: nf $ $Date: 2001-05-30 12:10:22 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
@@ -144,7 +144,7 @@ APP8STDLIBS=$(STATIC_LIBS)
# encoding converter for text files
APP9TARGET= localize
APP9STACK= 16000
-APP9OBJS= $(OBJ)$/localize.obj
+APP9OBJS= $(OBJ)$/localize.obj $(OBJ)$/utf8conv.obj
APP9STDLIBS+=$(STATIC_LIBS) $(BTSTRPLIB)
APP9LIBS+= $(LB)$/$(TARGET).lib