34static char buffer[100*1024];
35static char buffer2[100*1024];
36static OLECHAR olebuf[100*1024];
37static OLECHAR olebuf2[100*1024];
38static OLECHAR oletrans[100*1024];
41static int progress_count;
43static void progress_cb (
void )
49 progress_dlg->SetProgress ( progress_count );
55static void print_to_file (
const char *text )
58 fprintf ( cb_file,
"\t\t\tString %s\n", text );
62static void reverseWord ( OLECHAR *fp, OLECHAR *lp )
79 if ( f >=
'A' && f <=
'Z' )
81 if ( l >=
'a' && l <=
'z' )
99static void translateCopy( OLECHAR *outbuf, OLECHAR *inbuf )
104 static OLECHAR buffer[100*1024];
105 OLECHAR *firstLetter =
NULL, *lastLetter;
107 int formatWord =
FALSE;
110 while ( (ch = *inbuf++))
112 if ( ! (( ch >=
'a' && ch <=
'z') || ( ch >=
'A' && ch <=
'Z' )))
119 reverseWord ( firstLetter, lastLetter );
153 reverseWord ( firstLetter, lastLetter );
163 while( *inbuf !=
'\0' )
166 *outbuf++ = *inbuf++;
175 wcscpy ( olebuf,
label->Comment());
178 wcscpy ( olebuf,
label->Context());
181 wcscpy ( olebuf,
label->Speaker());
184 wcscpy ( olebuf,
label->Listener());
189static void writeText (
BabylonText *text,
int row )
192 int maxlen =
label->MaxLen ();
200 wcscpy ( olebuf, text->
Get());
207 swprintf ( buffer, L
"=IF(%c%d>%c%d,\"Too long!\",\" \")",
'A' +
CELL_STRLEN -1, row,
'A' +
CELL_MAXLEN -1, row );
212 writeLabel (
label, row );
245 swprintf ( buffer, L
"%S Translation",
GetLangName ( langid ));
254 int label_written =
FALSE;
255 text =
label->FirstText ( sh_text );
260 int bad_format =
FALSE;
261 int too_long =
FALSE;
267 export = !text->
IsSent ();
287 if ( ! (export = all) )
313 if ( export && text->
Len () )
323 static OLECHAR buffer[100*1024];
325 if ( !label_written )
330 label_written =
TRUE;
334 writeText ( text, row );
337 swprintf ( buffer, L
"%s%S.wav", text->
Wave (), linfo->
character );
350 translateCopy ( olebuf, text->
Get() );
354 wcscpy ( olebuf, trans->
Get());
359 if ( bad_format || too_long)
361 wcscpy ( olebuf, L
"ERROR: " );
364 wcscat ( olebuf, L
"too long" );
367 wcscat ( olebuf, L
"and " );
373 wcscat ( olebuf, L
"bad format" );
384 text =
label->NextText ( sh_text );
387 if ( limit && count > 50 )
408 exports = export_trans ( db, langid, options,
NULL,
FALSE );
414 AfxMessageBox (
"Nothing to export." );
421 if ( (progress_dlg = dlg) )
431 format =
"Exporting all strings";
434 format =
"Exporting all strings that require %s translation";
437 format =
"Exporting a sample %s translation file";
440 format =
"Exporting dialog only %s translation file";
443 format =
"Exporting non-dialog %s translation file";
446 format =
"Exporting all unverified %s dialog";
449 format =
"Exporting all missing %s dialog";
454 format =
"Undefined switch";
459 strcpy ( buffer2, format );
462 strcat ( buffer2,
" with current %s translations and translator comments" );
466 strcat ( buffer2,
" with %s translator comments" );
470 strcat ( buffer2,
" with current %s translations" );
472 strcat ( buffer2,
"..." );
477 _getcwd ( buffer,
sizeof ( buffer ) -1 );
479 strcat ( buffer,
"\\babylon.xlt" );
486 sprintf ( buffer2,
"Template file \"%s\" is missing. Cannot export.", buffer );
487 AfxMessageBox ( buffer2 );
488 dlg->
Log ( buffer2 );
499 if ( (exports = export_trans ( db, langid, options, progress_cb,
TRUE )) != -1 )
513 sprintf ( buffer2,
"Failed to save export!");
514 AfxMessageBox ( buffer2 );
515 dlg->
Log ( buffer2 );
527 sprintf ( buffer2,
"Failed to create new work book. File \"%s\" may be corrupt", buffer );
528 AfxMessageBox ( buffer2 );
529 dlg->
Log ( buffer2 );
548 int changes_count = 0;
549 int missing_count = 0;
550 int mismatch_count = 0;
552 int first_mismatch =
TRUE;
586 sprintf ( buffer,
"ERROR: expecting revision %d for string ID %d but found revision %d. Possible bad ID!", text->
Revision (),
id, revision );
607 if ( wcscmp ( text->
Get(), olebuf ) )
630 if ( !olebuf2[0] || wcscmp ( text->
Label ()->
Name(), olebuf2))
632 sprintf ( buffer,
"%S", olebuf );
638 bad_id = dlg.DoModal ()==IDNO;
672 if ( trans->
Revision () == revision && !wcscmp ( trans->
Get (), oletrans ))
678 trans->
Set ( oletrans );
700 sprintf ( buffer,
"Total found : %d", count );
704 sprintf ( buffer,
"New : %d", new_count);
708 sprintf ( buffer,
"Updates : %d", (changes_count - new_count));
713 sprintf ( buffer,
"Missing : %d", missing_count );
718 sprintf ( buffer,
"Unmatched : %d", stale_count);
728 sprintf ( buffer,
"Aborting import: BAD IDs");
732 AfxMessageBox (
"The imported translation file has bad string IDs! Fix the string IDs and re-import" );
746 int first_mismatch =
TRUE;
780 sprintf ( buffer,
"ERROR: expecting revision %d for string ID %d but found revision %d. Possible bad ID!", text->
Revision (),
id, revision );
792 if ( wcscmp ( text->
Get(), olebuf ) )
815 if ( !olebuf2[0] || wcscmp ( text->
Label ()->
Name(), olebuf2))
817 sprintf ( buffer,
"%S", olebuf );
823 bad_id = dlg.DoModal ()==IDNO;
866 sprintf ( buffer,
"Total found : %d", count );
870 sprintf ( buffer,
"Matched : %d", matched);
874 sprintf ( buffer,
"Unmatched : %d", unmatched);
880 sprintf ( buffer,
"changed : %d", changed);
890 sprintf ( buffer,
"Aborting import: BAD IDs");
894 AfxMessageBox (
"The imported translation file has bad string IDs! Fix the string IDs and re-import" );
907 sprintf ( buffer,
"Importing \"%s\"...", filename );
918 sprintf ( buffer,
"%S", olebuf );
925 AfxMessageBox (
"Import file is of an unknown language or is not a translation file" );
938 sprintf ( buffer,
"...%s", info->
name );
942 imports = import_trans ( db, info->
langid, progress_cb, dlg );
951 sprintf ( buffer2,
"Failed to open \"%s\"", buffer );
952 AfxMessageBox ( buffer2 );
953 dlg->
Log ( buffer2 );
970 if ( ! ( file = fopen ( filename,
"wt" ) ))
975 fprintf ( file,
"// Generated by %s\n",
AppTitle );
976 fprintf ( file,
"// Generated on %s %s\n\n\n", __DATE__, __TIME__ );
988 text =
label->FirstText ( sh_text );
990 fprintf ( file,
"\n\n%s\n",
label->NameSB ());
1002 string = text->
GetSB ();
1011 sprintf (
string,
"%d", text->
ID ());
1015 string = text->
GetSB();
1026 string = trans->
GetSB ();
1029 if ( text->
Len() == 0 )
1034 fprintf ( file,
"\"%s\" %s\n",
string, text->
WaveSB() );
1035 text =
label->NextText ( sh_text );
1038 fprintf ( file,
"END\n" );
1057 int len = strlen (
label->NameSB() );
1058 int strings =
label->NumStrings ();
1060 if ( fwrite ( &
id,
sizeof (
int ), 1, file ) != 1 )
1065 if ( fwrite ( &strings,
sizeof (
int ), 1, file ) != 1 )
1070 if ( fwrite ( &len,
sizeof (
int ), 1, file ) != 1 )
1080 if ( fwrite (
label->NameSB(), len, 1, file ) != 1 )
1088static int writeCSFString ( FILE *file, OLECHAR *
string,
char *wave,
LANGINFO *linfo )
1092 int wlen = strlen ( wave );
1099 wcscpy ( olebuf,
string );
1102 len = wcslen ( olebuf );
1105 OLECHAR *ptr = olebuf;
1114 if ( fwrite ( &
id,
sizeof (
int ), 1, file ) != 1 )
1119 if ( fwrite ( &len,
sizeof (
int ), 1, file ) != 1 )
1126 if ( fwrite ( olebuf, len*
sizeof(OLECHAR), 1, file ) != 1 )
1134 if ( fwrite ( &wlen,
sizeof (
int ), 1, file ) != 1 )
1139 if ( fwrite ( wave, wlen-1, 1, file ) != 1 )
1143 if ( fwrite ( linfo->
character, 1, 1, file ) != 1 )
1159 if ( ! ( file = fopen ( filename,
"w+b" ) ))
1170 header_size =
sizeof ( header );
1172 fseek ( file, header_size,
SEEK_SET );
1184 text =
label->FirstText ( sh_text );
1186 if ( !writeCSFLabel ( file,
label ) )
1202 string = text->
Get ();
1211 swprintf (
string, L
"%d", text->
ID ());
1215 string = text->
Get();
1226 string = trans->
Get ();
1229 if ( !writeCSFString ( file,
string, text->
WaveSB (), linfo ) )
1235 text =
label->NextText ( sh_text );
1242 if ( fwrite ( &header, header_size, 1, file ) != 1 )
1266 static char filename[2*1024];
1273 LangID *temp = languages;
1281 dlg->
Status (
"Generating game files:" );
1297 strlwr ( filename );
1301 sprintf ( buffer,
"Writing: %s - %s...", filename,
GetLangName ( langid ));
1310 done = generate_Babylonstr ( db, filename, langid, options );
1314 done = generate_csf ( db, filename, langid, options );
1322 if ( trnwarning || dlgwarning )
1332 sprintf ( buffer,
"%d translation%s missing", missing, missing > 1 ?
"s are" :
" is" );
1333 dlg->
Log ( buffer );
1338 sprintf ( buffer,
"%d string%s too big", trnreport.
too_big, trnreport.
too_big > 1 ?
"s are" :
" is" );
1339 dlg->
Log ( buffer );
1344 sprintf ( buffer,
"%d translation%s bad format", trnreport.
bad_format, trnreport.
bad_format > 1 ?
"s have a" :
" has a" );
1345 dlg->
Log ( buffer );
1353 sprintf ( buffer,
"%d dialog%s missing", dlgreport.
missing, dlgreport.
missing > 1 ?
"s are" :
" is" );
1354 dlg->
Log ( buffer );
1359 sprintf ( buffer,
"%d dialog%s not verified", dlgreport.
unresolved, dlgreport.
unresolved> 1 ?
"s are" :
" is" );
1360 dlg->
Log ( buffer );
1401 sprintf ( buffer,
"Processing wavefile \"%s\"...", filename );
1414 strcpy ( buffer, filename );
1416 if ( (ptr = strchr ( buffer,
'.' )) )
1421 strcat ( buffer,
".txt" );
1423 if ( (file = fopen (buffer,
"wt" )))
1426 while ( row - last_row < 1000 )
1430 GetString ( row,
'J' -
'A' + 1, olebuf );
1434 if ( wcsstr ( olebuf, L
".wav" ) )
1438 fprintf ( file,
"%S : ", olebuf );
1439 GetString ( row,
'K' -
'A' + 1, olebuf );
1444 fprintf ( file,
"%6d", text->
LineNumber () );
1448 fprintf ( file,
"??????" );
1451 fprintf ( file,
" - \"%S\"\n", olebuf );
1467 sprintf ( buffer2,
"Failed to open \"%s\"", buffer );
1468 AfxMessageBox ( buffer2 );
1469 dlg->
Log ( buffer2 );
1490 LangID *temp = languages;
1498 dlg->
Status (
"Generating Report:" );
1503 if ( ! ( file = fopen ( filename,
"wt" )))
1505 static char buffer[500];
1507 sprintf (
"Unable to open file \"%s\".\n\nCannot create report!", filename);
1508 AfxMessageBox ( buffer );
1525 fprintf ( file,
"Babylon Report: %s %s\n", date, time);
1538 fprintf ( file,
"\n\n%s Status:\n", info->
name );
1547 fprintf ( file,
"\n\tText Summary: %s\n", info->
name );
1548 fprintf ( file,
"\t-------------\n\n");
1550 fprintf ( file,
"\t\tErrors: %d\n", tr_report.
errors);
1554 fprintf ( file,
"\t\tNot translated: %d\n", tr_report.
missing);
1555 fprintf ( file,
"\t\tRetranslation: %d\n", tr_report.
retranslate);
1556 fprintf ( file,
"\t\tTranslated: %d\n", tr_report.
translated );
1558 fprintf ( file,
"\t\tTotal text: %d\n", tr_report.
numstrings );
1560 if ( count && count < options->limit )
1562 fprintf ( file,
"\n\tText Details: %s\n", info->
name);
1563 fprintf ( file,
"\t------------\n\n" );
1575 fprintf ( file,
"\n\tDialog Summary: %s\n", info->
name );
1576 fprintf ( file,
"\t-------------\n\n");
1578 fprintf ( file,
"\t\tMissing Audio: %d\n", dlg_report.
missing);
1579 fprintf ( file,
"\t\tNot verified: %d\n", dlg_report.
unresolved);
1580 fprintf ( file,
"\t\tVerified: %d\n", dlg_report.
resolved);
1581 fprintf ( file,
"\t\tTotal dialog: %d\n", dlg_report.
numdialog );
1583 if ( count && count < options->limit )
1585 fprintf ( file,
"\n\tDialog Details: %s\n", info->
name );
1586 fprintf ( file,
"\t------------\n\n" );
1587 db->
ReportDialog ( &dlg_report, langid, print_to_file );
1616 sprintf ( buffer,
"Importing \"%s\"...", filename );
1627 sprintf ( buffer,
"%S", olebuf );
1634 AfxMessageBox (
"Import file is of an unknown language or is not a translation file" );
1647 sprintf ( buffer,
"...%s", info->
name );
1651 imports = update_sent_trans ( db, info->
langid, progress_cb, dlg );
1660 sprintf ( buffer2,
"Failed to open \"%s\"", buffer );
1661 AfxMessageBox ( buffer2 );
1662 dlg->
Log ( buffer2 );
char DialogPath[_MAX_PATH]
#define CSF_STRINGWITHWAVE
char * GetLangName(LangID langid)
LANGINFO * GetLangInfo(int index)
int PutCell(int row, int column, OLECHAR *string, int val)
int GetInt(int row, int cell)
int GetString(int row, int cell, OLECHAR *string)
int SaveWorkBook(const char *filename, int protect)
int OpenWorkBook(const char *filename)
int NewWorkBook(const char *path)
BabylonText * FindText(OLECHAR *find_text)
int DialogIsValid(const char *path, LangID langid=LANGID_US, int check=TRUE)
BabylonLabel * Label(void)
Translation * GetTranslation(LangID langid)
int DialogIsPresent(const char *path, LangID langid=LANGID_US)
void AddTranslation(Translation *trans)
void SetProgress(int pos)
void Status(const char *string, int log=TRUE)
void InitProgress(int range)
void Log(const char *string, LogFormat format=NEW_LINE)
void SetValid(int new_valid)
BabylonLabel * FirstLabel(ListSearch &sh)
BabylonText * FindSubText(OLECHAR *text, int item=0)
int ReportDialog(DLGREPORT *report, LangID langid, void(*print)(const char *)=NULL, PMASK pmask=PMASK_ALL)
int ReportTranslations(TRNREPORT *report, LangID langid, void(*print)(const char *)=NULL, PMASK pmask=PMASK_ALL)
BabylonLabel * NextLabel(ListSearch &sh)
BabylonText * FindText(OLECHAR *text)
void SetRevision(int new_rev)
int ValidateFormat(BabylonText *text)
void Set(OLECHAR *string)
void SetLangID(LangID new_id)
int GenerateGameFiles(TransDB *db, const char *filepattern, GNOPTIONS *options, LangID *languages, CBabylonDlg *dlg)
int UpdateSentTranslations(TransDB *db, const char *filename, CBabylonDlg *dlg)
int ImportTranslations(TransDB *db, const char *filename, CBabylonDlg *dlg)
int ExportTranslations(TransDB *db, const char *filename, LangID langid, TROPTIONS *options, CBabylonDlg *dlg)
void ProcessWaves(TransDB *db, const char *filename, CBabylonDlg *dlg)
int GenerateReport(TransDB *db, const char *filename, RPOPTIONS *options, LangID *languages, CBabylonDlg *dlg)
int FileExists(const char *filename)
void EncodeFormat(text *string)
void ConvertMetaChars(text *string)
void DecodeFormat(text *string)
void StripSpaces(text *string)
int IsFormatTypeChar(text ch)
GnUntranslated untranslated