AIX语言包与编码转换
AIX上语言包及编码转换
查看已经安装的语言包:
# locale -a
C
POSIX
ZH_CN
ZH_CN.UTF-8
en_US
en_US.8859-15
en_US.ISO8859-1
zh_CN
zh_CN.IBM-eucCN
查看当前的设置:
# locale
LANG=zh_CN
LC_COLLATE= "zh_CN "
LC_CTYPE= "zh_CN "
LC_MONETARY= "zh_CN "
LC_NUMERIC= "zh_CN "
LC_TIME= "zh_CN "
LC_MESSAGES=zh_CN
LC_ALL=zh_CN
修改设置:
# export LC_ALL=ZH_CN.UTF-8
查看修改后的设置:
# locale
LANG=zh_CN
LC_COLLATE= "ZH_CN.UTF-8 "
LC_CTYPE= "ZH_CN.UTF-8 "
LC_MONETARY= "ZH_CN.UTF-8 "
LC_NUMERIC= "ZH_CN.UTF-8 "
LC_TIME= "ZH_CN.UTF-8 "
LC_MESSAGES= "ZH_CN.UTF-8 "
LC_ALL=ZH_CN.UTF-8
export LC_ALL=ZH_CN.UTF-8
export LANG=ZH_CN.UTF-8
结果是一样的。因为LC_ALL是优先级最高的,改不改LANG没有什么影响
AIX上安装语言包
1. 将AIX系统盘的第一张光盘放入光驱;
2. 运行命令:
smitty
--> System Environments
--> Manage Languange Environment
--> Add Addinational Languange Environments
在随后显示的菜单中将光标分别移到以下字段,按F4进行选择(选择 .... (zh_CN)相应语言):
CULTURAL Convention to Install
LANGUAGE translation to install
在光驱中放入介质,回车就可以了。
LANGUAGE translation to install
GB18030 S-Chinese (GB18030) [Zh_CN]
UTF-8 Chinese (Simplified UTF) [ZH_CN]
编码转换例程:
#include
#include
#include
#include
using namespace std;
#define MAXBUFLEN 512
// 代码转换操作类
class CodeConverter {
private:
iconv_t cd;
public:
// 构造函数
CodeConverter(const char *from_charset,const char *to_charset) {
cd = iconv_open(to_charset,from_charset);
}
// 析构函数
~CodeConverter() {
iconv_close(cd);
}
// 缓冲区数据转换输出
int Convert(char *inbuf,int inlen,char *outbuf,int outlen) {
int lri_ret;
char **pin = &inbuf;
char **pout = &outbuf;
memset(outbuf,0,outlen);
return iconv(cd,pin,(size_t *)&inlen,pout,(size_t *)&outlen);
}
// 文件转换输出
int ConvertFile(char *infile, char *outfile) {
FILE *rfp;
FILE *wfp;
char inBuf[MAXBUFLEN];
char outBuf[MAXBUFLEN*4];