]> git.mxchange.org Git - flightgear.git/commitdiff
#263: (Re-)introduce language option for menu
authorThorstenB <brehmt@gmail.com>
Sat, 21 Apr 2012 18:18:01 +0000 (20:18 +0200)
committerThorstenB <brehmt@gmail.com>
Sat, 21 Apr 2012 18:18:01 +0000 (20:18 +0200)
Adapt FGPUIMenuBar to use new Locale module.
Adds support for separate "key" property for menu items, so keyboard hints
are no longer part of the item's label (and do not need to be part of the
translated text resources).

src/GUI/FGPUIMenuBar.cxx

index 57336d284ad42cb6ea9d14f7292b38ded2182892..98884b7d36d7fa8259d8b4a4b570f488ce0ba79a 100644 (file)
@@ -10,6 +10,7 @@
 #include <simgear/props/props_io.hxx>
 
 #include <Main/globals.hxx>
+#include <Main/locale.hxx>
 #include <Main/fg_props.hxx>
 
 #include "new_gui.hxx"
@@ -139,7 +140,15 @@ FGPUIMenuBar::fireItem (puObject * item)
 void
 FGPUIMenuBar::make_menu (SGPropertyNode * node)
 {
-    const char * name = strdup(node->getStringValue("label"));
+    string s = getLocalizedLabel(node);
+
+    // hack: map at least some UTF-8 characters to Latin1, since FG fonts are
+    // Latin1 (or plain ASCII, which is a subset). This hack can be removed once
+    // the PLIB/OSG port is complete (OSG has full UTF-8 support! :) ).
+    FGLocale::utf8toLatin1(s);
+
+    const char* name = strdup(s.c_str());
+
     vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
 
     int array_size = item_nodes.size();
@@ -152,7 +161,18 @@ FGPUIMenuBar::make_menu (SGPropertyNode * node)
          i++, j--) {
 
                                 // Set up the PUI entries for this item
-        items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
+        string label = getLocalizedLabel(item_nodes[i]);
+        FGLocale::utf8toLatin1(label);
+
+        // append the keyboard hint to the menu entry
+        const char* key = item_nodes[i]->getStringValue("key", 0);
+        if (key)
+        {
+            label.append("           <");
+            label.append(key);
+            label.append(">");
+        }
+        items[j] = strdup(label.c_str());
         callbacks[j] = menu_callback;
 
                                 // Load all the bindings for this item