- 练习 6:Bash:语言设置,
LANG,locale,dpkg-reconfigure locales- 这样做
- 你会看到什么
- 解释
- 附加题
练习 6:Bash:语言设置,LANG,locale,dpkg-reconfigure locales
原文:Exercise 6. Bash: language settings, LANG, locale, dpkg-reconfigure locales
译者:飞龙
协议:CC BY-NC-SA 4.0
自豪地采用谷歌翻译
在 Linux 中,语言选择像导出变量一样简单。这是正确的,通过查看这个变量,程序决定如何和你交流。当然,为了使其工作,程序必须支持区域设置,并将其翻译成可用和安装的语言。让我们通过安装法语区域设置,看看它的工作原理。
现在,你将学习如何安装和选择一个区域设置。
这样做
1: echo $LANG2: locale3: man man # press q to exit man4: sudo dpkg-reconfigure locales
现在,选择fr_FR.UTF-8 locale,通过使用方向键来浏览列表,并使用看空格来选择区域设置。选择en_US.UTF-8作为默认的系统区域。
5: export LANG=fr_FR.UTF-86: echo $LANG7: locale # press q to exit man8: man man9: export LANG=en_US.UTF-8
你会看到什么
user1@vm1:~$ echo $LANGen_US.UTF-8user1@vm1:~$ localeLANG=en_US.UTF-8LANGUAGE=en_US:enLC_CTYPE="en_US.UTF-8"LC_NUMERIC="en_US.UTF-8"LC_TIME="en_US.UTF-8"LC_COLLATE="en_US.UTF-8"LC_MONETARY="en_US.UTF-8"LC_MESSAGES="en_US.UTF-8"LC_PAPER="en_US.UTF-8"LC_NAME="en_US.UTF-8"LC_ADDRESS="en_US.UTF-8"LC_TELEPHONE="en_US.UTF-8"LC_MEASUREMENT="en_US.UTF-8"LC_IDENTIFICATION="en_US.UTF-8"LC_ALL=user1@vm1:~$ man manMAN(1) Manual pager utils MAN(1)NAMEman - an interface to the on-line reference manualsuser1@vm1:~$ sudo dpkg-reconfigure locales---------------| Configuring locales |-----------------------| || Locales are a framework to switch between multiple || languages and allow users to use their language, || country, characters, collation order, etc. || || Please choose which locales to generate. UTF-8 locales || should be chosen by default, particularly for new || installations. Other character sets may be useful for || backwards compatibility with older systems and software. || || <Ok> || |------------------------------------------------------------------------| Configuring locales |--------| Locales to be generated: || || [ ] fr_BE@euro ISO-8859-15 || [ ] fr_CA ISO-8859-1 || [ ] fr_CA.UTF-8 UTF-8 || [ ] fr_CH ISO-8859-1 || [ ] fr_CH.UTF-8 UTF-8 || [*] fr_FR ISO-8859-1 || [ ] fr_FR.UTF-8 UTF-8 || [ ] fr_FR@euro ISO-8859-15 || || || <Ok> <Cancel> || |------------------------------------------------------------ Configuring locales ----------------------| || Many packages in Debian use locales to display text in || the correct language for the user. You can choose a || default locale for the system from the generated || locales. || || This will select the default language for the entire || system. If this system is a multi-user system where not || all users are able to speak the default language, they || will experience difficulties. || || <Ok> || |------------------------------------------------------------------------- Configuring locales --------------| Default locale for the system environment: || || None || en_US.UTF-8 || fr_FR.UTF-8 || || || <Ok> <Cancel> || |-----------------------------------------------Generating locales (this might take a while)...en_US.UTF-8... donefr_FR.UTF-8... doneGeneration complete.user1@vm1:~$ export LANG=fr_FR.UTF-8user1@vm1:~$ echo $LANGfr_FR.UTF-8user1@vm1:~$ localeLANG=fr_FR.UTF-8LANGUAGE=en_US:enLC_CTYPE="fr_FR.UTF-8"LC_NUMERIC="fr_FR.UTF-8"LC_TIME="fr_FR.UTF-8"LC_COLLATE="fr_FR.UTF-8"LC_MONETARY="fr_FR.UTF-8"LC_MESSAGES="fr_FR.UTF-8"LC_PAPER="fr_FR.UTF-8"LC_NAME="fr_FR.UTF-8"LC_ADDRESS="fr_FR.UTF-8"LC_TELEPHONE="fr_FR.UTF-8"LC_MEASUREMENT="fr_FR.UTF-8"LC_IDENTIFICATION="fr_FR.UTF-8"LC_ALL=user1@vm1:~$ man manMAN(1) Utilitaires de l'afficheur des pages de manuel MAN(1)NOMman - interface de consultation des manuels deréférence en ligneuser1@vm1:~$ export LANG=en_US.UTF-8user1@vm1:~$
解释
打印你当前使用的
LANG变量,程序用它来确定与你进行交互时要使用的语言。按照指定的国家/地区的格式,打印所有区域变量,程序员使用它们来设置数字,地址,电话格式,以及其它。
显示 unix 手册系统的手册页。注意我如何使用
#来注释一个动作,#之后的所有内容都不执行。执行程序来重新配置你的区域设置。因为这个变化是系统层次的,你需要以 root 身份运行这个命令,这就是在
dpkg-reconfigure locales前面有sudo的原因。现在不要纠结sudo,我会让你熟悉它。导出
LANG变量,用于设置所有其他区域变量。打印出
LANG变量,你可以看到它已经改变了,按照你的预期。打印其它已更改的区域变量。
以法语显示
man手册页。将`LANG变量恢复为英文。
附加题
阅读区域设置的手册页。为此,请输入
man locale。现在,阅读
man 7 locale页面。注意我 在这里使用7,来调用关于约定的手册页。如果你愿意, 现在阅读man man,了解其他可能的代码是什么,或者只是等待涵盖它的练习。
