Export (0) Print
Expand All
div
eof
Expand Minimize
0 out of 2 rated this helpful - Rate this topic

_create_locale 

Creates a locale object.


_locale_t _create_locale(
   int category,
   const char *locale 
);

Parameters

category

Category.

locale

Locale name.

If a valid locale and category are given, returns the specified locale settings as a _locale_t object. The current locale settings of the program are not changed.

The _create_locale function allows you to create an object that represents certain region-specific settings, for use in locale-specific versions of many CRT functions (functions with the _l suffix). The behavior is similar to setlocale, except that instead of applying the specified locale settings to the current environment, the settings are saved in a _locale_t structure that is returned.

The category argument specifies the parts of the locale-specific behavior that are affected. The flags used for category and the parts of the program they affect are as shown in the following table.

LC_ALL

All categories, as listed below.

LC_COLLATE

The strcoll, _stricoll, wcscoll, _wcsicoll, strxfrm, _strncoll, _strnicoll, _wcsncoll, _wcsnicoll, and wcsxfrm functions.

LC_CTYPE

The character-handling functions (except isdigit, isxdigit, mbstowcs, and mbtowc, which are unaffected).

LC_MONETARY

Monetary-formatting information returned by the localeconv function.

LC_NUMERIC

Decimal-point character for the formatted output routines (such as printf), for the data-conversion routines, and for the non-monetary formatting information returned by localeconv. In addition to the decimal-point character, LC_NUMERIC sets the thousands separator and the grouping control string returned by localeconv.

LC_TIME

The strftime and wcsftime functions.

This function validates the category and locale parameters. If the category parameter is not one of the values given in the previous table or if locale is NULL, the function returns NULL.

The locale argument is a pointer to a string that specifies the name of the locale. If locale points to an empty string, the locale is the implementation-defined native environment. A value of C specifies the minimal ANSI conforming environment for C translation. The C locale assumes that all char data types are 1 byte and that their value is always less than 256. The locale argument takes the following form:

locale :: "lang[_country_region[.code_page]]" 
            | ".code_page"
            | ""
            | NULL

The set of available languages, country/region codes, and code pages includes all those supported by the Win32 NLS API. The set of language and country/region codes supported by _create_locale is listed in Language and Country/Region Strings. For more information about locale settings, see setlocale, _wsetlocale.

The previous name of this function, __create_locale (with two leading underscores), has been deprecated.

Routine Required header Compatibility

_create_locale

<locale.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For additional compatibility information, see Compatibility in the Introduction.

// crt_create_locale.c
// Sets the current locale to "Germany" using the
// setlocale function and demonstrates its effect on the strftime
// function.

#include <stdio.h>
#include <locale.h>
#include <time.h>

int main(void)
{
       time_t ltime;
       struct tm thetime;
       unsigned char str[100];
       _locale_t locale;

       // Create a locale object representing the German locale
       locale = _create_locale(LC_ALL, "German");
       time (&ltime);
       _gmtime64_s(&thetime, &ltime);

       // %#x is the long date representation, appropriate to
       // the current locale
       //
       if (!_strftime_l((char *)str, 100, "%#x", 
                     (const struct tm *)&thetime, locale))
               printf("_strftime_l failed!\n");
       else
               printf("In German locale, _strftime_l returns '%s'\n", 
                      str);

       // Create a locale object representing the default C locale
       locale = _create_locale(LC_ALL, "C");
       time (&ltime);
       _gmtime64_s(&thetime, &ltime);

       if (!_strftime_l((char *)str, 100, "%#x", 
                     (const struct tm *)&thetime, locale))
               printf("_strftime_l failed!\n");
       else
               printf("In 'C' locale, _strftime_l returns '%s'\n", 
                      str);
}
In German locale, _strftime_l returns 'Samstag, 9. Februar 2002'
In 'C' locale, _strftime_l returns 'Saturday, February 09, 2002'
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.