Difference between revisions of "Internationalization/posix locale"

m
(Checking for default locale: another method)
Line 27: Line 27:
 
localeconv()</code>   
 
localeconv()</code>   
 
see ''manpage locale(7)'' to get more information.
 
see ''manpage locale(7)'' to get more information.
 +
 +
Another way to obtain the current locale is to use the environnement variable ''LANGUAGE'', this is done with the following code:
 +
 +
<code>[eiffel,N]
 +
environement : EXECUTION_ENVIRONMENT
 +
...
 +
environement.get ("LANGUAGE")
 +
    -- returns the (rank)list (as string) of languages set by the user
 +
</code>
  
 
== Retrieving locale information ==
 
== Retrieving locale information ==

Revision as of 02:18, 5 September 2006


Summary

My Summary is based on article by Michael Becker (see here).This summary is more or less concerning SuSE-Linux.

There are differences between User-locale and C-locale. C-locale, is the local, which is only effective in C-environment. If there are no locales set in user environment, then C-locale is effective, which is so called "POSIX"-locale.

With C-command setlocale (LC_ALL,"") one set C-locale with User-locale. So one could retrieve details about User-locale information with C-functions.

Listing available locales

There are two directories that one could get information about locales. They are: /usr/share/locale/ /usr/share/i18n/

In the first directory, the locales are binary files. So we could not need them for our purpose since i do not know how to read them for the moment.

In the second directory there are at least 2 subdirectories, with names charmaps and locales.

Shell command ls /usr/share/i18n/locales/ list all the available locales.

Checking for default locale

With shell command "locale" one can get infomation about default locale. In C, to get details of localeone can use

setlocale (LC_ALL,"")
localeconv()

see manpage locale(7) to get more information.

Another way to obtain the current locale is to use the environnement variable LANGUAGE, this is done with the following code:

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

Retrieving locale information

C-command nl_langinfo()(defined in langinfo.h) one could get information about all categories. For example, with nl_langinfo(D_T_FMT), one get a pointer at a string, which in form of %a %d %b %Y %T %Z.

Other information

Using a parser one could also retrieve locale information, about which I do not have a lot of idea.

Still there are C-functions to use categories. For example,

strftime()
strptime()
wcsftime()

for LC_TIME For another example,

isalnum
isalpha
isblank

and so on for LC_CTYPE.

For more information please read local-Specification of Unix Open