歡迎您光臨本站 註冊首頁

Redhat中文網頁顯示亂碼的解決

←手機掃碼閱讀     火星人 @ 2014-03-25 , reply:0

系統:英文版的Redhat企業版
癥狀:英文顯示沒問題;中文輸入法也沒問題;中文網頁顯示為亂碼,不管是用GB18030還是2312
解決:安裝fonts-chinese-3.02-9.6.el5.

此時相關如下:
[root@localhost ~]# rpm -qa | grep fonts- | wc -l
14
[root@localhost ~]# rpm -qa | grep fonts-
bitmap-fonts-0.3-5.1.1
xorg-x11-fonts-misc-7.1-2.1.el5
fonts-chinese-3.02-9.6.el5
xorg-x11-fonts-base-7.1-2.1.el5
xorg-x11-fonts-75dpi-7.1-2.1.el5
urw-fonts-2.3-6.1.1
xorg-x11-fonts-100dpi-7.1-2.1.el5
bitstream-vera-fonts-1.10-7
ghostscript-fonts-5.50-13.1.1
xorg-x11-fonts-ISO8859-1-75dpi-7.1-2.1.el5
xorg-x11-fonts-Type1-7.1-2.1.el5
xorg-x11-fonts-ISO8859-1-100dpi-7.1-2.1.el5
dejavu-lgc-fonts-2.10-1
xorg-x11-fonts-truetype-7.1-2.1.el5
[root@localhost ~]# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
[root@localhost ~]# locale
LANG=en_US.UTF-8
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=
[root@localhost ~]#

網上提供的消除中文亂碼的方法如下,只是一種治標的方法,應該是先查看有沒有相關的字體包已經安裝,再考慮更改如下設置:

將i18n內容改為

LANG="zh_CN.GB18030"
LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"
SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="lat0-sun16"

------------------------------------

下述命令如果有下述信息說明裝有中文字體:


[root@localhost ~]# xlsfonts | grep gb
-isas-fangsong ti-medium-r-normal--16-160-72-72-c-160-gb2312.1980-0
-isas-song ti-medium-r-normal--16-160-72-72-c-160-gb2312.1980-0
-isas-song ti-medium-r-normal--24-240-72-72-c-240-gb2312.1980-0
-misc-ar pl shanheisun uni-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
-misc-ar pl zenkai uni-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
-misc-zysong18030-medium-r-normal--0-0-0-0-c-0-gb18030.2000-0
-misc-zysong18030-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
-misc-zysong18030-medium-r-normal--0-0-0-0-c-0-gbk-0
-urw-dingbats-medium-r-normal--0-0-0-0-p-0-adobe-fontspecific
hanzigb16fs
hanzigb16st
hanzigb24st

字體所在目錄:/usr/share/locale


[root@localhost ~]# cd /usr/share/locale
[root@localhost locale]#ll

................................................

drwxr-xr-x 4 root root 4096 Dec 14 2006 zh_CN
drwxr-xr-x 3 root root 4096 Sep 26 17:38 zh_CN.GB2312
drwxr-xr-x 3 root root 4096 Sep 26 17:31 zh_HK
drwxr-xr-x 4 root root 4096 Dec 14 2006 zh_TW
drwxr-xr-x 3 root root 4096 Sep 26 17:38 zh_TW.Big5
drwxr-xr-x 3 root root 4096 Sep 26 17:31 znd
drwxr-xr-x 3 root root 4096 Sep 26 17:31 zu
drwxr-xr-x 3 root root 4096 Sep 26 17:31 zun

[root@localhost locale]# cd zh_CN
[root@localhost zh_CN]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 12 11:35 LC_MESSAGES
drwxr-xr-x 2 root root 4096 Sep 26 17:35 LC_TIME
[root@localhost zh_CN]#

LC_MESSAGES目錄中是MO (Machine Object) files,可以理解為中文庫文件,示例如下:
[root@localhost zh_CN]# cd LC_MESSAGES/
[root@localhost LC_MESSAGES]# msgunfmt bindconf.mo -o /tmp/ttt.po
[root@localhost LC_MESSAGES]#
[root@localhost LC_MESSAGES]# cat /tmp/ttt.po| more
msgid ""
msgstr ""
"Project-Id-Version: zh_CN\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-09-11 09:59+0800\n"
"PO-Revision-Date: 2005-12-07 11:33+1000\n"
"Last-Translator: \n"
"Language-Team: <zh@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: KBabel 1.9.1\n"

msgid ""
"\n"
"\n"
"\n"
"\n"
"\n"
msgstr ""
"\n"
"\n"
"\n"
"\n"
"\n"

msgid ""
"\n"
" Note that enabling the update forwarding feature on a slave server may "
"expose master servers relying on insecure IP address based access control to "
"attacks."
msgstr ""
"\n"
"請注意,在一個從伺服器上啟用更新轉發功能可能會使那些依賴基於訪問控制的不安全"
"的 IP 地址的主伺服器受到惡意攻擊。"
----more----
定義區域語言的配置文件位置:

[root@localhost ~]# cd /usr/share/i18n/
[root@localhost i18n]# ll
total 32
drwxr-xr-x 2 root root 12288 Sep 26 17:31 charmaps
drwxr-xr-x 2 root root 12288 Sep 26 17:31 locales
[root@localhost i18n]# ll charmaps/GB*
-rw-r--r-- 1 root root 472428 Jan 15 2007 charmaps/GB18030.gz
-rw-r--r-- 1 root root 1603 Jan 15 2007 charmaps/GB_1988-80.gz
-rw-r--r-- 1 root root 44803 Jan 15 2007 charmaps/GB2312.gz
-rw-r--r-- 1 root root 119113 Jan 15 2007 charmaps/GBK.gz

[root@localhost i18n]# ll locales/zh_*
-rw-r--r-- 1 root root 5618 Jan 15 2007 locales/zh_CN
-rw-r--r-- 1 root root 5851 Jan 15 2007 locales/zh_HK
-rw-r--r-- 1 root root 6102 Jan 15 2007 locales/zh_SG
-rw-r--r-- 1 root root 5605 Jan 15 2007 locales/zh_TW
以前還有/usr/share/i18n/repertoiremaps目錄和其中相關的配置文件,現在已經不用。

[root@localhost i18n]# man localedef 用來生成區域設置

修改系統編碼變換設置,告訴系統如何將漢字編碼轉換為系統內部碼:

[root@localhost ~]# locate gconv-modules //查找配置文件位置
/usr/lib/gconv/gconv-modules
/usr/lib/gconv/gconv-modules.cache


XFree86設置:

[root@localhost ~]# locate locale.dir
/usr/share/X11/locale/locale.dir

環境變數的設置:

[root@localhost ~]# echo $LANG //這是我電腦上的配置
en_US.UTF-8

[火星人 ] Redhat中文網頁顯示亂碼的解決已經有1480次圍觀

http://coctec.com/docs/linux/show-post-169177.html