Jump to content

UniMakeUserLocale: Difference between revisions

From EDM2
Created page with "UniMakeUserLocale creates a user locale from a base system locale. ==Syntax== int UniMakeUserLocale (UniChar *newName, UniChar *baseName); ==Parameters== ; newName (UniCha..."
 
 
Line 2: Line 2:


==Syntax==
==Syntax==
int UniMakeUserLocale (UniChar *newName, UniChar *baseName);
int UniMakeUserLocale (UniChar *newName, UniChar *baseName);


==Parameters==
==Parameters==

Latest revision as of 19:08, 26 July 2017

UniMakeUserLocale creates a user locale from a base system locale.

Syntax

int UniMakeUserLocale (UniChar *newName, UniChar *baseName);

Parameters

newName (UniChar *)
The name of the new locale.
baseName (UniChar *)
The name of the locale to base the new locale after.

Returns

Return value (int) - returns

ULS_SUCCESS
The user locale has been created.
ULS_NOMATCH
The base system locale does not exist.
ULS_INVALID
The name supplied contains an illegal character, is too long or redefines a base system locale.
ULS_NOOP
The name supplied currently exists as a locale name.
ULS_NOMEMORY
Cannot allocate memory for the new locale.

Remarks

The names for the new locale and the base system locale must be ASCII-7 chars and at most eight characters, in length. An existing locale name must be given as the base locale name.

If the user locale already exists, a ULS_NOOP return code will be given, therefore, this API can always be called before making an update to ensure that the user locale exists.

Sample Code

This example shows how to make a user locale.

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

int main(void) {

    LocaleObject   locale_object = NULL;
    int            rc = ULS_SUCCESS;
    UniChar        *plocaleName;
    UniChar        *puniSysLocale;

    /* Create current default locale object for this process */
    rc = UniCreateLocaleObject(UNI_UCS_STRING_POINTER,
                               (UniChar *)L"", &locale_object);
    if(rc) {
      printf("UniCreateLocaleObject error: return code = %u\n", rc);
      return 1;
    }

    /* Query the name of the default locale object */
    rc = UniQueryLocaleObject(locale_object, LC_ALL,
                              UNI_UCS_STRING_POINTER,
                              (void**)&plocaleName);
    if(rc) {
      printf("UniQueryLocaleObject error: return code = %u\n", rc);
      return 1;
    }

    /* Get the locale name from the locale object string */
    puniSysLocale = UniStrtok(plocaleName, (UniChar *)L" ");

    /* Make a new locale */
    rc = UniMakeUserLocale(puniSysLocale, puniSysLocale);
    if (rc) {
      printf("UniMakeUserLocale error: return code = %u\n", rc);
      return 1;
    }

    /* free the space used by the locale object string */
    UniFreeMem(plocaleName);
    if(locale_object)
        UniFreeLocaleObject(locale_object);

    return ULS_SUCCESS;
} 

Related Functions