Jump to content

Locale Support

From EDM2
Revision as of 16:46, 14 March 2005 by 194.109.223.144 (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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:

#include <stdio.h>
#include <unidef.h>

int main(void)
{
   LocaleObject      locale_object = NULL;
   UniChar           *pinfo_item;
   int               rc = ULS_SUCCESS;


   rc = UniCreateLocaleObject(UNI_UCS_STRING_POINTER,
                                   (UniChar *)L"", &locale_object);
   if (rc != ULS_SUCCESS)
        {
           printf("UniCreateLocaleObject error: return code = %u\n", rc);
           return 1;
        }
         /* Query the Abriviated name of the current locale */
         rc = UniQueryLocaleItem(locale_object,
                                 LOCI_sLanguageID,
                                 &pinfo_item);
         if (rc != ULS_SUCCESS) {
           printf("UniQueryLocaleItem error: return code = %u\n", rc);
           return 1;
         }
         rc = UniFreeMem(pinfo_item);
         if (rc != ULS_SUCCESS) {
           printf("UniFreeMem error: return code = %u\n", rc);
           return 1;
         }

   printf("sLanguageID = %ls",pinfo_item);
   return(0);
}