Which components use the locale variables?

  • A+
Category:Languages

I have read that every process has a set of locale variables associated with it. For example, these are the locale variables associated with the bash process on my system:

$ locale LANG="en_GB.UTF-8" LC_COLLATE="en_GB.UTF-8" LC_CTYPE="en_GB.UTF-8" LC_MESSAGES="en_GB.UTF-8" LC_MONETARY="en_GB.UTF-8" LC_NUMERIC="en_GB.UTF-8" LC_TIME="en_GB.UTF-8" LC_ALL= 

I want to know who actually uses these locale variables.

Do the C standard functions (for example: fwrite()) and the Linux system calls use them? Does the behavior of some C standard functions or some Linux system call differ depending on the value of some locale variable?

Or is it only certain programs that can use these locale variables? For example, I can write a program that will display messages to the user in a different language depending on the value of the LANG locale variable.

 


By default, C's stdlib functions use the "C" locale. You can switch it to the user locale to enable locale-specific

  • Character handling
  • Collating
  • Date/time formatting
  • Numeric editing
  • Monetary formatting
  • Messaging

POSIX setlocale documentation contains an incomplete list of locale-dependent functions affected by it:

catopen, exec, fprintf, fscanf, isalnum, isalpha, isblank, iscntrl, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, iswalnum, iswalpha, iswblank, iswcntrl, iswctype, iswdigit, iswgraph, iswlower, iswprint, iswpunct, iswspace, iswupper, iswxdigit, isxdigit, localeconv, mblen, mbstowcs, mbtowc, newlocale, nl_langinfo, perror, psiginfo, setlocale, strcoll, strerror, strfmon, strftime, strsignal, strtod, strxfrm, tolower, toupper, towlower, towupper, uselocale, wcscoll, wcstod, wcstombs, wcsxfrm, wctomb

E.g.:

printf("%'d/n", 1000000000); printf("Setting LC_ALL to %s/n", getenv("LANG")); setlocale(LC_ALL, ""); // Set user-preferred locale. printf("%'d/n", 1000000000); 

Outputs:

1000000000 Setting LC_ALL to en_US.UTF-8 1,000,000,000 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: