Skip to main content

IAR Embedded Workbench for RX 5.20

Locale

In this section:

Locale is a part of the C language that allows language and country-specific settings for several areas, such as currency symbols, date and time, and multibyte character encoding.

Depending on which library configuration you are using, you get different levels of locale support. However, the more locale support, the larger your code will get. It is therefore necessary to consider what level of support your application needs. See Runtime library configurations.

The DLIB runtime library can be used in two main modes:

  • Using a full library configuration that has a locale interface, which makes it possible to switch between different locales during runtime

    The application starts with the C locale. To use another locale, you must call the setlocale function or use the corresponding mechanisms in C++. The locales that the application can use are set up at linkage.

  • Using a normal library configuration that does not have a locale interface, where the C locale is hardwired into the application.

Note

If multibytes are to be printed, you must make sure that the implementation of __write in the DLIB low-level I/O interface can handle them.

Specifying which locales that should be available in your application

Caution

Choose Project>Options>General Options>Library Options 2>Locale support.

Danger

Use the linker option ‑‑keep with the tag of the locale as the parameter, for example:

‑‑keep _Locale_cs_CZ_iso8859_2

The available locales are listed in the file SupportedLocales.json in the rx\config directory, for example:

['Czech language locale for Czech Republic', 'iso8859-2', 'cs_CZ.iso8859-2', '_Locale_cs_CZ_iso8859_2'],

The line contains the full locale name, the encoding for the locale, the abbreviated locale name, and the tag to be used as parameter to the linker option ‑‑keep.

Changing locales at runtime

The standard library function setlocale is used for selecting the appropriate portion of the application’s locale when the application is running.

The setlocale function takes two arguments. The first one is a locale category that is constructed after the pattern LC_CATEGORY. The second argument is a string that describes the locale. It can either be a string previously returned by setlocale, or it can be a string constructed after the pattern:

lang_REGION

or

lang_REGION.encoding

The lang part specifies the language code, and the REGION part specifies a region qualifier, and encoding specifies the multibyte character encoding that should be used. The available encodings are ISO-8859-1, ISO-8859-2, ISO-8859-4, ISO-8859-5, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-15, CP932, and UTF-8.

For a complete list of the available locales and their respective encoding, see the file SupportedLocales.json in the rx\config directory.

Example

This example sets the locale configuration symbols to Swedish to be used in Finland and UTF8 multibyte character encoding:

setlocale (LC_ALL, "sv_FI.UTF8");