Tizen Native API
Functions | Defines
Ulocale
i18n

Functions

int i18n_ulocale_get_default (const char **locale)
 Gets the default locale.
int i18n_ulocale_set_default (const char *locale_id)
 Sets the default locale.
int i18n_ulocale_get_language (const char *locale_id, char *language, int32_t language_capacity, int32_t *buf_size_language)
 Gets the language code for the specified locale.
int32_t i18n_ulocale_get_country (const char *locale_id, char *country, int32_t country_capacity, int *error)
 Gets the country code for the specified locale.
int i18n_ulocale_get_display_name (const char *locale_id, const char *in_locale_id, i18n_uchar *result, int32_t max_result_size, int32_t *buf_size_display_name)
 Gets the full name suitable for display for the specified locale.
const char * i18n_ulocale_get_available (int32_t n)
 Gets the specified locale from a list of all available locales.
int32_t i18n_ulocale_count_available (void)
 Gets the size of the all available locale list.

Defines

#define I18N_ULOCALE_CHINESE   "zh"
#define I18N_ULOCALE_ENGLISH   "en"
#define I18N_ULOCALE_FRENCH   "fr"
#define I18N_ULOCALE_GERMAN   "de"
#define I18N_ULOCALE_ITALIAN   "it"
#define I18N_ULOCALE_JAPANESE   "ja"
#define I18N_ULOCALE_KOREAN   "ko"
#define I18N_ULOCALE_SIMPLIFIED_CHINESE   "zh_CN"
#define I18N_ULOCALE_TRADITIONAL_CHINESE   "zh_TW"
#define I18N_ULOCALE_CANADA   "en_CA"
#define I18N_ULOCALE_CANADA_FRENCH   "fr_CA"
#define I18N_ULOCALE_CHINA   "zh_CN"
#define I18N_ULOCALE_PRC   "zh_CN"
#define I18N_ULOCALE_FRANCE   "fr_FR"
#define I18N_ULOCALE_GERMANY   "de_DE"
#define I18N_ULOCALE_ITALY   "it_IT"
#define I18N_ULOCALE_JAPAN   "ja_JP"
#define I18N_ULOCALE_KOREA   "ko_KR"
#define I18N_ULOCALE_TAIWAN   "zh_TW"
#define I18N_ULOCALE_UK   "en_GB"
#define I18N_ULOCALE_US   "en_US"

A ulocale represents a specific geographical, political, or cultural region.

Required Header

#include <utils_i18n.h>

Overview

A ulocale represents a specific geographical, political, or cultural region. An operation that requires a ulocale to perform its task is called locale-sensitive and uses the ulocale to tailor information for the user. For example, displaying a number is a locale-sensitive operation. The number should be formatted according to the customs/conventions of the user's native country, region, or culture. In the C APIs, a locale is simply a const char string.

Sample Code 1

Gets a default locale and a full name for the locale

    const char *locale;
    const char *in_locale_id = "en_US";
    char language[64] = {0,};
    i18n_uchar result_w[64] = {0,};
    char result[64] = {0,};
    int language_capacity = 64;
    int buf_size_language;
    int buf_size_display_name;
    int ret = I18N_ERROR_NONE;

    // Sets default locale
    ret = i18n_ulocale_set_default(getenv("LC_TIME"));

    // Gets default locale
    ret = i18n_ulocale_get_default(&locale);
    if ( ret != I18N_ERROR_NONE ) {
        dlog_print(DLOG_INFO, LOG_TAG, "i18n_ulocale_get_default() is failed!!! \n");
    }
    dlog_print(DLOG_INFO, LOG_TAG, "default locale : %s\n", locale);    // default locale : en_GB.UTF-8

    // Gets the language code for the specified locale
    ret = i18n_ulocale_get_language(locale, language, language_capacity, &buf_size_language);
    if ( ret != I18N_ERROR_NONE ) {
        dlog_print(DLOG_INFO, LOG_TAG, "i18n_ulocale_get_language() is failed!!! \n");
    }
    dlog_print(DLOG_INFO, LOG_TAG, "language code for the locale : %s\n", language);  // language code for the locale : en

    // Gets the full name suitable for display for the specified locale
    ret = i18n_ulocale_get_display_name(locale, in_locale_id, result_w, 64, &buf_size_display_name);
    i18n_ustring_copy_au(result, result_w);
    dlog_print(DLOG_INFO, LOG_TAG, "full name suitable for the locale : %s\n", result); // full name suitable for the locale : English (United Kingdom)

Sample Code 2

See all available locales

    int i = 0;
    int32_t count = i18n_ulocale_count_available();
    for(i = 0; i < count; i++)
    {
        dlog_print(DLOG_INFO, LOG_TAG, "Available locale %d : %s " ,i, i18n_ulocale_get_available(i));
        //   ...
        //Available locale 5 : en_GB
        //Available locale 6 : en_US
        //Available locale 7 : en_US_POSIX
        //   ...
    }

Define Documentation

#define I18N_ULOCALE_CANADA   "en_CA"

Useful constant for en_CA

#define I18N_ULOCALE_CANADA_FRENCH   "fr_CA"

Useful constant for fr_CA

