This commit is contained in:
wizardforcel 2017-08-22 17:17:05 +08:00
parent 2645e6500b
commit 3a7f3148ed
1 changed files with 175 additions and 0 deletions

175
ex6.md Normal file
View File

@ -0,0 +1,175 @@
# 练习 6Bash语言设置`LANG``locale``dpkg-reconfigure locales`
> 原文:[Exercise 6. Bash: language settings, LANG, locale, dpkg-reconfigure locales](https://archive.fo/QgMfr)
> 译者:[飞龙](https://github.com/wizardforcel)
> 协议:[CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/)
> 自豪地采用[谷歌翻译](https://translate.google.cn/)
在 Linux 中,语言选择像导出变量一样简单。这是正确的,通过查看这个变量,程序决定如何和你交流。当然,为了使其工作,程序必须支持区域设置,并将其翻译成可用和安装的语言。让我们通过安装法语区域设置,看看它的工作原理。
现在,你将学习如何安装和选择一个区域设置。
## 这样做
```
1: echo $LANG
2: locale
3: man man # press q to exit man
4: sudo dpkg-reconfigure locales
```
现在,选择`fr_FR.UTF-8 locale`,通过使用方向键来浏览列表,并使用看空格来选择区域设置。选择`en_US.UTF-8`作为默认的系统区域。
```
5: export LANG=fr_FR.UTF-8
6: echo $LANG
7: locale # press q to exit man
8: man man
9: export LANG=en_US.UTF-8
```
## 你会看到什么
```
user1@vm1:~$ echo $LANG
en_US.UTF-8
user1@vm1:~$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_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 man
MAN(1) Manual pager utils MAN(1)
NAME
man - an interface to the on-line reference manuals
user1@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... done
fr_FR.UTF-8... done
Generation complete.
user1@vm1:~$ export LANG=fr_FR.UTF-8
user1@vm1:~$ echo $LANG
fr_FR.UTF-8
user1@vm1:~$ locale
LANG=fr_FR.UTF-8
LANGUAGE=en_US:en
LC_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 man
MAN(1) Utilitaires de l'afficheur des pages de manuel MAN(1)
NOM
man - interface de consultation des manuels de
référence en ligne
user1@vm1:~$ export LANG=en_US.UTF-8
user1@vm1:~$
```
## 解释
1. 打印你当前使用的`LANG`变量,程序用它来确定与你进行交互时要使用的语言。
2. 按照指定的国家/地区的格式,打印所有区域变量,程序员使用它们来设置数字,地址,电话格式,以及其它。
3. 显示 unix 手册系统的手册页。注意我如何使用`#`来注释一个动作,`#`之后的所有内容都不执行。
4. 执行程序来重新配置你的区域设置。因为这个变化是系统层次的,你需要以 root 身份运行这个命令,这就是在`dpkg-reconfigure locales`前面有`sudo`的原因。现在不要纠结`sudo`,我会让你熟悉它。
5. 导出`LANG`变量,用于设置所有其他区域变量。
6. 打印出`LANG`变量,你可以看到它已经改变了,按照你的预期。
7. 打印其它已更改的区域变量。
8. 以法语显示`man`手册页。
9. 将`LANG变量恢复为英文。
## 附加题
+ 阅读区域设置的手册页。为此,请输入`man locale`。
+ 现在,阅读`man 7 locale`页面。注意我 在这里使用`7`,来调用关于约定的手册页。如果你愿意, 现在阅读`man man`,了解其他可能的代码是什么,或者只是等待涵盖它的练习。