Difference between revisions of "Internationalization/dotnet locale"

m (Checking for default locale)
(Checking for default locale)
Line 15: Line 15:
 
== Checking for default locale ==
 
== Checking for default locale ==
  
To obtain the current locale:
+
The easiest and way to obtain the current locale is to use the following Eiffel code:
  
a_culture_info : CULTURE_INFO
+
<code>[eiffel,N]
a_culture_info.current_culture.name : SYSTEM_STRING
+
environement : EXECUTION_ENVIRONMENT
:returns the name of the current culture info, (in the format described below).
+
...
 +
environement.get ("LANGUAGE")
 +
    -- returns the (rank)list (as string) of languages set by the user
 +
</code>
 +
 
 +
an other method is:
 +
<code>[eiffel,N]
 +
a_culture_info : CULTURE_INFO
 +
a_culture_info.current_culture.name : SYSTEM_STRING
 +
    -- returns the name of the current culture info, (in the format described below).
 +
</code>
  
 
== Retrieving locale information ==
 
== Retrieving locale information ==

Revision as of 05:18, 4 September 2006


Summary

There is a class named CULTURE_INFO in "mscorlib" in EiffelStudio, which provides information about a specific culture such as:

  • associated language
  • sublanguage
  • country/region
  • calendar
  • cultural conventions

Listing available locales

I didn't find a function that returns all the available locale informations, I think because under .NET, they are all avaiable.

Checking for default locale

The easiest and way to obtain the current locale is to use the following Eiffel code:

environement : EXECUTION_ENVIRONMENT
...
environement.get ("LANGUAGE")
    -- returns the (rank)list (as string) of languages set by the user

an other method is:

a_culture_info : CULTURE_INFO
a_culture_info.current_culture.name : SYSTEM_STRING
    -- returns the name of the current culture info, (in the format described below).

Retrieving locale information

To obtain informations on a specific locale, it suffices to create an instance of CULTURE_INFO. There are basically two ways to do this:

  1. Create it with the culture identifier. This identifier maps every culture/language to an integer. It is not very usefull, because I did not find a logic behind the mapping function... You can find a table on here
  2. Create it with the name (STRING) of the culture. The culture names follow the RFC 1766 standard in the format "<languagecode2>-<country/regioncode2>", where <languagecode2> is a lowercase two-letter code derived from ISO 639-1 and <country/regioncode2> is an uppercase two-letter code derived from ISO 3166.

You can find a detailed description of RFC 1766

The CULTURE_INFO Class has some attibutes useful for the retrieving of the informations about Date, Time and Number formatting, they are:

  • date_time_format: DATE_TIME_FORMAT_INFO (see here)
Some information that is available in DATE_TIME_FORMAT_INFO
Information Result for locale "it-CH"
full_date_time_pattern dddd, d. MMMM yyyy HH:mm:ss
long_date_pattern dddd, d. MMMM yyyy
long_time_pattern HH:mm:ss
month_day_pattern d. MMMM
rfc1123_pattern ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
pm_designator
short_date_pattern dd.MM.yyyy
short_time_pattern HH:mm
sortable_date_time_pattern yyyy'-'MM'-'dd'T'HH':'mm':'ss
time_separator


  • there are also functions that return abbreviations of names of months and day:
    • get_abbreviated_day_name (dayofweek: DAY_OF_WEEK) : SYSTEM_STRING
    • get_abbreviated_month_name (month: INTEGER) : SYSTEM_STRING


  • number_format: NUMBER_FORMAT_INFO (see here)


Some information that is available in NUMBER_FORMAT_INFO
Information Result for locale "it-CH"
currency_group_separator '
currency_symbol SFr.
currency_decimal_digits 2
negative_sign -
number_decimal_digits 2
number_decimal_separator .
number_group_separator '
positive_sign +
negative_sign -
negative_infinity_symbol -Infinito
per_mille_symbol ë
na_n_symbol Non un numero reale

Other information

References