1
0
Fork 0

Erik Hofman:

This adds supports for a language specific font, defined in locale.xml
I've also moved the fgInitLocale() routine from main.cxx to fg_init.cxx
to prevent an ungly extern definition in options.cxx.
This commit is contained in:
curt 2002-10-07 15:45:00 +00:00
parent cf96178ea8
commit 9dcf7dd13f
5 changed files with 96 additions and 88 deletions

View file

@ -195,7 +195,8 @@ void guiInit()
} }
// Install our fast fonts // Install our fast fonts
fntpath.append(fgGetString("/sim/font", "typewriter.txf")); SGPropertyNode *locale = globals->get_locale();
fntpath.append(locale->getStringValue("font", "typewriter.txf"));
guiFntHandle = new fntTexFont ; guiFntHandle = new fntTexFont ;
guiFntHandle -> load ( (char *)fntpath.c_str() ) ; guiFntHandle -> load ( (char *)fntpath.c_str() ) ;
puFont GuiFont ( guiFntHandle, 15 ) ; puFont GuiFont ( guiFntHandle, 15 ) ;

View file

@ -302,6 +302,96 @@ bool fgInitConfig ( int argc, char **argv ) {
return true; return true;
} }
// Initialize the localization
SGPropertyNode *fgInitLocale(const char *language) {
SGPropertyNode *c_node = NULL, *d_node = NULL;
SGPropertyNode *intl = fgGetNode("/sim/intl");
SG_LOG(SG_GENERAL, SG_INFO, "Selecting language: " << language );
// localization not defined
if (!intl)
return NULL;
//
// Select the proper language from the list
//
vector<SGPropertyNode_ptr> locale = intl->getChildren("locale");
for (unsigned int i = 0; i < locale.size(); i++) {
vector<SGPropertyNode_ptr> lang = locale[i]->getChildren("lang");
for (unsigned int j = 0; j < lang.size(); j++) {
if (!strcmp(lang[j]->getStringValue(), language)) {
c_node = locale[i];
break;
}
}
}
// Get the defaults
d_node = intl->getChild("locale");
if (!c_node)
c_node = d_node;
// Check for localized font
SGPropertyNode *font_n = c_node->getNode("font", true);
if ( !strcmp(font_n->getStringValue(), "") )
font_n->setStringValue(d_node->getStringValue("font", "typewriter.txf"));
//
// Load the default strings
//
SGPath d_path( globals->get_fg_root() );
const char *d_path_str = d_node->getStringValue("strings");
if (!d_path_str) {
SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
return NULL;
}
d_path.append(d_path_str);
SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
<< d_path.str());
SGPropertyNode *strings = c_node->getNode("strings");
try {
readProperties(d_path.str(), strings);
} catch (const sg_exception &e) {
SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
return NULL;
}
//
// Load the language specific strings
//
if (c_node != d_node) {
SGPath c_path( globals->get_fg_root() );
const char *c_path_str = c_node->getStringValue("strings");
if (!c_path_str) {
SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
return NULL;
}
c_path.append(c_path_str);
SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
<< c_path.str());
try {
readProperties(c_path.str(), strings);
} catch (const sg_exception &e) {
SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
return NULL;
}
}
return c_node;
}
// find basic airport location info from airport database // find basic airport location info from airport database
bool fgFindAirportID( const string& id, FGAirport *a ) { bool fgFindAirportID( const string& id, FGAirport *a ) {

View file

@ -57,6 +57,10 @@ string fgBasePackageVersion();
bool fgInitConfig ( int argc, char **argv ); bool fgInitConfig ( int argc, char **argv );
// Initialize the localization
SGPropertyNode *fgInitLocale(const char *language);
// General house keeping initializations // General house keeping initializations
bool fgInitGeneral ( void ); bool fgInitGeneral ( void );

View file

@ -1478,91 +1478,6 @@ int fgGlutInitEvents( void ) {
return 1; return 1;
} }
// Initialize the localization
SGPropertyNode *fgInitLocale(const char *language) {
SGPropertyNode *c_node = NULL, *d_node = NULL;
SGPropertyNode *intl = fgGetNode("/sim/intl");
SG_LOG(SG_GENERAL, SG_INFO, "Selected language: " << language );
// localization not defined
if (!intl)
return NULL;
//
// Select the proper language from the list
//
vector<SGPropertyNode_ptr> locale = intl->getChildren("locale");
for (unsigned int i = 0; i < locale.size(); i++) {
vector<SGPropertyNode_ptr> lang = locale[i]->getChildren("lang");
for (unsigned int j = 0; j < lang.size(); j++) {
if (!strcmp(lang[j]->getStringValue(), language)) {
c_node = locale[i];
break;
}
}
}
// No <locale> tags defined
if (!c_node)
return NULL;
//
// Load the default strings
//
d_node = intl->getChild("locale");
SGPath d_path( globals->get_fg_root() );
if (!c_node)
c_node = d_node;
const char *d_path_str = d_node->getStringValue("strings");
if (!d_path_str) {
SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
return NULL;
}
d_path.append(d_path_str);
SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
<< d_path.str());
SGPropertyNode *strings = c_node->getNode("strings");
try {
readProperties(d_path.str(), strings);
} catch (const sg_exception &e) {
SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
return NULL;
}
//
// Load the language specific strings
//
SGPath c_path( globals->get_fg_root() );
const char *c_path_str = c_node->getStringValue("strings");
if (!c_path_str) {
SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
return NULL;
}
c_path.append(c_path_str);
SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
<< c_path.str());
try {
readProperties(c_path.str(), strings);
} catch (const sg_exception &e) {
SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
return NULL;
}
return c_node;
}
// Main loop // Main loop
int mainLoop( int argc, char **argv ) { int mainLoop( int argc, char **argv ) {

View file

@ -60,8 +60,6 @@
#include "options.hxx" #include "options.hxx"
#include "viewmgr.hxx" #include "viewmgr.hxx"
// Hack: from main.cxx
extern SGPropertyNode *fgInitLocale(const char *);
SG_USING_STD(string); SG_USING_STD(string);
SG_USING_NAMESPACE(std); SG_USING_NAMESPACE(std);