]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/locale.cxx
Update for changed SGPath::realpath signature
[flightgear.git] / src / Main / locale.cxx
index 41fafe995f6c2b92ecfeb98264706f3bf78da202..fd7a5f2b5137aeb8a1f290a69db414f23bde2fb4 100644 (file)
@@ -26,6 +26,7 @@
 #include <windows.h>
 #endif
 
+#include <cstdio>
 #include <boost/foreach.hpp>
 
 #include <simgear/props/props_io.hxx>
@@ -89,27 +90,7 @@ FGLocale::getUserLanguage()
     return result;
 }
 #elif __APPLE__
-
-// determine locale / langauge on Mac
-#include <CoreFoundation/CoreFoundation.h>
-
-string_list
-FGLocale::getUserLanguage()
-{
-    string_list result;
-    CFArrayRef langs = CFLocaleCopyPreferredLanguages();
-    
-    char buffer[64];
-    for (int i=0; i<CFArrayGetCount(langs); ++i) {
-        CFStringRef s = (CFStringRef) CFArrayGetValueAtIndex(langs, i);
-        CFStringGetCString(s, buffer, 64, kCFStringEncodingASCII);
-        result.push_back(buffer);
-    }
-    
-    CFRelease(langs);
-    return result;
-}
-
+//  implemented in CocoaHelpers.mm
 #else
 /**
  * Determine locale/language settings on Linux/Unix.
@@ -190,26 +171,29 @@ FGLocale::selectLanguage(const char *language)
     }
 
     
-    SGPropertyNode *locale = NULL;
+    _currentLocale = NULL;
     BOOST_FOREACH(string lang, languages) {
-        locale = findLocaleNode(lang);
-        if (locale) {
+        SG_LOG(SG_GENERAL, SG_DEBUG, "trying to find locale for " << lang );
+        _currentLocale = findLocaleNode(lang);
+        if (_currentLocale) {
+            SG_LOG(SG_GENERAL, SG_DEBUG, "found locale for " << lang << " at " << _currentLocale->getPath() );
             break;
         }
     }
     
-    if (!locale)
+    // load resource for system messages (translations for fgfs internal messages)
+    loadResource("sys");
+
+    // load resource for atc messages
+    loadResource("atc");
+
+    if (!_currentLocale)
     {
        SG_LOG(SG_GENERAL, SG_ALERT,
-              "No internationalization settings specified in preferences.xml" );
+              "System locale not found or no internationalization settings specified in preferences.xml. Using default (en)." );
        return false;
     }
 
-    _currentLocale = locale;
-
-    // load resource for system messages (translations for fgfs internal messages)
-    loadResource("sys");
-
     return true;
 }
 
@@ -226,21 +210,21 @@ FGLocale::loadResource(SGPropertyNode* localeNode, const char* resource)
     if (!path_str)
     {
         SG_LOG(SG_GENERAL, SG_WARN, "No path in " << stringNode->getPath() << "/" << resource << ".");
-        return NULL;
+        return false;
     }
 
     path.append(path_str);
     SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings for '" <<
            localeNode->getStringValue("lang", "<none>")
-           <<"' from " << path.str());
+           <<"' from " << path);
 
     // load the actual file
     try
     {
-        readProperties(path.str(), stringNode->getNode(resource, 0, true));
+        readProperties(path, stringNode->getNode(resource, 0, true));
     } catch (const sg_exception &e)
     {
-        SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings from " << path.str() <<
+        SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings from " << path <<
                ". Error: " << e.getFormattedMessage());
         return false;
     }