From 470d233f0d603b7db2b4ce243342db3a0de1a207 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 10 Oct 2002 15:02:50 +0000 Subject: [PATCH] Eric Hofman: Now the options can be localized as well. This adds a slight problem for the --language options, but not that much (worst case, the strings are loaded twice consuming some more memory). I tried to be as accurate as posiible when copying the options texts, but there might be some mostakes left. --- Thanks | 9 +++ src/Main/fg_init.cxx | 180 ++++++++++++++++++++++++----------------- src/Main/main.cxx | 27 +------ src/Main/options.cxx | 63 +++++++++++---- src/Objects/matlib.cxx | 8 +- 5 files changed, 170 insertions(+), 117 deletions(-) diff --git a/Thanks b/Thanks index 7c3c76db1..7185ba3f2 100644 --- a/Thanks +++ b/Thanks @@ -172,6 +172,7 @@ Erik Hofman Major overhaul and parameterization of the sound module, to allow aircraft-specific sound configuration at runtime. Irix port. + Localization support. Charlie Hotchkiss @@ -233,6 +234,7 @@ David Megginson 3D model animation module initial take of sound-effects module Random ground cover objects + Vacuum and pitot systems. Eric Mitchell @@ -278,6 +280,8 @@ Curt Olson He has his hands in many of the areas, but is primarily responsible for the scenery subsystem, as well as much of the infrastructure in the sim. + Electrical system. + Runway lighting. Brian Paul @@ -466,6 +470,11 @@ Jean-Claude Wippler http://www.equi4.com/metakit +John Wojnaroski + Open Glass Cockpit project + 3d clouds + + WoodSoup Project http://www.woodsoup.org [ FlightGear no longer uses woodsoup services, but we appreciate the support provided to our project during the time they hosted us. ] diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 029356efd..8314d7bbd 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -228,80 +228,6 @@ string fgBasePackageVersion() { } -// Read in configuration (file and command line) -bool fgInitConfig ( int argc, char **argv ) { - - // First, set some sane default values - fgSetDefaults(); - - // Read global preferences from $FG_ROOT/preferences.xml - SGPath props_path(globals->get_fg_root()); - props_path.append("preferences.xml"); - SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences"); - readProperties(props_path.str(), globals->get_props()); - SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences"); - - // Read the default aircraft config file. - string aircraft = fgGetString("/sim/aircraft", ""); - if (aircraft.size() > 0) { - SGPath aircraft_path(globals->get_fg_root()); - aircraft_path.append("Aircraft"); - aircraft_path.append(aircraft); - aircraft_path.concat("-set.xml"); - SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft - << " from " << aircraft_path.str()); - try { - readProperties(aircraft_path.str(), globals->get_props()); - } catch (const sg_exception &e) { - string message = "Error reading default aircraft: "; - message += e.getFormattedMessage(); - SG_LOG(SG_INPUT, SG_ALERT, message); - exit(2); - } - } else { - SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified"); - } - - // Attempt to locate and parse the various config files in order - // from least precidence to greatest precidence - - // Check for $fg_root/system.fgfsrc - SGPath config( globals->get_fg_root() ); - config.append( "system.fgfsrc" ); - fgParseOptions(config.str()); - -#if defined( unix ) || defined( __CYGWIN__ ) - char name[256]; - // Check for $fg_root/system.fgfsrc.hostname - gethostname( name, 256 ); - config.concat( "." ); - config.concat( name ); - fgParseOptions(config.str()); -#endif - - // Check for ~/.fgfsrc - char* envp = ::getenv( "HOME" ); - if ( envp != NULL ) { - config.set( envp ); - config.append( ".fgfsrc" ); - fgParseOptions(config.str()); - } - -#if defined( unix ) || defined( __CYGWIN__ ) - // Check for ~/.fgfsrc.hostname - gethostname( name, 256 ); - config.concat( "." ); - config.concat( name ); - fgParseOptions(config.str()); -#endif - - // Parse remaining command line options - // These will override anything specified in a config file - fgParseArgs(argc, argv); - - return true; -} - // Initialize the localization SGPropertyNode *fgInitLocale(const char *language) { SGPropertyNode *c_node = NULL, *d_node = NULL; @@ -312,7 +238,7 @@ SGPropertyNode *fgInitLocale(const char *language) { // localization not defined if (!intl) return NULL; - + // // Select the proper language from the list // @@ -364,7 +290,6 @@ SGPropertyNode *fgInitLocale(const char *language) { return NULL; } - // // Load the language specific strings // @@ -393,6 +318,109 @@ SGPropertyNode *fgInitLocale(const char *language) { } + +// Initialize the localization routines +bool fgDetectLanguage() { + char *language = ::getenv("LANG"); + + if (language == NULL) { + SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" ); + language = "C"; + } + + SGPropertyNode *locale = fgInitLocale(language); + if (!locale) { + cerr << "No internationalization settings specified in preferences.xml" + << endl; + + return false; + } + + globals->set_locale( locale ); + + return true; +} + + +// Read in configuration (file and command line) +bool fgInitConfig ( int argc, char **argv ) { + + // First, set some sane default values + fgSetDefaults(); + + // Read global preferences from $FG_ROOT/preferences.xml + SGPath props_path(globals->get_fg_root()); + props_path.append("preferences.xml"); + SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences"); + readProperties(props_path.str(), globals->get_props()); + SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences"); + + // Detect the required language as early as possible + if (fgDetectLanguage() != true) + return false; + + // Read the default aircraft config file. + string aircraft = fgGetString("/sim/aircraft", ""); + if (aircraft.size() > 0) { + SGPath aircraft_path(globals->get_fg_root()); + aircraft_path.append("Aircraft"); + aircraft_path.append(aircraft); + aircraft_path.concat("-set.xml"); + SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft + << " from " << aircraft_path.str()); + try { + readProperties(aircraft_path.str(), globals->get_props()); + } catch (const sg_exception &e) { + string message = "Error reading default aircraft: "; + message += e.getFormattedMessage(); + SG_LOG(SG_INPUT, SG_ALERT, message); + exit(2); + } + } else { + SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified"); + } + + // Attempt to locate and parse the various config files in order + // from least precidence to greatest precidence + + // Check for $fg_root/system.fgfsrc + SGPath config( globals->get_fg_root() ); + config.append( "system.fgfsrc" ); + fgParseOptions(config.str()); + +#if defined( unix ) || defined( __CYGWIN__ ) + char name[256]; + // Check for $fg_root/system.fgfsrc.hostname + gethostname( name, 256 ); + config.concat( "." ); + config.concat( name ); + fgParseOptions(config.str()); +#endif + + // Check for ~/.fgfsrc + char* envp = ::getenv( "HOME" ); + if ( envp != NULL ) { + config.set( envp ); + config.append( ".fgfsrc" ); + fgParseOptions(config.str()); + } + +#if defined( unix ) || defined( __CYGWIN__ ) + // Check for ~/.fgfsrc.hostname + gethostname( name, 256 ); + config.concat( "." ); + config.concat( name ); + fgParseOptions(config.str()); +#endif + + // Parse remaining command line options + // These will override anything specified in a config file + fgParseArgs(argc, argv); + + return true; +} + + // find basic airport location info from airport database bool fgFindAirportID( const string& id, FGAirport *a ) { if ( id.length() ) { diff --git a/src/Main/main.cxx b/src/Main/main.cxx index b535b03dd..dbc0cfd54 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -1323,7 +1323,7 @@ static void fgIdleFunction ( void ) { // sleep(1); idle_state = 1000; - cout << "Panel visible = " << fgPanelVisible() << endl; + SG_LOG( SG_GENERAL, SG_INFO, "Panel visible = " << fgPanelVisible() ); fgReshape( fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize") ); } @@ -1533,12 +1533,11 @@ int mainLoop( int argc, char **argv ) { string base_version = fgBasePackageVersion(); if ( !(base_version == required_version) ) { // tell the operator how to use this application - fgUsage(); - cout << endl << "Base package check failed ... " \ + cerr << endl << "Base package check failed ... " \ << "Found version " << base_version << " at: " \ << globals->get_fg_root() << endl; - cout << "Please upgrade to version" << required_version << endl; + cerr << "Please upgrade to version" << required_version << endl; exit(-1); } @@ -1551,26 +1550,6 @@ int mainLoop( int argc, char **argv ) { exit(-1); } - // Initialize the localization routines - if (globals->get_locale() == NULL) { - char *language = getenv("LANG"); - if (language == NULL) { - SG_LOG(SG_GENERAL, SG_ALERT, "Unable to detect the language" ); - language = "C"; - } - - SGPropertyNode *locale = fgInitLocale(language); - if (!locale) { - cerr - << "Not internationalization settings specified in preferences.xml" - << endl; - - return false; - } - - globals->set_locale( locale ); - } - // Initialize the Window/Graphics environment. if( !fgGlutInit(&argc, argv) ) { SG_LOG( SG_GENERAL, SG_ALERT, "GLUT initialization failed ..." ); diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 5d40f0b80..9dd26a912 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -1164,6 +1164,8 @@ fgParseOptions (const string& path) { void fgUsage (bool verbose) { + SGPropertyNode *locale = globals->get_locale(); + SGPropertyNode options_root; SGPath opath( globals->get_fg_root() ); opath.append( "options.xml" ); @@ -1188,7 +1190,7 @@ fgUsage (bool verbose) exit(-1); } - SGPropertyNode *usage = options->getNode("usage"); + SGPropertyNode *usage = locale->getNode(options->getStringValue("usage")); if (usage) { cout << "Usage: " << usage->getStringValue() << endl; } @@ -1229,25 +1231,54 @@ fgUsage (bool verbose) snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' '); } + // There may be more than one tag assosiated + // with one option + msg += cstr; - SGPropertyNode *desc = option[k]->getNode("description"); - if (desc) { - msg += desc->getStringValue(); - - for ( unsigned int l = 1; - (desc = option[k]->getNode("description", l, false)); - l++ ) - { - snprintf(cstr, 96, "\n%32c%s", ' ', - desc->getStringValue()); - msg += cstr; - } - msg += '\n'; - } + vectordesc = + option[k]->getChildren("description"); + + if (desc.size() > 0) { + for ( unsigned int l = 0; l < desc.size(); l++) { + + // There may be more than one translation line. + + string t = desc[l]->getStringValue(); + SGPropertyNode *n = locale->getNode("strings"); + vectortrans_desc = + n->getChildren(t.substr(8).c_str()); + + for ( unsigned int m = 0; m < trans_desc.size(); m++ ) { + string t_str = trans_desc[m]->getStringValue(); + + if ((m > 0) || ((l > 0) && m == 0)) { + snprintf(cstr, 96, "%32c", ' '); + msg += cstr; + + } + + // If the string is too large to fit on the screen, + // then split it up in several pieces. + + while ( t_str.size() > 47 ) { + + unsigned int m = t_str.rfind(' ', 47); + msg += t_str.substr(0, m); + snprintf(cstr, 96, "\n%32c", ' '); + msg += cstr; + + t_str.erase(t_str.begin(), t_str.begin() + m + 1); + } + msg += t_str + '\n'; + } + } + } } } - SGPropertyNode *name = section[j]->getNode("name"); + SGPropertyNode *name = + locale->getNode(section[j]->getStringValue("name")); + if (!msg.empty() && name) { cout << endl << name->getStringValue() << ":" << endl; cout << msg; diff --git a/src/Objects/matlib.cxx b/src/Objects/matlib.cxx index 342918bd4..73103bd08 100644 --- a/src/Objects/matlib.cxx +++ b/src/Objects/matlib.cxx @@ -160,10 +160,16 @@ static int gen_vasi_light_map() { // top half white, bottom half red env_map[i][j][0] = 255; - if ( i >= half_res ) { + if ( i > half_res ) { + // white env_map[i][j][1] = 255; env_map[i][j][2] = 255; + } else if ( i == half_res - 1 || i == half_res ) { + // pink + env_map[i][j][1] = 127; + env_map[i][j][2] = 127; } else { + // red env_map[i][j][1] = 0; env_map[i][j][2] = 0; } -- 2.39.5