Index: /trunk/include/iprt/locale.h
===================================================================
--- /trunk/include/iprt/locale.h	(revision 68120)
+++ /trunk/include/iprt/locale.h	(revision 68121)
@@ -32,5 +32,5 @@
 RT_C_DECLS_BEGIN
 
-/** @defgroup grp_rt_time   RTLocale - Locale and Related Info
+/** @defgroup grp_rt_locale RTLocale - Locale and Related Info
  * @ingroup grp_rt
  * @{
@@ -47,4 +47,15 @@
 RTDECL(int) RTLocaleQueryLocaleName(char *pszName, size_t cbName);
 
+/**
+ * Returns a normalized base locale name ('{ll}_{CC}' or 'C').
+ *
+ * @returns IPRT status code.
+ * @retval  VERR_NOT_SUPPORTED if not supported.
+ * @param   pszName         Where to return the name.
+ * @param   cbName          The size of the name buffer.
+ *
+ * @sa      RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2
+ */
+RTDECL(int) RTLocaleQueryNormalizedBaseLocaleName(char *pszName, size_t cbName);
 
 /**
@@ -61,4 +72,25 @@
 RTDECL(int) RTLocaleQueryUserCountryCode(char pszCountryCode[3]);
 
+
+/**
+ * Checks whether @a a_psz seems to start with a
+ * language-code-underscore-country-code sequence.
+ *
+ * We perform a check for a likely ISO 639-1 language code, followed by an
+ * underscore, followed by a likely ISO 3166-1 alpha-2 country code.
+ *
+ * @return true if probable '{ll}_{CC}' sequence, false if surely not.
+ * @param  a_psz        The string to test the start of.
+ *
+ * @note User must include iprt/ctype.h separately.
+ */
+#define RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(a_psz) \
+    (   RT_C_IS_LOWER((a_psz)[0]) \
+     && RT_C_IS_LOWER((a_psz)[1]) \
+     && (a_psz)[2] == '_' \
+     && RT_C_IS_UPPER((a_psz)[3]) \
+     && RT_C_IS_UPPER((a_psz)[4]) )
+
+
 /** @} */
 
Index: /trunk/include/iprt/mangling.h
===================================================================
--- /trunk/include/iprt/mangling.h	(revision 68120)
+++ /trunk/include/iprt/mangling.h	(revision 68121)
@@ -1124,4 +1124,5 @@
 # define RTLocalIpcSessionQueryGroupId                  RT_MANGLER(RTLocalIpcSessionQueryGroupId)
 # define RTLocaleQueryLocaleName                        RT_MANGLER(RTLocaleQueryLocaleName)
+# define RTLocaleQueryNormalizedBaseLocaleName          RT_MANGLER(RTLocaleQueryNormalizedBaseLocaleName)
 # define RTLocaleQueryUserCountryCode                   RT_MANGLER(RTLocaleQueryUserCountryCode)
 # define RTLockValidatorClassAddPriorClass              RT_MANGLER(RTLockValidatorClassAddPriorClass)
Index: /trunk/src/VBox/Runtime/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Runtime/Makefile.kmk	(revision 68120)
+++ /trunk/src/VBox/Runtime/Makefile.kmk	(revision 68121)
@@ -820,4 +820,5 @@
 	r3/win/RTCrStoreCreateSnapshotById-win.cpp \
 	r3/win/RTHandleGetStandard-win.cpp \
+ 	r3/win/RTLocaleQueryNormalizedBaseLocaleName-win.cpp \
 	r3/win/RTLocaleQueryUserCountryCode-win.cpp \
 	r3/win/RTSystemQueryOSInfo-win.cpp \
@@ -888,4 +889,5 @@
 	generic/uuid-generic.cpp \
  	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+ 	r3/generic/RTLocaleQueryNormalizedBaseLocaleName-r3-generic.cpp \
 	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
@@ -999,4 +1001,5 @@
 	r3/generic/allocex-r3-generic.cpp \
  	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+ 	r3/generic/RTLocaleQueryNormalizedBaseLocaleName-r3-generic.cpp \
 	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
@@ -1081,4 +1084,5 @@
 	r3/generic/allocex-r3-generic.cpp \
  	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+ 	r3/generic/RTLocaleQueryNormalizedBaseLocaleName-r3-generic.cpp \
 	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