#define I18N_ULOCALE_CHINA   "zh_CN"

Useful constant for zh_CN

#define I18N_ULOCALE_CHINESE   "zh"

Useful constant for zh

#define I18N_ULOCALE_ENGLISH   "en"

Useful constant for en

#define I18N_ULOCALE_FRANCE   "fr_FR"

Useful constant for fr_FR

#define I18N_ULOCALE_FRENCH   "fr"

Useful constant for fr

#define I18N_ULOCALE_GERMAN   "de"

Useful constant for de

#define I18N_ULOCALE_GERMANY   "de_DE"

Useful constant for de_DE

#define I18N_ULOCALE_ITALIAN   "it"

Useful constant for it

#define I18N_ULOCALE_ITALY   "it_IT"

Useful constant for it_IT

#define I18N_ULOCALE_JAPAN   "ja_JP"

Useful constant for ja_JP

#define I18N_ULOCALE_JAPANESE   "ja"

Useful constant for ja

#define I18N_ULOCALE_KOREA   "ko_KR"

Useful constant for ko_KR

#define I18N_ULOCALE_KOREAN   "ko"

Useful constant for ko

#define I18N_ULOCALE_PRC   "zh_CN"

Useful constant for zh_CN

#define I18N_ULOCALE_SIMPLIFIED_CHINESE   "zh_CN"

Useful constant for zh_CN

#define I18N_ULOCALE_TAIWAN   "zh_TW"

Useful constant for zh_TW

#define I18N_ULOCALE_TRADITIONAL_CHINESE   "zh_TW"

Useful constant for zh_TW

#define I18N_ULOCALE_UK   "en_GB"

Useful constant for en_GB

#define I18N_ULOCALE_US   "en_US"

Useful constant for en_US


Function Documentation

int32_t i18n_ulocale_count_available ( void  )

Gets the size of the all available locale list.

Since :
2.3
Returns:
the size of the locale list
const char* i18n_ulocale_get_available ( int32_t  n)

Gets the specified locale from a list of all available locales.

The return value is a pointer to an item of a locale name array. Both this array and the pointers it contains are owned by I18N and should not be deleted or written through by the caller. The locale name is terminated by a null pointer.

Since :
2.3
Parameters:
[in]nthe specific locale name index of the available locale list
Returns:
A specified locale name of all available locales
int32_t i18n_ulocale_get_country ( const char *  locale_id,
char *  country,
int32_t  country_capacity,
int *  error 
)

Gets the country code for the specified locale.

Since :
2.3
Parameters:
[in]locale_idThe locale to get the country code with
[out]countrythe country code for locale_id
[in]country_capacityThe size of the country buffer to store the country code with
[out]errorerror information if retrieving the country code is failed (It must not indicate a failure before the function call)
Returns:
The actual buffer size needed for the language code
If it's greater than language_capacity, the returned language code will be truncated.
int i18n_ulocale_get_default ( const char **  locale)

Gets the default locale.

The returned string is a snapshot in time, and will remain valid and unchanged even when i18n_ulocale_set_default() is called.

Since :
2.3
Parameters:
[out]localeThe default locale
Return values:
I18N_ERROR_NONESuccessful
I18N_ERROR_INVALID_PARAMETERInvalid function parameter
int i18n_ulocale_get_display_name ( const char *  locale_id,
const char *  in_locale_id,
i18n_uchar *  result,
int32_t  max_result_size,
int32_t *  buf_size_display_name 
)

Gets the full name suitable for display for the specified locale.

Since :
2.3
Parameters:
[in]locale_idThe locale to get the displayable name with
NULL may be used to specify the default.
[in]in_locale_idThe locale to be used to display the name
NULL may be used to specify the default.
[out]resultThe displayable name for locale_id
[in]max_result_sizeThe size of the name buffer to store the displayable full name with
[out]buf_size_display_nameThe actual buffer size needed for the displayable name
If it's greater than max_result_size, the returned displayable name will be truncated.
Return values:
I18N_ERROR_NONESuccessful
I18N_ERROR_INVALID_PARAMETERInvalid function parameter
int i18n_ulocale_get_language ( const char *  locale_id,
char *  language,
int32_t  language_capacity,
int32_t *  buf_size_language 
)

Gets the language code for the specified locale.

Since :
2.3
Parameters:
[in]locale_idThe locale to get the ISO language code with
[out]languageThe language code for locale_id
[in]language_capacityThe size of the language buffer to store the language code with
[out]buf_size_languageThe actual buffer size needed for the language code
If it's greater than language_capacity, the returned language code will be truncated.
Return values:
I18N_ERROR_NONESuccessful
I18N_ERROR_INVALID_PARAMETERInvalid function parameter
int i18n_ulocale_set_default ( const char *  locale_id)

Sets the default locale.

Since :
2.3
Parameters:
[in]locale_idThe new ICU default locale
A value of NULL will try to get the system's default locale.
Return values:
I18N_ERROR_NONESuccessful

Except as noted, this content - excluding the Code Examples - is licensed under Creative Commons Attribution 3.0 and all of the Code Examples contained herein are licensed under BSD-3-Clause.
For details, see the Content License