LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 877|回复: 6

问一个关于Linux环境变量的问题

[复制链接]
发表于 2005-11-9 12:03:47 | 显示全部楼层 |阅读模式
根据个人在论坛所看到的帖子内容理解,一个程序或者文件它们的文件名和数据都是遵从一定的编码规则,如果可以是系统改为和这些文件一致的字符编码方式并有合适的字体(如果显示中文),那么就可以解决乱码的问题,而Linux下用来设置这些的是不是就是LC_ALL, LANG, LC_CTYPE这些变量和每个应用程序自己的配置文件?不知道这么理解对不对?
发表于 2005-11-9 12:28:50 | 显示全部楼层
推荐兄弟看这篇文章:
http://www.gentoo.org/doc/en/gui ... xml#doc_chap3_sect3
Environment variables for locales

Locale settings are stored in environment variables. These are typically set in the /etc/env.d/02locale (for system-wide settings) and ~/.bashrc (for user-specific settings) file. The variables controlling different aspects of locale settings are given in the table below, those with highest precedence (ie. those that override settings below them) are at the top of the table. All variables take one name of a locale in ab_CD format given above.

Variable name         Explanation

LC_ALL         Define all locale settings at once. This is the top level setting for locales which will override any other setting.

LC_COLLATE         Define alphabetical ordering of strings. This affects eg. output of sorted directory listing.

LC_CTYPE         Define the character handling properties for the system. This determines which characters are seen as part of alphabet, numeric and so on. This also determines the character set used, if applicable.

LC_MESSAGES         Programs' localizations for applications that use message based localization scheme (majority of Gnu programs, see next chapters for closer information which do, and how to get the programs, that don't, to work).

LC_MONETARY         Defines currency units and formatting of currency type numeric values.

LC_NUMERIC         Defines formatting of numeric values which aren't monetary. Affects things such as thousand separator and decimal separator.

LC_TIME         Defines formatting of dates and times.

LC_PAPER         Defines default paper size.

LANG         Defines all locale settings at once. This setting can be overridden by individual LC_* settings above or even by LC_ALL.

Note: Even though most programs work with LC_ALL only, some of them misbehave if LC_ALL is set but LANG isn't. If you want to play safe, set them both.

Most typically users only set the LANG variable and perhaps LC_CTYPE variable on user level by adding definitions to shells startup files defining the environment variable manually from command line:

Code Listing 3.1: setting the German locale

export LANG="de_DE@euro"

Note: Append @euro to your locale if you want to use the Euro currency symbol
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-11-9 17:43:21 | 显示全部楼层
多谢多谢,我先研究一下。
回复 支持 反对

使用道具 举报

发表于 2005-11-9 18:56:53 | 显示全部楼层
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-11-9 19:22:12 | 显示全部楼层
恩,好文章,多谢二位了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-11-9 19:41:24 | 显示全部楼层
看过上面的文章,尚有几个疑问求证:
1、一个程序如何存储和显示数据,是不是根据自己所使用的程序库的locale决定的,如果在程序中没有设定,那么就使用当前系统环境的locale?如果这样的话是不是就可以实现bash使用英文而在X中使用中文了,我自己试了一下,在bash中把LC_ALL改了,结果bash和X都成了英文。不知道问题出在哪里?
2、以前在论坛看到的如何使软件正常显示中文,大体的思路是不是都是先对软件设置正确的locale,然后配置字体系统,让系统能够找到字符对应字体显示。不知道我这样理解对不对。
回复 支持 反对

使用道具 举报

发表于 2005-11-9 21:50:33 | 显示全部楼层
Post by Maxshine
看过上面的文章,尚有几个疑问求证:
1、一个程序如何存储和显示数据,是不是根据自己所使用的程序库的locale决定的,如果在程序中没有设定,那么就使用当前系统环境的locale?如果这样的话是不是就可以实现bash使用英文而在X中使用中文了,我自己试了一下,在bash中把LC_ALL改了,结果bash和X都成了英文。不知道问题出在哪里?

一个软件支持多语言,通常就是它可以根据环境中的 locale 设置来选择显示对应的字串。
可以将 bash 和 X 设为不同的 locale。比如在 .bashrc 里面 LC_CTYPE=C,而 .xinitrc 里面 LC_CTYPE=zh_CN.UTF-8。
Post by Maxshine

2、以前在论坛看到的如何使软件正常显示中文,大体的思路是不是都是先对软件设置正确的locale,然后配置字体系统,让系统能够找到字符对应字体显示。不知道我这样理解对不对。

首先是该软件要支持多语言,针对不同的 locale,匹配字体的方式会依软件不同而不同。

关于 Linux 的国际化与本地化,还有一份文档不错:
http://jserv.sayya.org/i18n/linux-i18n-intro.pdf
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表