哪些组件使用语言环境变量? [英] Which components use the locale variables?

查看:86
本文介绍了哪些组件使用语言环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读到每个进程都有一组与之关联的语言环境变量.例如,以下是与我的系统上的bash进程关联的语言环境变量:

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.

C标准函数(例如:fwrite())和Linux系统调用是否使用它们?某些C标准函数或某些Linux系统调用的行为是否会根据某些区域设置变量的值而有所不同?

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?

还是仅某些程序可以使用这些语言环境变量?例如,我可以编写一个程序,该程序将根据LANG语言环境变量的值以不同的语言向用户显示消息.

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.

推荐答案

默认情况下, C的标准库函数使用"C"语言环境.您可以将其切换到用户区域设置,以启用特定于区域设置:

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

  • 字符处理
  • 整理
  • 日期/时间格式
  • 数字编辑
  • 货币格式
  • 消息传递

POSIX setlocale 文档包含不完整的语言环境列表受其影响的功能:

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,touper ,uselocale,wcscoll,wcstod,wcstombs,wcsxfrm,wctomb

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

例如:

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

输出:

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

这篇关于哪些组件使用语言环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