ReactOS 0.4.16-dev-1520-gb558596
LocaleNameToLCID.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Win32 Base API
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: Implementation of LocaleNameToLCID
5 * COPYRIGHT: Copyright 2025 Timo Kreuzer <timo.kreuzer@reactos.org>
6 */
7
8#include "k32_vista.h"
9#include <ndk/rtlfuncs.h>
10
11#define NDEBUG
12#include <debug.h>
13
14LCID
19{
21 LCID Lcid;
22
23 /* Validate flags */
25 {
27 return 0;
28 }
29
30 /* Check for LOCALE_NAME_USER_DEFAULT (NULL) */
31 if (lpName == NULL)
32 {
33 return GetUserDefaultLCID();
34 }
35
36 /* Check for LOCALE_NAME_INVARIANT (L"") */
37 if (lpName[0] == L'\0')
38 {
40 }
41
42 /* Call the RTL function (include neutral names) */
43 Status = RtlLocaleNameToLcid(lpName, &Lcid, RTL_LOCALE_ALLOW_NEUTRAL_NAMES);
44 if (!NT_SUCCESS(Status))
45 {
47 return 0;
48 }
49
50 /* Are neutral locales allowed? */
52 {
53 /* Check if we got a neutral locale */
54 LANGID LangId = LANGIDFROMLCID(Lcid);
55 USHORT SubLangId = SUBLANGID(LangId);
56 if (SubLangId == SUBLANG_NEUTRAL)
57 {
58 /* Adjust it to be the default locale */
60 }
61 else if (SubLangId >= 0x18)
62 {
63 /* Handle special neutral LCIDs */
64 switch (Lcid)
65 {
66 case 0x0742C: return 0x0082C; // "az-Cyrl" -> "az-Cyrl-AZ"
67 case 0x0782C: return 0x0042C; // "az-Latn" -> "az-Latn-AZ"
68 case 0x07C67: return 0x00867; // "ff-Latn" -> "ff-Latn-SN"
69 case 0x0781A: return 0x0141A; // "bs" -> "bs-Latn-BA"
70 case 0x0641A: return 0x0201A; // "bs-Cyrl" -> "bs-Cyrl-BA"
71 case 0x0681A: return 0x0141A; // "bs-Latn" -> "bs-Latn-BA"
72 case 0x07C5C: return 0x0045C; // "chr-Cher" -> "chr-Cher-US"
73 case 0x07C2E: return 0x0082E; // "dsb" -> "dsb-DE"
74 case 0x07C68: return 0x00468; // "ha-Latn" -> "ha-Latn-NG"
75 case 0x0785D: return 0x0045D; // "iu-Cans" -> "iu-Cans-CA"
76 case 0x07C5D: return 0x0085D; // "iu-Latn" -> "iu-Latn-CA"
77 case 0x07C92: return 0x00492; // "ku-Arab" -> "ku-Arab-IQ"
78 case 0x07850: return 0x00450; // "mn-Cyrl" -> "mn-MN"
79 case 0x07C50: return 0x00850; // "mn-Mong" -> "mn-Mong-CN"
80 case 0x07C14: return 0x00414; // "nb" -> "nb-NO"
81 case 0x07814: return 0x00814; // "nn" -> "nn-NO"
82 case 0x07C46: return 0x00846; // "pa-Arab" -> "pa-Arab-PK"
83 case 0x0703B: return 0x0243B; // "smn" -> "smn-FI"
84 case 0x07C59: return 0x00859; // "sd-Arab" -> "sd-Arab-PK"
85 case 0x0783B: return 0x01C3B; // "sma" -> "sma-SE"
86 case 0x07C3B: return 0x0143B; // "smj" -> "smj-SE"
87 case 0x0743B: return 0x0203B; // "sms" -> "sms-FI"
88 case 0x06C1A: return 0x0281A; // "sr-Cyrl" -> "sr-Cyrl-RS"
89 case 0x0701A: return 0x0241A; // "sr-Latn" -> "sr-Latn-RS"
90 case 0x07C28: return 0x00428; // "tg-Cyrl" -> "tg-Cyrl-TJ"
91 case 0x07C5F: return 0x0085F; // "tzm-Latn" -> "tzm-Latn-DZ"
92 case 0x0785F: return 0x0105F; // "tzm-Tfng" -> "tzm-Tfng-MA"
93 case 0x07843: return 0x00843; // "uz-Cyrl" -> "uz-Cyrl-UZ"
94 case 0x07C43: return 0x00443; // "uz-Latn" -> "uz-Latn-UZ"
95 case 0x07804: return 0x00804; // "zh" -> "zh-CN"
96 case 0x07C04: return 0x00C04; // "zh-Hant" -> "zh-HK"
97 }
98
99 /* Should not happen */
100 DPRINT1("Unandled neutral LCID %x\n", Lcid);
101 ASSERT(FALSE);
102 return 0;
103 }
104 }
105
106 return Lcid;
107}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
LCID WINAPI LocaleNameToLCID(_In_ LPCWSTR lpName, _In_ DWORD dwFlags)
LCID WINAPI GetUserDefaultLCID(void)
Definition: locale.c:1216
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
NTSYSAPI NTSTATUS WINAPI RtlLocaleNameToLcid(const WCHAR *, LCID *, ULONG)
USHORT LANGID
Definition: mui.h:9
#define ASSERT(a)
Definition: mode.c:44
LPCWSTR LPCWSTR LPCWSTR DWORD dwFlags
Definition: env.c:37
#define _In_
Definition: no_sal2.h:158
#define SORT_DEFAULT
#define MAKELCID(lgid, srtid)
unsigned short USHORT
Definition: pedump.c:61
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANGID(l)
Definition: nls.h:17
#define LANGIDFROMLCID(l)
Definition: nls.h:18
#define SUBLANG_NEUTRAL
Definition: nls.h:167
#define SUBLANG_DEFAULT
Definition: nls.h:168
DWORD LCID
Definition: nls.h:13
#define PRIMARYLANGID(l)
Definition: nls.h:16
#define LANG_INVARIANT
Definition: nls.h:23
_In_ LPCSTR lpName
Definition: winbase.h:2830
#define WINAPI
Definition: msvc.h:6
#define LOCALE_ALLOW_NEUTRAL_NAMES
Definition: winnls.h:25
_In_ CONST DEVPROPKEY _In_ LCID Lcid
Definition: iofuncs.h:2415
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185