]> git.mxchange.org Git - flightgear.git/commitdiff
Better internationalization infrastructure. We now supports the "LANG"
authorcurt <curt>
Thu, 3 Oct 2002 14:39:37 +0000 (14:39 +0000)
committercurt <curt>
Thu, 3 Oct 2002 14:39:37 +0000 (14:39 +0000)
environment variable.

src/GUI/gui.cxx
src/Main/globals.hxx
src/Main/main.cxx

index f826a2da40b421922026927dde44f850b961265b..29638b8fb8d42cdc0f55186e0c38269166c8b3d3 100644 (file)
@@ -94,6 +94,7 @@ void initMenu()
      mainMenuBar = new puMenuBar ();
 
      SGPropertyNode *menu = main.getChild("menu");
+     SGPropertyNode *locale = globals->get_locale();
 
      vector<SGPropertyNode_ptr>submenu = 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);
index 4346f6e6a88c672ccd7b7a55879ca74fcb39f6a1..674718f7a6fe3dd0d31e83c850d436f79b7da04c 100644 (file)
@@ -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; }
index 01e07976439198ae915fb83e670aee8034a91e7a..0f885fba3419316df3d5954cf3fca0ba92528414 100644 (file)
@@ -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<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;
+         }
+      }
+   }
+
+
+   //
+   // 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 ..." );