From: curt Date: Thu, 3 Oct 2002 14:39:37 +0000 (+0000) Subject: Better internationalization infrastructure. We now supports the "LANG" X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=44fcbbd0aff8566e2e792de071c8ee2e35f52bf1;p=flightgear.git Better internationalization infrastructure. We now supports the "LANG" environment variable. --- diff --git a/src/GUI/gui.cxx b/src/GUI/gui.cxx index f826a2da4..29638b8fb 100644 --- a/src/GUI/gui.cxx +++ b/src/GUI/gui.cxx @@ -94,6 +94,7 @@ void initMenu() mainMenuBar = new puMenuBar (); SGPropertyNode *menu = main.getChild("menu"); + SGPropertyNode *locale = globals->get_locale(); vectorsubmenu = menu->getChildren("submenu"); @@ -120,8 +121,8 @@ void initMenu() if (sep) { Menu[h].submenu[pos] = strdup("----------"); } else if (call && strcmp(call->getStringValue(), "")) { - string text = fgGetString( name->getStringValue(), - "/strings/null" ); + string text = locale->getStringValue( name->getStringValue(), + "strings/null" ); Menu[h].submenu[pos] = strdup(text.c_str()); } else { @@ -139,8 +140,8 @@ void initMenu() } SGPropertyNode *name = submenu[h]->getNode("name"); - string text = fgGetString( name->getStringValue(), - "/strings/null" ); + string text = locale->getStringValue( name->getStringValue(), + "strings/null" ); Menu[h].name = strdup(text.c_str()); mainMenuBar->add_submenu(Menu[h].name, Menu[h].submenu, Menu[h].cb); diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 4346f6e6a..674718f7a 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -165,6 +165,9 @@ private: SGPropertyNode *props; SGPropertyNode *initial_state; + // localization + SGPropertyNode *locale; + SGCommandMgr *commands; FGModelLoader * model_loader; @@ -275,6 +278,9 @@ public: inline SGPropertyNode *get_props () { return props; } inline void set_props( SGPropertyNode *n ) { props = n; } + inline SGPropertyNode *get_locale () { return locale; } + inline void set_locale( SGPropertyNode *n ) { locale = n; } + inline SGCommandMgr *get_commands () { return commands; } inline FGModelLoader * get_model_loader () { return model_loader; } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 01e079764..0f885fba3 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -1456,6 +1456,91 @@ int fgGlutInitEvents( void ) { return 1; } +// Initialize the localization +SGPropertyNode *fgInitLocale() { + SGPropertyNode *c_node = NULL, *d_node = NULL; + + // + // Detect the current language + // + char *language = getenv("LANG"); + if (language == NULL) { + SG_LOG(SG_GENERAL, SG_ALERT, "Unable to detect the current language" ); + language = "C"; + } + + SGPropertyNode *intl = fgGetNode("/sim/intl", ""); + + if (!intl) + return NULL; + + 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; + } + } + } + + + // + // 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 ) { @@ -1530,6 +1615,14 @@ int mainLoop( int argc, char **argv ) { exit(-1); } + // Initialize the localization routines + SGPropertyNode *locale = fgInitLocale(); + if (!locale) + return false; + + globals->set_locale( locale ); + + // Initialize the Window/Graphics environment. if( !fgGlutInit(&argc, argv) ) { SG_LOG( SG_GENERAL, SG_ALERT, "GLUT initialization failed ..." );