]> git.mxchange.org Git - flightgear.git/commitdiff
Add Windows-specific implementation to determine locale settings.
authorThorstenB <brehmt@gmail.com>
Sun, 6 May 2012 21:15:27 +0000 (23:15 +0200)
committerThorstenB <brehmt@gmail.com>
Sun, 6 May 2012 21:15:27 +0000 (23:15 +0200)
src/Main/locale.cxx
src/Main/locale.hxx

index 27aff0c8d546bdad44d111e5d979211539658350..f3c8e9ba3cf7887f1ff11061084da8a396f8788a 100644 (file)
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
 
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
+
 #include <simgear/props/props_io.hxx>
 #include <simgear/structure/exception.hxx>
 
@@ -37,6 +41,48 @@ FGLocale::~FGLocale()
 {
 }
 
+#ifdef HAVE_WINDOWS_H
+/**
+ * Determine locale/language settings on Windows.
+ *
+ * Copyright (C) 1997, 2002, 2003 Martin von Loewis
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies.
+ *
+ * This software comes with no warranty. Use at your own risk.
+ */
+const char*
+FGLocale::getUserLanguage()
+{
+    static char locale[100] = {0};
+
+    if (GetLocaleInfo(LOCALE_USER_DEFAULT,
+                      LOCALE_SISO639LANGNAME,
+                      locale, sizeof(locale)))
+    {
+        size_t i = strlen(locale);
+        locale[i++] = '_';
+        if (GetLocaleInfo(LOCALE_USER_DEFAULT,
+                          LOCALE_SISO3166CTRYNAME,
+                          locale+i, (int)(sizeof(locale)-i)))
+            return locale;
+    }
+
+    return NULL;
+}
+#else
+/**
+ * Determine locale/language settings on Linux (and Mac?).
+ */
+const char*
+FGLocale::getUserLanguage()
+{
+    return ::getenv("LANG");
+}
+#endif
+
 // Search property tree for matching locale description
 SGPropertyNode*
 FGLocale::findLocaleNode(const string& language)
@@ -85,12 +131,12 @@ FGLocale::findLocaleNode(const string& language)
 bool
 FGLocale::selectLanguage(const char *language)
 {
-    // Use environment setting when no language is given.
+    // Use system setting when no language is given.
     if ((language == NULL)||(language[0]==0))
-        language = ::getenv("LANG");
+        language = getUserLanguage();
 
     // Use plain C locale if nothing is available.
-    if (language == NULL)
+    if ((language == NULL)||(language[0]==0))
     {
         SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" );
         language = "C";
@@ -120,7 +166,7 @@ FGLocale::loadResource(SGPropertyNode* localeNode, const char* resource)
     const char *path_str = stringNode->getStringValue(resource, NULL);
     if (!path_str)
     {
-        SG_LOG(SG_GENERAL, SG_ALERT, "No path in " << stringNode->getPath() << "/" << resource << ".");
+        SG_LOG(SG_GENERAL, SG_WARN, "No path in " << stringNode->getPath() << "/" << resource << ".");
         return NULL;
     }
 
index e9d2a5ae0c9a02e40846caa98077a7b73921cc07..8ccd2d218fd40aefea9accb4d96473b01bca5667 100644 (file)
@@ -72,6 +72,11 @@ public:
      */
     static void utf8toLatin1        (std::string& s);
 
+    /**
+     * Obtain user's default language setting.
+     */
+    const char* getUserLanguage();
+
 protected:
     /**
      * Find property node matching given language.