Skip to content

Commit

Permalink
first stab at unifying language handling - remove tdm_lang, the unuse…
Browse files Browse the repository at this point in the history
…d landuageDict and the restriction on sys_lang. TODO: move fontLang code into I18N module

git-svn-id: https://svn.thedarkmod.com/svn/darkmod_src/trunk@5249 49c82d7f-2e2a-0410-a16f-ae8f201b507f
  • Loading branch information
tels committed Feb 6, 2012
1 parent 68e9fd6 commit bfd44f4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 75 deletions.
45 changes: 1 addition & 44 deletions framework/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ idCVar com_videoRam( "com_videoRam", "64", CVAR_INTEGER | CVAR_SYSTEM | CVAR_NOC

idCVar com_product_lang_ext( "com_product_lang_ext", "1", CVAR_INTEGER | CVAR_SYSTEM | CVAR_ARCHIVE, "Extension to use when creating language files." );

// Tels: can be removed when D3 is open source and we can access sys_lang properly
idCVar cv_tdm_lang("tdm_lang", "english", CVAR_GUI | CVAR_ARCHIVE, "The current used language. Possible values are 'english', 'german', 'russian' etc." );


// com_speeds times
int time_gameFrame;
Expand Down Expand Up @@ -217,8 +214,6 @@ class idCommonLocal : public idCommon {

int gameDLL;

idLangDict languageDict; // legacy

#ifdef ID_WRITE_VERSION
idCompressor * config_compressor;
#endif
Expand Down Expand Up @@ -1711,12 +1706,8 @@ idCommonLocal::GetLanguageDict
*/
const idLangDict *idCommonLocal::GetLanguageDict( void )
{
#if 0
return &languageDict;
#endif

// Redirect the call to I18N
return GetI18N()->GetLanguageDict();
return i18n->GetLanguageDict();
}

I18N* idCommonLocal::GetI18N()
Expand Down Expand Up @@ -1749,39 +1740,8 @@ idCommonLocal::InitLanguageDict
===============
*/
void idCommonLocal::InitLanguageDict( void ) {
idStr fileName;
languageDict.Clear();

//D3XP: Instead of just loading a single lang file for each language
//we are going to load all files that begin with the language name
//similar to the way pak files work. So you can place english001.lang
//to add new strings to the english language dictionary
idFileList* langFiles;
langFiles = fileSystem->ListFilesTree( "strings", ".lang", true );

idStrList langList = langFiles->GetList();

StartupVariable( "sys_lang", false ); // let it be set on the command line - this is needed because this init happens very early
idStr langName = cvarSystem->GetCVarString( "sys_lang" );

//Loop through the list and filter
idStrList currentLangList = langList;
FilterLangList(&currentLangList, langName);

if ( currentLangList.Num() == 0 ) {
// reset cvar to default and try to load again
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "reset sys_lang" );
langName = cvarSystem->GetCVarString( "sys_lang" );
currentLangList = langList;
FilterLangList(&currentLangList, langName);
}

for( int i = 0; i < currentLangList.Num(); i++ ) {
//common->Printf("%s\n", currentLangList[i].c_str());
languageDict.Load( currentLangList[i], false );
}

fileSystem->FreeFileList(langFiles);

Sys_InitScanTable();
}
Expand Down Expand Up @@ -3037,9 +2997,6 @@ void idCommonLocal::Shutdown( void ) {
warningCaption.Clear();
errorList.Clear();

// free language dictionary
languageDict.Clear();

// enable leak test
Mem_EnableLeakTest( "doom" );

Expand Down
30 changes: 6 additions & 24 deletions framework/I18N.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ I18NLocal::Init
void I18NLocal::Init()
{
// some default values, the object becomes only fully usable after Init(), tho:
m_lang = cvarSystem->GetCVarString( "tdm_lang" );
m_lang = cvarSystem->GetCVarString( "sys_lang" );
m_bMoveArticles = (m_lang != "polish" && m_lang != "italian") ? true : false;

m_Dict.Clear();
Expand Down Expand Up @@ -184,7 +184,7 @@ void I18NLocal::Init()
m_Remap.Empty(); // by default, no remaps

// Create the correct dictionary
SetLanguage( cvarSystem->GetCVarString( "tdm_lang" ), true );
SetLanguage( cvarSystem->GetCVarString( "sys_lang" ), true );
}

/*
Expand Down Expand Up @@ -370,32 +370,14 @@ void I18NLocal::SetLanguage( const char* lang, bool firstTime ) {
m_lang = lang;

// set sys_lang
cvarSystem->SetCVarString("tdm_lang", lang);
cvarSystem->SetCVarString("sys_lang", lang);
m_bMoveArticles = (m_lang != "polish" && m_lang != "italian") ? true : false;

idStr newLang = idStr(lang);

// If we need to remap some characters upon loading one of these languages:
LoadCharacterMapping(newLang);

// For some reason, "english", "german", "french" and "spanish" share
// the same font, but "polish" and "russian" get their own font. But
// since "polish" is actually a copy of the normal western font, use
// "english" instead to trick D3 into loading the correct font. The
// dictionary below will be polish, regardless.
if (newLang == "polish")
{
newLang = "english";
}
// set sysvar sys_lang (if not possible, D3 will revert to english)
cvarSystem->SetCVarString( "sys_lang", newLang.c_str() );
LoadCharacterMapping(m_lang);

// If sys_lang differs from lang, the language was not supported, so
// we will load it ourselves.
if ( newLang != cvarSystem->GetCVarString( "sys_lang" ) )
{
common->Printf("I18NLocal: Language '%s' not supported by D3, forcing it.\n", lang);
}
// set sysvar sys_lang
cvarSystem->SetCVarString( "sys_lang", m_lang.c_str() );

// build our combined dictionary, first the TDM base dict
idStr file = "strings/"; file += m_lang + ".lang";
Expand Down
7 changes: 1 addition & 6 deletions sys/sys_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
static bool versioned = RegisterVersionedFile("$Id$");
#include "sys_local.h"

const char * sysLanguageNames[] = {
"english", "spanish", "italian", "german", "french", "russian",
"polish", "korean", "japanese", "chinese", NULL
};

idCVar sys_lang( "sys_lang", "english", CVAR_SYSTEM | CVAR_ARCHIVE, "", sysLanguageNames, idCmdSystem::ArgCompletion_String<sysLanguageNames> );
idCVar sys_lang( "sys_lang", "english", CVAR_SYSTEM | CVAR_ARCHIVE, "The current used language. Possible values are 'english', 'german', 'russian' etc." );

idSysLocal sysLocal;
idSys * sys = &sysLocal;
Expand Down
2 changes: 1 addition & 1 deletion ui/DeviceContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void idDeviceContext::SetupFonts() {
fontLang = cvarSystem->GetCVarString( "sys_lang" );

// western european languages can use the english font
if ( fontLang == "french" || fontLang == "german" || fontLang == "spanish" || fontLang == "italian" ) {
if ( fontLang == "french" || fontLang == "german" || fontLang == "spanish" || fontLang == "italian" || fontLang == "polish") {
fontLang = "english";
}

Expand Down

0 comments on commit bfd44f4

Please sign in to comment.