2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
2012-12-22 15:18:19 +00:00
|
|
|
#include "precompiled.h"
|
2012-11-26 18:58:24 +00:00
|
|
|
#pragma hdrstop
|
|
|
|
|
|
|
|
#include "Common_local.h"
|
|
|
|
|
|
|
|
idCVar com_product_lang_ext( "com_product_lang_ext", "1", CVAR_INTEGER | CVAR_SYSTEM | CVAR_ARCHIVE, "Extension to use when creating language files." );
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
LoadMapLocalizeData
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
typedef idHashTable<idStrList> ListHash;
|
2012-11-28 15:47:07 +00:00
|
|
|
void LoadMapLocalizeData( ListHash& listHash )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idStr fileName = "map_localize.cfg";
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* buffer = NULL;
|
2012-11-26 18:58:24 +00:00
|
|
|
idLexer src( LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( fileSystem->ReadFile( fileName, ( void** )&buffer ) > 0 )
|
|
|
|
{
|
|
|
|
src.LoadMemory( buffer, strlen( buffer ), fileName );
|
|
|
|
if( src.IsLoaded() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr classname;
|
|
|
|
idToken token;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while( src.ReadToken( &token ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
classname = token;
|
|
|
|
src.ExpectTokenString( "{" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStrList list;
|
2012-11-28 15:47:07 +00:00
|
|
|
while( src.ReadToken( &token ) )
|
|
|
|
{
|
|
|
|
if( token == "}" )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
list.Append( token );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
listHash.Set( classname, list );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
fileSystem->FreeFile( ( void* )buffer );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void LoadGuiParmExcludeList( idStrList& list )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idStr fileName = "guiparm_exclude.cfg";
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* buffer = NULL;
|
2012-11-26 18:58:24 +00:00
|
|
|
idLexer src( LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( fileSystem->ReadFile( fileName, ( void** )&buffer ) > 0 )
|
|
|
|
{
|
|
|
|
src.LoadMemory( buffer, strlen( buffer ), fileName );
|
|
|
|
if( src.IsLoaded() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr classname;
|
|
|
|
idToken token;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while( src.ReadToken( &token ) )
|
|
|
|
{
|
|
|
|
list.Append( token );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
fileSystem->FreeFile( ( void* )buffer );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
bool TestMapVal( idStr& str )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Already Localized?
|
2012-11-28 15:47:07 +00:00
|
|
|
if( str.Find( "#str_" ) != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
bool TestGuiParm( const char* parm, const char* value, idStrList& excludeList )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idStr testVal = value;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Already Localized?
|
2012-11-28 15:47:07 +00:00
|
|
|
if( testVal.Find( "#str_" ) != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Numeric
|
2012-11-28 15:47:07 +00:00
|
|
|
if( testVal.IsNumeric() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Contains ::
|
2012-11-28 15:47:07 +00:00
|
|
|
if( testVal.Find( "::" ) != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Contains /
|
2012-11-28 15:47:07 +00:00
|
|
|
if( testVal.Find( "/" ) != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( excludeList.Find( testVal ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void GetFileList( const char* dir, const char* ext, idStrList& list )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
//Recurse Subdirectories
|
|
|
|
idStrList dirList;
|
2012-11-28 15:47:07 +00:00
|
|
|
Sys_ListFiles( dir, "/", dirList );
|
|
|
|
for( int i = 0; i < dirList.Num(); i++ )
|
|
|
|
{
|
|
|
|
if( dirList[i] == "." || dirList[i] == ".." )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idStr fullName = va( "%s/%s", dir, dirList[i].c_str() );
|
|
|
|
GetFileList( fullName, ext, list );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStrList fileList;
|
2012-11-28 15:47:07 +00:00
|
|
|
Sys_ListFiles( dir, ext, fileList );
|
|
|
|
for( int i = 0; i < fileList.Num(); i++ )
|
|
|
|
{
|
|
|
|
idStr fullName = va( "%s/%s", dir, fileList[i].c_str() );
|
|
|
|
list.Append( fullName );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
int LocalizeMap( const char* mapName, idLangDict& langDict, ListHash& listHash, idStrList& excludeList, bool writeFile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
common->Printf( "Localizing Map '%s'\n", mapName );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int strCount = 0;
|
|
|
|
|
|
|
|
idMapFile map;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( map.Parse( mapName, false, false ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int count = map.GetNumEntities();
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int j = 0; j < count; j++ )
|
|
|
|
{
|
|
|
|
idMapEntity* ent = map.GetEntity( j );
|
|
|
|
if( ent )
|
|
|
|
{
|
|
|
|
|
|
|
|
idStr classname = ent->epairs.GetString( "classname" );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Hack: for info_location
|
|
|
|
bool hasLocation = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStrList* list;
|
2012-11-28 15:47:07 +00:00
|
|
|
listHash.Get( classname, &list );
|
|
|
|
if( list )
|
|
|
|
{
|
|
|
|
|
|
|
|
for( int k = 0; k < list->Num(); k++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
idStr val = ent->epairs.GetString( ( *list )[k], "" );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( val.Length() && classname == "info_location" && ( *list )[k] == "location" )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
hasLocation = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( val.Length() && TestMapVal( val ) )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !hasLocation || ( *list )[k] == "location" )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Localize it!!!
|
|
|
|
strCount++;
|
2012-11-28 15:47:07 +00:00
|
|
|
ent->epairs.Set( ( *list )[k], langDict.AddString( val ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
listHash.Get( "all", &list );
|
|
|
|
if( list )
|
|
|
|
{
|
|
|
|
for( int k = 0; k < list->Num(); k++ )
|
|
|
|
{
|
|
|
|
idStr val = ent->epairs.GetString( ( *list )[k], "" );
|
|
|
|
if( val.Length() && TestMapVal( val ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Localize it!!!
|
|
|
|
strCount++;
|
2012-11-28 15:47:07 +00:00
|
|
|
ent->epairs.Set( ( *list )[k], langDict.AddString( val ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Localize the gui_parms
|
2012-11-28 15:47:07 +00:00
|
|
|
const idKeyValue* kv = ent->epairs.MatchPrefix( "gui_parm" );
|
|
|
|
while( kv )
|
|
|
|
{
|
|
|
|
if( TestGuiParm( kv->GetKey(), kv->GetValue(), excludeList ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Localize It!
|
|
|
|
strCount++;
|
|
|
|
ent->epairs.Set( kv->GetKey(), langDict.AddString( kv->GetValue() ) );
|
|
|
|
}
|
|
|
|
kv = ent->epairs.MatchPrefix( "gui_parm", kv );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( writeFile && strCount > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Before we write the map file lets make a backup of the original
|
2012-11-28 15:47:07 +00:00
|
|
|
idStr file = fileSystem->RelativePathToOSPath( mapName );
|
|
|
|
idStr bak = file.Left( file.Length() - 4 );
|
|
|
|
bak.Append( ".bak_loc" );
|
2012-11-26 18:58:24 +00:00
|
|
|
fileSystem->CopyFile( file, bak );
|
|
|
|
|
|
|
|
map.Write( mapName, ".map" );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
common->Printf( "Count: %d\n", strCount );
|
2012-11-26 18:58:24 +00:00
|
|
|
return strCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
LocalizeMaps_f
|
|
|
|
=================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
CONSOLE_COMMAND( localizeMaps, "localize maps", NULL )
|
|
|
|
{
|
|
|
|
if( args.Argc() < 2 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "Usage: localizeMaps <count | dictupdate | all> <map>\n" );
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int strCount = 0;
|
|
|
|
|
|
|
|
bool count = false;
|
|
|
|
bool dictUpdate = false;
|
|
|
|
bool write = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( idStr::Icmp( args.Argv( 1 ), "count" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
count = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( idStr::Icmp( args.Argv( 1 ), "dictupdate" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
count = true;
|
|
|
|
dictUpdate = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( idStr::Icmp( args.Argv( 1 ), "all" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
count = true;
|
|
|
|
dictUpdate = true;
|
|
|
|
write = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "Invalid Command\n" );
|
|
|
|
common->Printf( "Usage: localizeMaps <count | dictupdate | all>\n" );
|
|
|
|
return;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idLangDict strTable;
|
2012-11-28 15:47:07 +00:00
|
|
|
idStr filename = va( "strings/english%.3i.lang", com_product_lang_ext.GetInteger() );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
|
|
|
// I think this is equivalent...
|
2012-11-28 15:47:07 +00:00
|
|
|
const byte* buffer = NULL;
|
|
|
|
int len = fileSystem->ReadFile( filename, ( void** )&buffer );
|
|
|
|
if( verify( len > 0 ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
strTable.Load( buffer, len, filename );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
fileSystem->FreeFile( ( void* )buffer );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// ... to this
|
|
|
|
//if ( strTable.Load( filename ) == false) {
|
|
|
|
// //This is a new file so set the base index
|
|
|
|
// strTable.SetBaseID(com_product_lang_ext.GetInteger()*100000);
|
|
|
|
//}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
common->SetRefreshOnPrint( true );
|
|
|
|
|
|
|
|
ListHash listHash;
|
2012-11-28 15:47:07 +00:00
|
|
|
LoadMapLocalizeData( listHash );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStrList excludeList;
|
2012-11-28 15:47:07 +00:00
|
|
|
LoadGuiParmExcludeList( excludeList );
|
|
|
|
|
|
|
|
if( args.Argc() == 3 )
|
|
|
|
{
|
|
|
|
strCount += LocalizeMap( args.Argv( 2 ), strTable, listHash, excludeList, write );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStrList files;
|
2012-11-28 15:47:07 +00:00
|
|
|
GetFileList( "z:/d3xp/d3xp/maps/game", "*.map", files );
|
|
|
|
for( int i = 0; i < files.Num(); i++ )
|
|
|
|
{
|
|
|
|
idStr file = fileSystem->OSPathToRelativePath( files[i] );
|
|
|
|
strCount += LocalizeMap( file, strTable, listHash, excludeList, write );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( count )
|
|
|
|
{
|
|
|
|
common->Printf( "Localize String Count: %d\n", strCount );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
common->SetRefreshOnPrint( false );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( dictUpdate )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
strTable.Save( filename );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
LocalizeGuis_f
|
|
|
|
=================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
CONSOLE_COMMAND( localizeGuis, "localize guis", NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( args.Argc() != 2 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "Usage: localizeGuis <all | gui>\n" );
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idLangDict strTable;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idStr filename = va( "strings/english%.3i.lang", com_product_lang_ext.GetInteger() );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
{
|
|
|
|
// I think this is equivalent...
|
2012-11-28 15:47:07 +00:00
|
|
|
const byte* buffer = NULL;
|
|
|
|
int len = fileSystem->ReadFile( filename, ( void** )&buffer );
|
|
|
|
if( verify( len > 0 ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
strTable.Load( buffer, len, filename );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
fileSystem->FreeFile( ( void* )buffer );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// ... to this
|
|
|
|
//if(strTable.Load( filename ) == false) {
|
|
|
|
// //This is a new file so set the base index
|
|
|
|
// strTable.SetBaseID(com_product_lang_ext.GetInteger()*100000);
|
|
|
|
//}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idFileList* files;
|
|
|
|
if( idStr::Icmp( args.Argv( 1 ), "all" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr game = cvarSystem->GetCVarString( "game_expansion" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( game.Length() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
files = fileSystem->ListFilesTree( "guis", "*.gui", true, game );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
files = fileSystem->ListFilesTree( "guis", "*.gui", true );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < files->GetNumFiles(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
commonLocal.LocalizeGui( files->GetFile( i ), strTable );
|
|
|
|
}
|
|
|
|
fileSystem->FreeFileList( files );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( game.Length() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
files = fileSystem->ListFilesTree( "guis", "*.pd", true, game );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
files = fileSystem->ListFilesTree( "guis", "*.pd", true, "d3xp" );
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < files->GetNumFiles(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
commonLocal.LocalizeGui( files->GetFile( i ), strTable );
|
|
|
|
}
|
|
|
|
fileSystem->FreeFileList( files );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
commonLocal.LocalizeGui( args.Argv( 1 ), strTable );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
strTable.Save( filename );
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
CONSOLE_COMMAND( localizeGuiParmsTest, "Create test files that show gui parms localized and ignored.", NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
common->SetRefreshOnPrint( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idFile* localizeFile = fileSystem->OpenFileWrite( "gui_parm_localize.csv" );
|
|
|
|
idFile* noLocalizeFile = fileSystem->OpenFileWrite( "gui_parm_nolocalize.csv" );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStrList excludeList;
|
2012-11-28 15:47:07 +00:00
|
|
|
LoadGuiParmExcludeList( excludeList );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStrList files;
|
2012-11-28 15:47:07 +00:00
|
|
|
GetFileList( "z:/d3xp/d3xp/maps/game", "*.map", files );
|
|
|
|
|
|
|
|
for( int i = 0; i < files.Num(); i++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
common->Printf( "Testing Map '%s'\n", files[i].c_str() );
|
2012-11-26 18:58:24 +00:00
|
|
|
idMapFile map;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idStr file = fileSystem->OSPathToRelativePath( files[i] );
|
|
|
|
if( map.Parse( file, false, false ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int count = map.GetNumEntities();
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int j = 0; j < count; j++ )
|
|
|
|
{
|
|
|
|
idMapEntity* ent = map.GetEntity( j );
|
|
|
|
if( ent )
|
|
|
|
{
|
|
|
|
const idKeyValue* kv = ent->epairs.MatchPrefix( "gui_parm" );
|
|
|
|
while( kv )
|
|
|
|
{
|
|
|
|
if( TestGuiParm( kv->GetKey(), kv->GetValue(), excludeList ) )
|
|
|
|
{
|
|
|
|
idStr out = va( "%s,%s,%s\r\n", kv->GetValue().c_str(), kv->GetKey().c_str(), file.c_str() );
|
2012-11-26 18:58:24 +00:00
|
|
|
localizeFile->Write( out.c_str(), out.Length() );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idStr out = va( "%s,%s,%s\r\n", kv->GetValue().c_str(), kv->GetKey().c_str(), file.c_str() );
|
2012-11-26 18:58:24 +00:00
|
|
|
noLocalizeFile->Write( out.c_str(), out.Length() );
|
|
|
|
}
|
|
|
|
kv = ent->epairs.MatchPrefix( "gui_parm", kv );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fileSystem->CloseFile( localizeFile );
|
|
|
|
fileSystem->CloseFile( noLocalizeFile );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
common->SetRefreshOnPrint( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
CONSOLE_COMMAND( localizeMapsTest, "Create test files that shows which strings will be localized.", NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
ListHash listHash;
|
2012-11-28 15:47:07 +00:00
|
|
|
LoadMapLocalizeData( listHash );
|
|
|
|
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
common->SetRefreshOnPrint( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idFile* localizeFile = fileSystem->OpenFileWrite( "map_localize.csv" );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idStrList files;
|
2012-11-28 15:47:07 +00:00
|
|
|
GetFileList( "z:/d3xp/d3xp/maps/game", "*.map", files );
|
|
|
|
|
|
|
|
for( int i = 0; i < files.Num(); i++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
common->Printf( "Testing Map '%s'\n", files[i].c_str() );
|
2012-11-26 18:58:24 +00:00
|
|
|
idMapFile map;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idStr file = fileSystem->OSPathToRelativePath( files[i] );
|
|
|
|
if( map.Parse( file, false, false ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int count = map.GetNumEntities();
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int j = 0; j < count; j++ )
|
|
|
|
{
|
|
|
|
idMapEntity* ent = map.GetEntity( j );
|
|
|
|
if( ent )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Temp code to get a list of all entity key value pairs
|
|
|
|
/*idStr classname = ent->epairs.GetString("classname");
|
|
|
|
if(classname == "worldspawn" || classname == "func_static" || classname == "light" || classname == "speaker" || classname.Left(8) == "trigger_") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for( int i = 0; i < ent->epairs.GetNumKeyVals(); i++) {
|
|
|
|
const idKeyValue* kv = ent->epairs.GetKeyVal(i);
|
|
|
|
idStr out = va("%s,%s,%s,%s\r\n", classname.c_str(), kv->GetKey().c_str(), kv->GetValue().c_str(), file.c_str());
|
|
|
|
localizeFile->Write( out.c_str(), out.Length() );
|
|
|
|
}*/
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idStr classname = ent->epairs.GetString( "classname" );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
//Hack: for info_location
|
|
|
|
bool hasLocation = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStrList* list;
|
2012-11-28 15:47:07 +00:00
|
|
|
listHash.Get( classname, &list );
|
|
|
|
if( list )
|
|
|
|
{
|
|
|
|
|
|
|
|
for( int k = 0; k < list->Num(); k++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
idStr val = ent->epairs.GetString( ( *list )[k], "" );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( classname == "info_location" && ( *list )[k] == "location" )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
hasLocation = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( val.Length() && TestMapVal( val ) )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !hasLocation || ( *list )[k] == "location" )
|
|
|
|
{
|
|
|
|
idStr out = va( "%s,%s,%s\r\n", val.c_str(), ( *list )[k].c_str(), file.c_str() );
|
2012-11-26 18:58:24 +00:00
|
|
|
localizeFile->Write( out.c_str(), out.Length() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
listHash.Get( "all", &list );
|
|
|
|
if( list )
|
|
|
|
{
|
|
|
|
for( int k = 0; k < list->Num(); k++ )
|
|
|
|
{
|
|
|
|
idStr val = ent->epairs.GetString( ( *list )[k], "" );
|
|
|
|
if( val.Length() && TestMapVal( val ) )
|
|
|
|
{
|
|
|
|
idStr out = va( "%s,%s,%s\r\n", val.c_str(), ( *list )[k].c_str(), file.c_str() );
|
2012-11-26 18:58:24 +00:00
|
|
|
localizeFile->Write( out.c_str(), out.Length() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
fileSystem->CloseFile( localizeFile );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
common->SetRefreshOnPrint( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idCommonLocal::LocalizeSpecificMapData
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idCommonLocal::LocalizeSpecificMapData( const char* fileName, idLangDict& langDict, const idLangDict& replaceArgs )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr out, ws, work;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idMapFile map;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( map.Parse( fileName, false, false ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int count = map.GetNumEntities();
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < count; i++ )
|
|
|
|
{
|
|
|
|
idMapEntity* ent = map.GetEntity( i );
|
|
|
|
if( ent )
|
|
|
|
{
|
|
|
|
for( int j = 0; j < replaceArgs.GetNumKeyVals(); j++ )
|
|
|
|
{
|
|
|
|
const idLangKeyValue* kv = replaceArgs.GetKeyVal( j );
|
|
|
|
const char* temp = ent->epairs.GetString( kv->key );
|
|
|
|
if( ( temp != NULL ) && *temp )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr val = kv->value;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( val == temp )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent->epairs.Set( kv->key, langDict.AddString( temp ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
map.Write( fileName, ".map" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idCommonLocal::LocalizeMapData
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idCommonLocal::LocalizeMapData( const char* fileName, idLangDict& langDict )
|
|
|
|
{
|
|
|
|
const char* buffer = NULL;
|
2012-11-26 18:58:24 +00:00
|
|
|
idLexer src( LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
common->SetRefreshOnPrint( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( fileSystem->ReadFile( fileName, ( void** )&buffer ) > 0 )
|
|
|
|
{
|
|
|
|
src.LoadMemory( buffer, strlen( buffer ), fileName );
|
|
|
|
if( src.IsLoaded() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "Processing %s\n", fileName );
|
|
|
|
idStr mapFileName;
|
|
|
|
idToken token, token2;
|
|
|
|
idLangDict replaceArgs;
|
2012-11-28 15:47:07 +00:00
|
|
|
while( src.ReadToken( &token ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
mapFileName = token;
|
|
|
|
replaceArgs.Clear();
|
|
|
|
src.ExpectTokenString( "{" );
|
2012-11-28 15:47:07 +00:00
|
|
|
while( src.ReadToken( &token ) )
|
|
|
|
{
|
|
|
|
if( token == "}" )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( src.ReadToken( &token2 ) )
|
|
|
|
{
|
|
|
|
if( token2 == "}" )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
replaceArgs.AddKeyVal( token, token2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
common->Printf( " localizing map %s...\n", mapFileName.c_str() );
|
|
|
|
LocalizeSpecificMapData( mapFileName, langDict, replaceArgs );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
fileSystem->FreeFile( ( void* )buffer );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
common->SetRefreshOnPrint( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idCommonLocal::LocalizeGui
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idCommonLocal::LocalizeGui( const char* fileName, idLangDict& langDict )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr out, ws, work;
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* buffer = NULL;
|
2012-11-26 18:58:24 +00:00
|
|
|
out.Empty();
|
|
|
|
int k;
|
|
|
|
char ch;
|
|
|
|
char slash = '\\';
|
|
|
|
char tab = 't';
|
|
|
|
char nl = 'n';
|
|
|
|
idLexer src( LEXFL_NOFATALERRORS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( fileSystem->ReadFile( fileName, ( void** )&buffer ) > 0 )
|
|
|
|
{
|
|
|
|
src.LoadMemory( buffer, strlen( buffer ), fileName );
|
|
|
|
if( src.IsLoaded() )
|
|
|
|
{
|
|
|
|
idFile* outFile = fileSystem->OpenFileWrite( fileName );
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Printf( "Processing %s\n", fileName );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
const bool captureToImage = false;
|
|
|
|
UpdateScreen( captureToImage );
|
|
|
|
idToken token;
|
2012-11-28 15:47:07 +00:00
|
|
|
while( src.ReadToken( &token ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
src.GetLastWhiteSpace( ws );
|
|
|
|
out += ws;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( token.type == TT_STRING )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
out += va( "\"%s\"", token.c_str() );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
out += token;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( out.Length() > 200000 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
outFile->Write( out.c_str(), out.Length() );
|
|
|
|
out = "";
|
|
|
|
}
|
|
|
|
work = token.Right( 6 );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( token.Icmp( "text" ) == 0 || work.Icmp( "::text" ) == 0 || token.Icmp( "choices" ) == 0 )
|
|
|
|
{
|
|
|
|
if( src.ReadToken( &token ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// see if already exists, if so save that id to this position in this file
|
|
|
|
// otherwise add this to the list and save the id to this position in this file
|
|
|
|
src.GetLastWhiteSpace( ws );
|
|
|
|
out += ws;
|
|
|
|
token = langDict.AddString( token );
|
|
|
|
out += "\"";
|
2012-11-28 15:47:07 +00:00
|
|
|
for( k = 0; k < token.Length(); k++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ch = token[k];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ch == '\t' )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
out += slash;
|
|
|
|
out += tab;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( ch == '\n' || ch == '\r' )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
out += slash;
|
|
|
|
out += nl;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
out += ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out += "\"";
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( token.Icmp( "comment" ) == 0 )
|
|
|
|
{
|
|
|
|
if( src.ReadToken( &token ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// need to write these out by hand to preserve any \n's
|
|
|
|
// see if already exists, if so save that id to this position in this file
|
|
|
|
// otherwise add this to the list and save the id to this position in this file
|
|
|
|
src.GetLastWhiteSpace( ws );
|
|
|
|
out += ws;
|
|
|
|
out += "\"";
|
2012-11-28 15:47:07 +00:00
|
|
|
for( k = 0; k < token.Length(); k++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ch = token[k];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ch == '\t' )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
out += slash;
|
|
|
|
out += tab;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( ch == '\n' || ch == '\r' )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
out += slash;
|
|
|
|
out += nl;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
out += ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out += "\"";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
outFile->Write( out.c_str(), out.Length() );
|
|
|
|
fileSystem->CloseFile( outFile );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
fileSystem->FreeFile( ( void* )buffer );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|