1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: localize.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_transex3.hxx"
34 #include "srciter.hxx"
37 #include "tools/errcode.hxx"
38 #include "tools/fsys.hxx"
40 #ifndef TRANSEX_FILE_HXX
41 #define TRANSEX_FILE_HXX
42 #include <transex3/file.hxx>
47 // SourceTreeLocalizer
50 const char *ExeTable
[][5] = {
51 { "src", "transex3", " -UTF8 -e", "negative", "noiso" },
52 { "hrc", "transex3", " -UTF8 -e", "positive", "noiso" },
53 //{ "src", "transex3", "-UTF8 -e", "negative", "noiso" },
54 //{ "hrc", "transex3", "-UTF8 -e", "positive", "noiso" },
56 //{ "lng", "lngex", "-UTF8 -e", "negative", "noiso" },
57 { "ulf", "ulfex", " -e", "negative", "noiso" },
58 { "xrb", "xmlex", "-UTF8 -e", "negative", "iso" },
59 { "xxl", "xmlex", "-UTF8 -e", "negative", "iso" },
60 { "xgf", "xmlex", "-UTF8 -e -t:xgf", "negative", "iso" },
61 { "xcd", "cfgex", "-UTF8 -e", "negative", "iso" },
62 { "xcu", "cfgex", "-UTF8 -e", "negative", "iso" },
63 { "xcs", "cfgex", "-UTF8 -e -f", "negative", "iso" },
64 { "xrm", "xrmex", "-UTF8 -e", "negative", "iso" },
65 { "xhp", "helpex", " -e", "negative", "noiso" },
66 { "NULL", "NULL", "NULL", "NULL", "NULL" }
69 const char *NegativeList
[] = {
70 "officecfg/data/org.openoffice.Office.Labels.xcd",
71 "officecfg/data/org/openoffice/Office/Labels.xcd",
72 "officecfg/data/org/openoffice/Office/SFX.xcd",
73 "officecfg/data/org/openoffice/Office/Accelerators.xcu",
78 const char *PositiveList
[] = {
79 "svx/inc/globlmn_tmpl.hrc",
80 "sw/source/ui/inc/swmn_tmpl.hrc",
81 "sw/source/ui/inc/swacc_tmpl.hrc",
82 "sw/source/ui/inc/toolbox_tmpl.hrc",
83 "offmgr/inc/offmenu_tmpl.hrc",
84 "offmgr/source/offapp/intro/intro_tmpl.hrc",
85 "dbaccess/source/ui/inc/toolbox_tmpl.hrc",
86 "svx/source/intro/intro_tmpl.hrc",
87 "dbaccess/source/ui/dlg/AutoControls_tmpl.hrc",
88 "svx/source/unodialogs/textconversiondlgs/chinese_direction_tmpl.hrc",
89 "chart2/source/controller/dialogs/res_DataLabel_tmpl.hrc",
90 "chart2/source/controller/dialogs/res_LegendPosition_tmpl.hrc",
91 "chart2/source/controller/dialogs/res_Statistic_tmpl.hrc",
92 "chart2/source/controller/dialogs/res_Titlesx_tmpl.hrc",
93 "chart2/source/controller/dialogs/res_SecondaryAxisCheckBoxes_tmpl.hrc",
94 "chart2/source/controller/menu/MenuItems_tmpl.hrc",
95 "chart2/source/controller/dialogs/res_ErrorBar_tmpl.hrc",
96 "chart2/source/controller/dialogs/res_Trendline_tmpl.hrc",
97 "svx.link/inc/globlmn_tmpl.hrc",
98 "sw.link/source/ui/inc/swmn_tmpl.hrc",
99 "sw.link/source/ui/inc/swacc_tmpl.hrc",
100 "sw.link/source/ui/inc/toolbox_tmpl.hrc",
101 "offmgr.link/inc/offmenu_tmpl.hrc",
102 "offmgr.link/source/offapp/intro/intro_tmpl.hrc",
103 "dbaccess.link/source/ui/inc/toolbox_tmpl.hrc",
104 "svx.link/source/intro/intro_tmpl.hrc",
105 "dbaccess.link/source/ui/dlg/AutoControls_tmpl.hrc",
106 "svx.link/source/unodialogs/textconversiondlgs/chinese_direction_tmpl.hrc",
107 "chart2.link/source/controller/dialogs/res_DataLabel_tmpl.hrc",
108 "chart2.link/source/controller/dialogs/res_LegendPosition_tmpl.hrc",
109 "chart2.link/source/controller/dialogs/res_Statistic_tmpl.hrc",
110 "chart2.link/source/controller/dialogs/res_Titlesx_tmpl.hrc",
111 "chart2.link/source/controller/dialogs/res_SecondaryAxisCheckBoxes_tmpl.hrc",
112 "chart2.link/source/controller/menu/MenuItems_tmpl.hrc",
113 "chart2.link/source/controller/dialogs/res_ErrorBar_tmpl.hrc",
114 "chart2.link/source/controller/dialogs/res_Trendline_tmpl.hrc",
119 const char PRJ_DIR_NAME
[] = "prj";
120 const char DLIST_NAME
[] = "d.lst";
122 #define LOCALIZE_NONE 0x0000
123 #define LOCALIZE_EXTRACT 0x0001
124 #define LOCALIZE_MERGE 0x0002
126 class SourceTreeLocalizer
: public SourceTreeIterator
132 ByteString sLanguageRestriction
;
134 ByteString sIsoCode99
;
135 ByteString sOutputFile
;
140 const ByteString
GetProjectName( BOOL bAbs
= FALSE
);
141 const ByteString
GetProjectRootRel();
144 BOOL
CheckNegativeList( const ByteString
&rFileName
);
145 BOOL
CheckPositiveList( const ByteString
&rFileName
);
148 const ByteString
&rFileName
,
149 const ByteString
&rExecutable
,
150 const ByteString
&rParameter
,
151 const ByteString
&rIso
155 const ByteString
&rDirectory
,
156 const ByteString
&rExtension
,
157 const ByteString
&rExecutable
,
158 const ByteString
&rParameter
,
159 const ByteString
&rCollectMode
,
160 const ByteString
&rIso
162 void WorkOnDirectory( const ByteString
&rDirectory
);
164 BOOL
MergeSingleFile(
165 const ByteString
&rPrj
,
166 const ByteString
&rFile
,
167 const ByteString
&rSDFFile
171 SourceTreeLocalizer( const ByteString
&rRoot
, const ByteString
&rVersion
, bool bLocal
, bool bQuiet2_in
, bool skip_links
);
172 ~SourceTreeLocalizer();
174 ByteString
getSourceLanguages( ByteString sLanguageRestriction
, ByteString sCommand
);
176 void SetLanguageRestriction( const ByteString
& rRestrictions
)
177 { sLanguageRestriction
= rRestrictions
; }
178 void SetIsoCode99( const ByteString
& rIsoCode
)
179 { sIsoCode99
= rIsoCode
; }
181 BOOL
Extract( const ByteString
&rDestinationFile
);
182 BOOL
Merge( const ByteString
&rSourceFile
, const ByteString
&rOutput
);
184 virtual void OnExecuteDirectory( const rtl::OUString
&rDirectory
);
187 /*****************************************************************************/
188 SourceTreeLocalizer::SourceTreeLocalizer(
189 const ByteString
&rRoot
, const ByteString
&rVersion
, bool bLocal_in
, bool bQuiet2_in
, bool skip_links
)
190 /*****************************************************************************/
191 : SourceTreeIterator( rRoot
, rVersion
, bLocal_in
),
192 nMode( LOCALIZE_NONE
),
193 bQuiet2( bQuiet2_in
),
196 bSkipLinks
= skip_links
;
199 /*****************************************************************************/
200 SourceTreeLocalizer::~SourceTreeLocalizer()
201 /*****************************************************************************/
205 /*****************************************************************************/
206 const ByteString
SourceTreeLocalizer::GetProjectName( BOOL bAbs
)
207 /*****************************************************************************/
213 for ( ; ! bFound
&& aCur
.Level() > 1; aCur
.CutName() )
215 DirEntry aTest
= aCur
+ DirEntry(PRJ_DIR_NAME
) + DirEntry(DLIST_NAME
);
216 if ( aTest
.Exists() )
218 // HACK !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
219 if (( ByteString( aCur
.GetName(), RTL_TEXTENCODING_ASCII_US
).Equals("webinstall") ) ||
220 ( ByteString( aCur
.GetName(), RTL_TEXTENCODING_ASCII_US
).Equals("portal") ) ||
221 ( ByteString( aCur
.GetName(), RTL_TEXTENCODING_ASCII_US
).Equals("xulclient") ) ||
222 ( ByteString( aCur
.GetName(), RTL_TEXTENCODING_ASCII_US
).Search( "wdk_" ) == 0 ))
224 // end HACK !!!!!!!!!!!!!!!!!!!!!!!!!
229 return ByteString( aCur
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
231 return ByteString( aCur
.GetName(), RTL_TEXTENCODING_ASCII_US
);
237 /*****************************************************************************/
238 int SourceTreeLocalizer::GetFileCnt(){
239 /*****************************************************************************/
243 /*****************************************************************************/
244 const ByteString
SourceTreeLocalizer::GetProjectRootRel()
245 /*****************************************************************************/
247 ByteString
sProjectRoot( GetProjectName( TRUE
));
250 ByteString
sCur( aCur
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
252 if( sCur
.SearchAndReplace( sProjectRoot
, "" ) == STRING_NOTFOUND
)
255 ByteString
sDelimiter(
256 DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US
);
258 sCur
.SearchAndReplaceAll( sDelimiter
, "/" );
259 sCur
.EraseLeadingChars( '/' );
260 ULONG nCount
= sCur
.GetTokenCount( '/' );
262 ByteString sProjectRootRel
;
263 for ( ULONG i
= 0; i
< nCount
; i
++ ) {
264 if ( sProjectRootRel
.Len())
265 sProjectRootRel
+= sDelimiter
;
266 sProjectRootRel
+= "..";
268 if ( sProjectRootRel
.Len())
269 return sProjectRootRel
;
274 bool skipProject( ByteString sPrj
)
276 static const ByteString
READLICENSE( "readlicense" );
277 return sPrj
.EqualsIgnoreCaseAscii( READLICENSE
);
280 /*****************************************************************************/
281 void SourceTreeLocalizer::WorkOnFile(
282 const ByteString
&rFileName
, const ByteString
&rExecutable
,
283 const ByteString
&rParameter
, const ByteString
&rIso
)
284 /*****************************************************************************/
286 (void) rIso
; // Remove me ;)
287 String
sFull( rFileName
, RTL_TEXTENCODING_ASCII_US
);
288 DirEntry
aEntry( sFull
);
289 ByteString
sFileName( aEntry
.GetName(), RTL_TEXTENCODING_ASCII_US
);
291 // set current working directory
292 DirEntry
aPath( aEntry
.GetPath());
296 ByteString
sPrj( GetProjectName());
297 //printf ("prj = %s , exe = %s\n", sPrj.GetBuffer() , rExecutable.GetBuffer() );
298 // printf("Skip %s = %d \n",sPrj.GetBuffer() , skipProject( sPrj ) );
299 //printf("prj = %s\n",sPrj.GetBuffer());
300 if ( sPrj
.Len() && !skipProject( sPrj
) )
302 ByteString
sRoot( GetProjectRootRel());
305 DirEntry
aTemp( Export::GetTempFile());
306 ByteString
sTempFile( aTemp
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
309 #if defined(WNT) || defined(OS2)
310 sDel
=ByteString("\\");
312 sDel
=ByteString("/");
314 ByteString
sPath1( Export::GetEnv("SOLARVER") );
315 ByteString
sPath2( Export::GetEnv("INPATH") );
316 ByteString
sPath3( "bin" );
317 ByteString
sPath4( Export::GetEnv("UPDMINOREXT") );
318 ByteString
sExecutable( sPath1
);
319 sExecutable
+= sDel
;
320 sExecutable
+= sPath2
;
322 sExecutable
+= sPath3
;
323 sExecutable
+= sPath4
;
324 sExecutable
+= sDel
;
325 sExecutable
+= rExecutable
;
328 ByteString
sCommand( sExecutable
);
330 sCommand
+= rParameter
;
336 sCommand
+= sFileName
;
338 sCommand
+= sTempFile
;
339 if ( sLanguageRestriction
.Len()) {
341 sCommand
+= getSourceLanguages( sLanguageRestriction
, sCommand
);
347 //printf("DBG: %s\n",sCommand.GetBuffer());
348 system( sCommand
.GetBuffer());
353 SvFileStream
aSDFIn( aTemp
.GetFull(), STREAM_READ
);
355 while ( aSDFIn
.IsOpen() && !aSDFIn
.IsEof()) {
356 aSDFIn
.ReadLine( sLine
);
358 aSDF
.WriteLine( sLine
);
366 // reset current working directory
370 ByteString
SourceTreeLocalizer::getSourceLanguages( ByteString sLanguageRestriction_inout
, ByteString sCommand
)
372 // Source languages in helpcontent2 and macromigration en-US only!
373 if( sCommand
.Search("helpex") != STRING_NOTFOUND
) {
374 sLanguageRestriction_inout
.Assign( ByteString("en-US") );
376 else if( sCommand
.Search("xmlex") != STRING_NOTFOUND
){
377 sLanguageRestriction_inout
.Assign( ByteString("en-US") );
379 return sLanguageRestriction_inout
;
382 /*****************************************************************************/
383 BOOL
SourceTreeLocalizer::CheckNegativeList( const ByteString
&rFileName
)
384 /*****************************************************************************/
389 ByteString
sDelimiter(
390 DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US
);
392 ByteString
sFileName( rFileName
);
393 sFileName
.ToLowerAscii();
395 ByteString
sNegative( NegativeList
[ nIndex
] );
396 while( !sNegative
.Equals( "NULL" ) && bReturn
) {
397 sNegative
.SearchAndReplaceAll( "\\", sDelimiter
);
398 sNegative
.SearchAndReplaceAll( "/", sDelimiter
);
399 sNegative
.ToLowerAscii();
401 if( sFileName
.Search( sNegative
) == sFileName
.Len() - sNegative
.Len())
405 sNegative
= NegativeList
[ nIndex
];
411 /*****************************************************************************/
412 BOOL
SourceTreeLocalizer::CheckPositiveList( const ByteString
&rFileName
)
413 /*****************************************************************************/
416 BOOL bReturn
= FALSE
;
418 ByteString
sDelimiter(
419 DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US
);
421 ByteString
sFileName( rFileName
);
422 sFileName
.ToLowerAscii();
424 ByteString
sNegative( PositiveList
[ nIndex
] );
425 while( !sNegative
.Equals( "NULL" ) && !bReturn
) {
426 sNegative
.SearchAndReplaceAll( "\\", sDelimiter
);
427 sNegative
.SearchAndReplaceAll( "/", sDelimiter
);
428 sNegative
.ToLowerAscii();
430 if( sFileName
.Search( sNegative
) == sFileName
.Len() - sNegative
.Len())
434 sNegative
= PositiveList
[ nIndex
];
440 /*****************************************************************************/
441 void SourceTreeLocalizer::WorkOnFileType(
442 const ByteString
&rDirectory
, const ByteString
&rExtension
,
443 const ByteString
&rExecutable
, const ByteString
&rParameter
,
444 const ByteString
&rCollectMode
, const ByteString
&rIso
446 /*****************************************************************************/
448 String
sWild( rDirectory
, RTL_TEXTENCODING_ASCII_US
);
449 sWild
+= DirEntry::GetAccessDelimiter();
450 sWild
+= String::CreateFromAscii( "*." );
451 sWild
+= String( rExtension
, RTL_TEXTENCODING_ASCII_US
);
453 DirEntry
aEntry( sWild
);
454 Dir
aDir( sWild
, FSYS_KIND_FILE
);
456 for ( USHORT i
= 0; i
< aDir
.Count(); i
++ ) {
457 DirEntry
aFile( aDir
[ i
] );
458 ByteString
sFile( aFile
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
460 BOOL bAllowed
= TRUE
;
462 if ( rCollectMode
.Equals( "negative" ))
463 bAllowed
= CheckNegativeList( sFile
);
464 else if ( rCollectMode
.Equals( "positive" ))
465 bAllowed
= CheckPositiveList( sFile
);
468 WorkOnFile( sFile
, rExecutable
, rParameter
, rIso
);
472 /*****************************************************************************/
473 void SourceTreeLocalizer::WorkOnDirectory( const ByteString
&rDirectory
)
474 /*****************************************************************************/
476 //printf("Working on Directory %s\n",rDirectory.GetBuffer());
478 ByteString
sExtension( ExeTable
[ nIndex
][ 0 ] );
479 ByteString
sExecutable( ExeTable
[ nIndex
][ 1 ] );
480 ByteString
sParameter( ExeTable
[ nIndex
][ 2 ] );
481 ByteString
sCollectMode( ExeTable
[ nIndex
][ 3 ] );
482 ByteString
sIso( ExeTable
[ nIndex
][ 4 ] );
484 while( !sExtension
.Equals( "NULL" )) {
496 sExtension
= ExeTable
[ nIndex
][ 0 ];
497 sExecutable
= ExeTable
[ nIndex
][ 1 ];
498 sParameter
= ExeTable
[ nIndex
][ 2 ];
499 sCollectMode
= ExeTable
[ nIndex
][ 3 ];
500 sIso
= ExeTable
[ nIndex
][ 4 ];
504 void SourceTreeLocalizer::OnExecuteDirectory( const rtl::OUString
&aDirectory
)
506 ByteString
rDirectory( rtl::OUStringToOString( aDirectory
, RTL_TEXTENCODING_UTF8
, aDirectory
.getLength() ) ) ;
507 if ( nMode
== LOCALIZE_NONE
){
508 if( !bQuiet2
) fprintf( stdout
, "%s\n", rDirectory
.GetBuffer());
511 WorkOnDirectory( rDirectory
);
514 /*****************************************************************************/
515 BOOL
SourceTreeLocalizer::Extract( const ByteString
&rDestinationFile
)
516 /*****************************************************************************/
518 nMode
= LOCALIZE_EXTRACT
;
519 aSDF
.Open( String( rDestinationFile
, RTL_TEXTENCODING_ASCII_US
),
520 STREAM_STD_WRITE
| STREAM_TRUNC
);
521 aSDF
.SetLineDelimiter( LINEEND_CRLF
);
523 BOOL bReturn
= aSDF
.IsOpen();
525 bReturn
= StartExecute();
529 printf("ERROR: Can't create file %s\n", rDestinationFile
.GetBuffer() );
531 nMode
= LOCALIZE_NONE
;
535 /*****************************************************************************/
536 BOOL
SourceTreeLocalizer::MergeSingleFile(
537 const ByteString
&rPrj
,
538 const ByteString
&rFile
,
539 const ByteString
&rSDFFile
541 /*****************************************************************************/
543 //printf("MergeSingleFile(%s,%s,%s)",rPrj.GetBuffer(),rFile.GetBuffer(),rSDFFile.GetBuffer());
547 ByteString
sRoot( Export::GetEnv( "SRC_ROOT" ));
548 DirEntry
aEntry( String( sRoot
, RTL_TEXTENCODING_ASCII_US
));
549 aEntry
+= DirEntry( String( rPrj
, RTL_TEXTENCODING_ASCII_US
));
551 ByteString
sDelimiter(
552 DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US
);
554 ByteString
sCur( rFile
);
555 sCur
.SearchAndReplaceAll( "\\", sDelimiter
);
556 sCur
.SearchAndReplaceAll( "/", sDelimiter
);
558 aEntry
+= DirEntry( String( sCur
, RTL_TEXTENCODING_ASCII_US
));
559 ByteString
sFile( aEntry
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
561 ByteString
sBCur( aEntry
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
562 if( !bQuiet2
) fprintf( stdout
, "##### %s #####\n", sBCur
.GetBuffer());
565 ByteString
sExtension( aEntry
.GetExtension(), RTL_TEXTENCODING_ASCII_US
);
566 ByteString
sCandidate( ExeTable
[ nIndex
][ 0 ] );
568 while( !sCandidate
.Equals ("NULL") && !sCandidate
.Equals(sExtension
) )
569 sCandidate
= ExeTable
[ ++nIndex
][ 0 ];
571 ByteString
sIso( ExeTable
[ nIndex
][ 4 ] );
573 if ( !sCandidate
.Equals( "NULL" ) ) {
574 if( !aEntry
.Exists()) {
575 DirEntryKind theDir
=FSYS_KIND_FILE
;
576 Dir
myDir( aEntry
.GetPath(), theDir
);
579 for( USHORT x
=0; x
< myDir
.Count() && !found
;){
581 StringCompare result
=current
.GetName().CompareIgnoreCaseToAscii( aEntry
.GetName() );
582 if( result
==COMPARE_EQUAL
){
583 fprintf(stderr
,"WARNING: %s not found\n", ByteString(aEntry
.GetFull(),RTL_TEXTENCODING_ASCII_US
).GetBuffer() );
584 fprintf(stderr
,"but use %s instead \n" , ByteString(current
.GetFull(), RTL_TEXTENCODING_ASCII_US
).GetBuffer() );
589 if(!found
) return TRUE
;
593 DirEntry
aOut( Export::GetTempFile() );
595 if( sOutputFile
.Len() == 0 )
596 sOutput
= ByteString ( aOut
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
598 sOutput
= sOutputFile
;
599 ByteString
sCommand( ExeTable
[ nIndex
][ 1 ] );
601 sCommand
+= ByteString( aEntry
.GetName(), RTL_TEXTENCODING_ASCII_US
);
603 sCommand
+= rSDFFile
;
607 sCommand
+= ByteString( ExeTable
[ nIndex
][ 2 ] );
608 if ( sIso
.Equals( "iso" ) && sIsoCode99
.Len()) {
609 sCommand
+= " -ISO99 ";
610 sCommand
+= sIsoCode99
;
612 if ( sLanguageRestriction
.Len()) {
614 sCommand
+= sLanguageRestriction
;
620 DirEntry
aPath( aEntry
.GetPath());
624 system( sCommand
.GetBuffer());
627 //if( bQuiet2 ){ printf("."); }
628 SvFileStream
aInStream( aOut
.GetFull(), STREAM_READ
);
629 if ( !aInStream
.IsOpen()) {
631 "ERROR: Unable to open file %s for reading!\n",
632 sOutput
.GetBuffer());
635 FileStat::SetReadOnlyFlag( aEntry
, FALSE
);
636 String
myStr2(aEntry
.GetFull());
637 String aTemp22
= String::CreateFromAscii("_tmp");
638 myStr2
.Append(aTemp22
);
640 ByteString
test(myStr2
,RTL_TEXTENCODING_ASCII_US
);
641 SvFileStream
aOutStream( myStr2
, STREAM_STD_WRITE
| STREAM_TRUNC
);
642 if ( !aOutStream
.IsOpen()) {
643 ByteString
test2(myStr2
,RTL_TEXTENCODING_ASCII_US
);
644 fprintf( stderr
,"ERROR: Unable to open file %s for modification!\n", test2
.GetBuffer());
650 aOutStream
.SetLineDelimiter( LINEEND_LF
);
652 aInStream
.ReadLine( sLine
);
653 while ( !aInStream
.IsEof()) {
654 aOutStream
.WriteLine( sLine
);
655 aInStream
.ReadLine( sLine
);
661 DirEntry
myTempFile(ByteString(myStr2
,RTL_TEXTENCODING_ASCII_US
)); // xxx_tmp ->
662 DirEntry
myFile(ByteString(aEntry
.GetFull(),RTL_TEXTENCODING_ASCII_US
));// xxx
664 DirEntry
oldFile(ByteString(aEntry
.GetFull(),RTL_TEXTENCODING_ASCII_US
));
666 if(oldFile
.Kill()==ERRCODE_NONE
){
667 if(myTempFile
.MoveTo(myFile
)!=ERRCODE_NONE
){
668 fprintf( stderr
, "ERROR: Can't rename file %s\n",ByteString(myStr2
,RTL_TEXTENCODING_ASCII_US
).GetBuffer());
672 fprintf( stderr
, "ERROR: Can't remove file %s\n",ByteString(aEntry
.GetFull(),RTL_TEXTENCODING_ASCII_US
).GetBuffer());
682 /*****************************************************************************/
683 BOOL
SourceTreeLocalizer::ExecuteMerge( )
684 /*****************************************************************************/
686 DirEntry
aEntry( Export::GetTempFile());
688 bool bMerged
= false;
690 ByteString sFileName
;
697 ByteString sOutputFileName
= sOutputFile
;
698 ByteString
sInpath(".");
699 sInpath
+= Export::GetEnv("INPATH");
700 ByteString
sBlank("");
702 sOutputFileName
.SearchAndReplaceAll( sInpath
, sBlank
);
704 String sDel
= DirEntry::GetAccessDelimiter();
705 ByteString
sBDel( sDel
.GetBuffer() , sDel
.Len() , RTL_TEXTENCODING_UTF8
);
707 xub_StrLen nPos
= sOutputFileName
.SearchBackward( sBDel
.GetChar(0) );
709 sOutputFileName
= sOutputFileName
.Copy( nPos
+1 , sOutputFileName
.Len()-nPos
-1 );
711 ByteStringBoolHashMap aFileHM
;
712 // Read all possible files
713 while ( !aSDF
.IsEof()) {
714 aSDF
.ReadLine( sLine
);
715 sFileName
= sLine
.GetToken( 0, '\t' );
717 sFileName
+= sLine
.GetToken( 1, '\t' );
718 aFileHM
[sFileName
]=true;
721 // RECODE THIS !!!!!!!!!!!!!!!!!!!!!
722 for( ByteStringBoolHashMap::iterator iter
= aFileHM
.begin(); iter
!= aFileHM
.end(); ++iter
){
723 sFileKey
= iter
->first
;
725 aFile
.Open( aEntry
.GetFull(), STREAM_STD_WRITE
|STREAM_TRUNC
);
727 while ( !aSDF
.IsEof()) {
728 aSDF
.ReadLine( sLine
);
729 sFileName
= sLine
.GetToken( 0, '\t' );
731 sFileName
+= sLine
.GetToken( 1, '\t' );
732 if( sFileName
.Len() && ( sFileName
.CompareTo(sFileKey
) == COMPARE_EQUAL
) ){
733 if ( aFile
.IsOpen() && sLine
.Len())
734 aFile
.WriteLine( sLine
);
740 ByteString
sPrj( sFileKey
.GetToken( 0, '#' ));
741 ByteString
sFile( sFileKey
.GetToken( 1, '#' ));
742 ByteString
sSDFFile( aFile
.GetFileName(), RTL_TEXTENCODING_ASCII_US
);
744 //printf("localize test sPrj = %s , sFile = %s , sSDFFile = %s sOutputFileName = %s\n",sPrj.GetBuffer(), sFile.GetBuffer() , sSDFFile.GetBuffer() , sOutputFileName.GetBuffer() );
751 USHORT nPos
= sFile
.SearchBackward( '\\' );
752 ByteString sTmp
= sFile
.Copy( nPos
+1 , sFile
.Len()-nPos
-1 );
753 //printf("'%s'='%s'\n",sTmp.GetBuffer(), sOutputFileName.GetBuffer());
754 if( sTmp
.CompareTo(sOutputFileName
) == COMPARE_EQUAL
){
756 if ( !MergeSingleFile( sPrj
, sFile
, sSDFFile
))
761 //printf("MergeSingleFile('%s','%s','%s')\n",sPrj.GetBuffer(),sFile.GetBuffer(),sSDFFile.GetBuffer());
762 if ( !MergeSingleFile( sPrj
, sFile
, sSDFFile
))
769 // If Outputfile not included in the SDF file copy it without merge
771 if( bLocal
&& !bMerged
){
772 DirEntry
aSourceFile( sOutputFileName
.GetBuffer() );
773 FSysError aErr
= aSourceFile
.CopyTo( DirEntry ( sOutputFile
.GetBuffer() ) , FSYS_ACTION_COPYFILE
);
774 if( aErr
!= FSYS_ERR_OK
){
775 printf("ERROR: Can't copy file '%s' to '%s' %d\n",sOutputFileName
.GetBuffer(),sOutputFile
.GetBuffer(),sal::static_int_cast
<int>(aErr
));
782 /*****************************************************************************/
783 BOOL
SourceTreeLocalizer::Merge( const ByteString
&rSourceFile
, const ByteString
&rOutput
)
784 /*****************************************************************************/
786 sOutputFile
= rOutput
;
787 nMode
= LOCALIZE_MERGE
;
788 aSDF
.Open( String( rSourceFile
, RTL_TEXTENCODING_ASCII_US
),
791 BOOL bReturn
= aSDF
.IsOpen();
793 bReturn
= ExecuteMerge();
797 nMode
= LOCALIZE_NONE
;
802 #define STATE_NONE 0x0000
803 #define STATE_EXPORT 0x0001
804 #define STATE_MERGE 0x0002
805 #define STATE_ISOCODE 0x0003
806 #define STATE_LANGUAGES 0x0004
807 #define STATE_FILENAME 0x0005
808 #define STATE_OUTPUT 0x0006
810 /*****************************************************************************/
812 /*****************************************************************************/
815 "localize (c)2001 by Sun Microsystems\n"
816 "====================================\n" );
818 "As part of the L10N framework, localize extracts and merges translations\n"
819 "out of and into the whole source tree.\n\n"
820 "Syntax: localize -e|-m -l l1[=f1][,l2[=f2]][...] -f FileName [-QQ][-skip_links]\n"
822 "\t-e: Extract mode\n"
824 "\tFileName: Output file when extract mode, input file when merge mode\n"
825 "\tl1...ln: supported languages (\"all\" for all languages).\n"
826 "\tf1...fn: fallback languages for supported languages\n"
827 "\tQQ: quiet output)"
831 "Valid language codes for l1...ln and f1...fn are:\n" );
835 "localize -e -l en-US,de -f MyFile\n\n"
836 "All strings will be extracted for language de and language en-US.\n"
841 "localize -m -l es -f MyFile\n\n"
842 "All strings in MyFile will be merged into language es in the\n"
847 /*****************************************************************************/
849 /*****************************************************************************/
855 /*****************************************************************************/
856 BOOL
CheckLanguages( ByteString
&rLanguages
)
857 /*****************************************************************************/
859 ByteString
sTmp( rLanguages
);
863 /*****************************************************************************/
864 #if defined(UNX) || defined(OS2)
865 int main( int argc
, char *argv
[] )
867 int _cdecl
main( int argc
, char *argv
[] )
869 /*****************************************************************************/
871 String
sTempBase( String::CreateFromAscii( "loc" ));
872 DirEntry::SetTempNameBase( sTempBase
);
873 USHORT nState
= STATE_NONE
;
875 BOOL bExport
= FALSE
;
878 bool bQuiet2
= false;
879 bool bSkipLinks
= false;
882 ByteString sLanguages
;
883 ByteString sFileName
;
886 for( int i
= 1; i
< argc
; i
++ ) {
887 ByteString
sSwitch( argv
[ i
] );
888 sSwitch
.ToUpperAscii();
890 if ( sSwitch
.Equals( "-E" )) {
891 nState
= STATE_EXPORT
;
896 else if ( sSwitch
.Equals( "-M" )) {
897 nState
= STATE_MERGE
;
902 else if( sSwitch
.Equals( "-Q" )) {
905 else if ( sSwitch
.Equals( "-I" ) )
906 nState
= STATE_ISOCODE
;
907 else if ( sSwitch
.Equals( "-L" ) )
908 nState
= STATE_LANGUAGES
;
909 else if ( sSwitch
.Equals( "-F" ) )
910 nState
= STATE_FILENAME
;
911 else if ( sSwitch
.Equals( "-QQ" ))
913 // else if ( ByteString( argv[ i ]).ToUpperAscii().Equals( "-SKIP_LINKS" ))
914 // bSkipLinks = true;
915 else if ( ByteString( argv
[ i
]).ToUpperAscii().Equals( "-O" ) )
916 nState
= STATE_OUTPUT
;
924 sIsoCode
= ByteString( argv
[ i
] );
930 sOutput
= ByteString( argv
[ i
] );
933 case STATE_LANGUAGES
:
934 if ( sLanguages
.Len())
936 sLanguages
= ByteString( argv
[ i
] );
940 if ( sFileName
.Len())
942 sFileName
= ByteString( argv
[ i
] );
950 if ( !bMerge
&& !bExport
) {
955 ByteString
sRoot( Export::GetEnv( "SRC_ROOT" ));
956 DirEntry
aRoot( String( sRoot
, RTL_TEXTENCODING_ASCII_US
));
957 sRoot
= ByteString( aRoot
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
958 ByteString
sVersion( Export::GetEnv( "WORK_STAMP" ));
960 if ( !sRoot
.Len() || !sVersion
.Len()) {
961 fprintf( stderr
, "ERROR: No environment set!\n" );
965 if ( !CheckLanguages( sLanguages
))
968 if ( !sFileName
.Len()) {
969 fprintf( stderr
, "ERROR: No filename given\n" );
973 ByteString
sMode( "merge" );
977 ByteString
sICode( sIsoCode
);
979 sICode
= "not given, support for language 99 disabled";
980 if(!bQuiet
&& !bQuiet2
){
983 "============================================================\n"
984 "Current settings:\n"
985 "============================================================\n"
990 "ISO code (99): %s\n"
993 "============================================================\n"
997 sVersion
.GetBuffer(),
999 sLanguages
.GetBuffer(),
1001 sFileName
.GetBuffer(),
1005 SourceTreeLocalizer
aIter( sRoot
, sVersion
, (sOutput
.Len() > 0) , bQuiet2
, bSkipLinks
);
1007 aIter
.SetLanguageRestriction( sLanguages
);
1008 aIter
.SetIsoCode99( sIsoCode
);
1010 if( bQuiet2
){ /*printf("");*/fflush( stdout
);}
1011 aIter
.Extract( sFileName
);
1012 if( bQuiet2
){ printf("\n %d files found!\n",aIter
.GetFileCnt());}
1016 DirEntry
aEntry( String( sFileName
, RTL_TEXTENCODING_ASCII_US
));
1017 if ( !aEntry
.Exists())
1019 printf("%s\n",sFileName
.GetBuffer());
1020 aIter
.Merge( sFileName
, sOutput
);