@@ -1154,4 +1158,5 @@
 	r3/generic/allocex-r3-generic.cpp \
  	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+ 	r3/generic/RTLocaleQueryNormalizedBaseLocaleName-r3-generic.cpp \
 	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
@@ -1226,4 +1231,5 @@
 	r3/generic/allocex-r3-generic.cpp \
  	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+ 	r3/generic/RTLocaleQueryNormalizedBaseLocaleName-r3-generic.cpp \
 	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
@@ -1291,4 +1297,5 @@
 	r3/generic/allocex-r3-generic.cpp \
  	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+ 	r3/generic/RTLocaleQueryNormalizedBaseLocaleName-r3-generic.cpp \
 	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
@@ -1381,4 +1388,5 @@
 	r3/generic/allocex-r3-generic.cpp \
  	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+ 	r3/generic/RTLocaleQueryNormalizedBaseLocaleName-r3-generic.cpp \
 	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
Index: /trunk/src/VBox/Runtime/r3/generic/RTLocaleQueryNormalizedBaseLocaleName-r3-generic.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/generic/RTLocaleQueryNormalizedBaseLocaleName-r3-generic.cpp	(revision 68121)
+++ /trunk/src/VBox/Runtime/r3/generic/RTLocaleQueryNormalizedBaseLocaleName-r3-generic.cpp	(revision 68121)
@@ -0,0 +1,93 @@
+/* $Id$ */
+/** @file
+ * IPRT - RTLocaleQueryNormalizedBaseLocaleName, ring-3 generic.
+ */
+
+/*
+ * Copyright (C) 2017 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include <iprt/locale.h>
+#include "internal/iprt.h"
+
+#include <iprt/ctype.h>
+#include <iprt/err.h>
+#include <iprt/string.h>
+
+
+/*
+ * Note! Code duplicated in r3/win/RTLocaleQueryNormalizedBaseLocaleName-win.cpp (adds fallback).
+ */
+RTDECL(int) RTLocaleQueryNormalizedBaseLocaleName(char *pszName, size_t cbName)
+{
+    char szLocale[_1K];
+    int rc = RTLocaleQueryLocaleName(szLocale, sizeof(szLocale));
+    if (RT_SUCCESS(rc))
+    {
+        /*
+         * May return some complicated "LC_XXX=yyy;LC.." sequence if
+         * partially set (like IPRT does).  Try get xx_YY sequence first
+         * because 'C' or 'POSIX' may be LC_xxx variants that haven't been
+         * set yet.
+         *
+         * ASSUMES complicated locale mangling is done in a certain way...
+         */
+        const char *pszLocale = strchr(szLocale, '=');
+        if (!pszLocale)
+            pszLocale = szLocale;
+        else
+            pszLocale++;
+        bool fSeenC = false;
+        bool fSeenPOSIX = false;
+        do
+        {
+            const char *pszEnd = strchr(pszLocale, ';');
+
+            if (   RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(pszLocale)
+                && (   pszLocale[5] == '\0'
+                    || RT_C_IS_PUNCT(pszLocale[5])) )
+                return RTStrCopyEx(pszName, cbName, pszLocale, 5);
+
+            if (   pszLocale[0] == 'C'
+                && (   pszLocale[1] == '\0'
+                    || RT_C_IS_PUNCT(pszLocale[1])) )
+                fSeenC = true;
+            else if (   strncmp(pszLocale, "POSIX", 5) == 0
+                     && (   pszLocale[5] == '\0'
+                        || RT_C_IS_PUNCT(pszLocale[5])) )
+                fSeenPOSIX = true;
+
+            /* advance */
+            pszLocale = pszEnd ? strchr(pszEnd + 1, '=') : NULL;
+        } while (pszLocale++);
+
+        if (fSeenC || fSeenPOSIX)
+            return RTStrCopy(pszName, cbName, "C"); /* C and POSIX should be identical IIRC, so keep it simple. */
+
+        rc = VERR_NOT_AVAILABLE;
+    }
+    return rc;
+}
+
+
Index: /trunk/src/VBox/Runtime/r3/win/RTLocaleQueryNormalizedBaseLocaleName-win.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/win/RTLocaleQueryNormalizedBaseLocaleName-win.cpp	(revision 68121)
+++ /trunk/src/VBox/Runtime/r3/win/RTLocaleQueryNormalizedBaseLocaleName-win.cpp	(revision 68121)
@@ -0,0 +1,107 @@
+/* $Id$ */
+/** @file
+ * IPRT - RTLocaleQueryNormalizedBaseLocaleName, ring-3, Windows.
+ */
+
+/*
+ * Copyright (C) 2017 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include <iprt/win/windows.h>
+
+#include <iprt/locale.h>
+#include "internal/iprt.h"
+
+#include <iprt/ctype.h>
+#include <iprt/err.h>
+#include <iprt/string.h>
+
+
+RTDECL(int) RTLocaleQueryNormalizedBaseLocaleName(char *pszName, size_t cbName)
+{
+    /*
+     * Note! This part is duplicate of r3/generic/RTLocaleQueryNormalizedBaseLocaleName-r3-generic.cpp!
+     */
+    char szLocale[_1K];
+    int rc = RTLocaleQueryLocaleName(szLocale, sizeof(szLocale));
+    if (RT_SUCCESS(rc))
+    {
+        /*
+         * May return some complicated "LC_XXX=yyy;LC.." sequence if
+         * partially set (like IPRT does).  Try get xx_YY sequence first
+         * because 'C' or 'POSIX' may be LC_xxx variants that haven't been
+         * set yet.
+         *
+         * ASSUMES complicated locale mangling is done in a certain way...
+         */
+        const char *pszLocale = strchr(szLocale, '=');
+        if (!pszLocale)
+            pszLocale = szLocale;
+        else
+            pszLocale++;
+        bool fSeenC = false;
+        bool fSeenPOSIX = false;
+        do
+        {
+            const char *pszEnd = strchr(pszLocale, ';');
+
+            if (   RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(pszLocale)
+                && (   pszLocale[5] == '\0'
+                    || RT_C_IS_PUNCT(pszLocale[5])) )
+                return RTStrCopyEx(pszName, cbName, pszLocale, 5);
+
+            if (   pszLocale[0] == 'C'
+                && (   pszLocale[1] == '\0'
+                    || RT_C_IS_PUNCT(pszLocale[1])) )
+                fSeenC = true;
+            else if (   strncmp(pszLocale, "POSIX", 5) == 0
+                     && (   pszLocale[5] == '\0'
+                        || RT_C_IS_PUNCT(pszLocale[5])) )
+                fSeenPOSIX = true;
+
+            /* advance */
+            pszLocale = pszEnd ? strchr(pszEnd + 1, '=') : NULL;
+        } while (pszLocale++);
+
+        if (fSeenC || fSeenPOSIX)
+            return RTStrCopy(pszName, cbName, "C"); /* C and POSIX should be identical IIRC, so keep it simple. */
+
+        rc = VERR_NOT_AVAILABLE;
+    }
+
+    /*
+     * Fallback.
+     */
+    if (   GetLocaleInfoA(GetUserDefaultLCID(), LOCALE_SISO639LANGNAME, szLocale, sizeof(szLocale)) == 3
+        && GetLocaleInfoA(GetUserDefaultLCID(), LOCALE_SISO3166CTRYNAME, &szLocale[3], sizeof(szLocale) - 4) == 3)
+    {
+        szLocale[2] = '_';
+        Assert(RTLOCALE_IS_LANGUAGE2_UNDERSCORE_COUNTRY2(szLocale));
+        return RTStrCopy(pszName, cbName, szLocale);
+    }
+
+    return rc;
+}
+
+
Index: /trunk/src/VBox/Runtime/r3/win/RTLocaleQueryUserCountryCode-win.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/win/RTLocaleQueryUserCountryCode-win.cpp	(revision 68120)
+++ /trunk/src/VBox/Runtime/r3/win/RTLocaleQueryUserCountryCode-win.cpp	(revision 68121)
@@ -1,9 +1,9 @@
 /* $Id$ */
 /** @file
- * IPRT - Log To Debugger, Win32.
+ * IPRT - RTLocaleQueryUserCountryCode, ring-3, Windows.
  */
 
 /*
- * Copyright (C) 2006-2016 Oracle Corporation
+ * Copyright (C) 2017 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
