Locale Support
Appearance
Obtaining localized information from the system
If you want to know how the date is displayed on the current system or how the names of the month are spelled in the currently selected language or what the currently selected language is at all at this time there is not well documented library that comes with ACP/MCP & eCS. LIBULS
This article is intended to give you a short introduction on the usage of that library.
in LIBULS there is a whole set of call that support codepage conversion and querying locale information.
This article will give a short quick and dirty sample on how to use it.
Reasons to use the LIBULS functions instead of querying enivronment:
- Normaly LANG will contain something usefull like: en_us or de_de from which you could parse a language. But LANG=myRealyLongStupidLocale is allowed as well, now you tell me which language this locale represents.
- Using the LIBULS allow you to acces not only language names, but a whole set of localized settings
- Using a country number will result in suplying several translations for the same language ( e.g. german is used in 041,049,043) where using the locale will return a common language for all of them : de
Now lets gets hands on with a sample, later I'll descibe what every line does here:
01: #include <stdio.h> 02: #include <unidef.h> 03: 04: int main(void) 05: { 06: LocaleObject locale_object = NULL; 07: UniChar *pinfo_item; 08: int rc = ULS_SUCCESS; 09: 10: 11: rc = UniCreateLocaleObject(UNI_UCS_STRING_POINTER, 12: (UniChar *)L"", &locale_object); 13: if (rc != ULS_SUCCESS) 14: { 15: printf("UniCreateLocaleObject error: return code = %u\n", rc); 16: return 1; 17: } 18: /* Query the Abriviated name of the current locale */ 19: rc = UniQueryLocaleItem(locale_object, 20: LOCI_sLanguageID, 21: &pinfo_item); 22: if (rc != ULS_SUCCESS) { 23: printf("UniQueryLocaleItem error: return code = %u\n", rc); 24: return 1; 25: } 26: rc = UniFreeMem(pinfo_item); 27: if (rc != ULS_SUCCESS) { 28: printf("UniFreeMem error: return code = %u\n", rc); 29: return 1; 30: } 31: 32: printf("sLanguageID = %ls",pinfo_item); 33: return(0); 34: }