diff --git a/src/GUI/gui.cxx b/src/GUI/gui.cxx index 29638b8fb..582215022 100644 --- a/src/GUI/gui.cxx +++ b/src/GUI/gui.cxx @@ -195,7 +195,8 @@ void guiInit() } // 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 -> load ( (char *)fntpath.c_str() ) ; puFont GuiFont ( guiFntHandle, 15 ) ; diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 5bc4c4921..029356efd 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -302,6 +302,96 @@ bool fgInitConfig ( int argc, char **argv ) { 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 locale = intl->getChildren("locale"); + for (unsigned int i = 0; i < locale.size(); i++) { + + vector 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 bool fgFindAirportID( const string& id, FGAirport *a ) { diff --git a/src/Main/fg_init.hxx b/src/Main/fg_init.hxx index caba67dc5..58beebdf8 100644 --- a/src/Main/fg_init.hxx +++ b/src/Main/fg_init.hxx @@ -57,6 +57,10 @@ string fgBasePackageVersion(); bool fgInitConfig ( int argc, char **argv ); +// Initialize the localization +SGPropertyNode *fgInitLocale(const char *language); + + // General house keeping initializations bool fgInitGeneral ( void ); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 6b461876c..b535b03dd 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -1478,91 +1478,6 @@ int fgGlutInitEvents( void ) { 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 locale = intl->getChildren("locale"); - for (unsigned int i = 0; i < locale.size(); i++) { - - vector 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 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 int mainLoop( int argc, char **argv ) { diff --git a/src/Main/options.cxx b/src/Main/options.cxx index f414b91ed..5d40f0b80 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -60,8 +60,6 @@ #include "options.hxx" #include "viewmgr.hxx" -// Hack: from main.cxx -extern SGPropertyNode *fgInitLocale(const char *); SG_USING_STD(string); SG_USING_NAMESPACE(std);