| 1 | #ifdef HAVE_CONFIG_H |
| 2 | # include <config.h> |
| 3 | #endif |
| 4 | |
| 5 | |
| 6 | #include "menubar.hxx" |
| 7 | #include <Main/locale.hxx> |
| 8 | #include <Main/globals.hxx> |
| 9 | |
| 10 | FGMenuBar::FGMenuBar() |
| 11 | { |
| 12 | // load locale's menu resources (default and current language) |
| 13 | globals->get_locale()->loadResource("menu"); |
| 14 | } |
| 15 | |
| 16 | FGMenuBar::~FGMenuBar () |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | std::string |
| 21 | FGMenuBar::getLocalizedLabel(SGPropertyNode* node) |
| 22 | { |
| 23 | if (!node) |
| 24 | return {}; |
| 25 | |
| 26 | std::string name = node->getStringValue("name", ""); |
| 27 | if (!name.empty()) { |
| 28 | const auto translated = globals->get_locale()->getLocalizedString(name, "menu"); |
| 29 | if (!translated.empty()) |
| 30 | return translated; |
| 31 | } |
| 32 | |
| 33 | // return default with fallback to name |
| 34 | std::string label = node->getStringValue("label", name.c_str()); |
| 35 | |
| 36 | // this can occur if the menu item is missing a <name> |
| 37 | if (label.empty()) { |
| 38 | SG_LOG(SG_GUI, SG_ALERT, "FGMenuBar::getLocalizedLabel: No <name> defined for:" << node->getPath()); |
| 39 | return std::string{"<unnamed>"}; |
| 40 | } |
| 41 | |
| 42 | return label; |
| 43 | } |
| 44 | |
| 45 | // end of menubar.cxx |