国际化 i18n native2ascii

之前在很多地方都能见到I18N,特别是open source里面。

I18N就是Internationalization的缩写,其原因是I和n之间一共有18个字母(寒~)。

下面这些地方会需要I18N

  • Displaying characters for the users' native languages.
  • Inputing characters for the users' native languages.
  • Handling files written in popular encodings that are used for the users' native languages.
  • Using characters from the users' native languages for file names and other items.
  • Printing out characters from the users' native languages.
  • Displaying messages by the program in the users' native languages.
  • Formatting input and output of numbers, dates, money, etc., in a way that obeys customs of the users' native cultures.
  • Classifying and sorting characters, in a way that obey customs of the users' native cultures.
  • Using typesetting and hyphenation rules appropriate for the users' native languages.

当然除了I18N还有L10N(localization) 和M17N (multilingualization),这3个之间有什么区别呢,举例说明。

L10N支持2种语言,英文和另外一种语言(例如中文);

I18N支持多种语言,但是同一时间只能是英文和一种选定的语言,例如英文+中文、英文+德文、英文+韩文等等;

M17N可以在同一时间支持多种语言,例如你可以在一个页面里看到中文、英文、德文和韩文。



B:将zh.txt转换为Unicode编码,输出到控制台
C:\test>native2ascii zh.txt
\u7194\u5ca9
可以看到,控制台输出了“\u7194\u5ca9”。

C:将zh.txt转换为ISO8859-1编码,输出文件到i.txt
native2ascii -encoding ISO8859-1 zh.txt i.txt
打开i.txt文件,内容为“\u00c8\u00db\u00d1\u00d2”。

D:将u.txt转换为本地编码,输出到文件u_nv.txt
native2ascii -reverse u.txt u_nv.txt
打开u_nv.txt文件,内容为“熔岩”。


E:将u.txt转换为本地编码,输出到控制台

C:\test>native2ascii -reverse u.txt
熔岩
可以看到,控制台输出了“熔岩”。


F:将i.txt转换为本地编码,输出到i_nv.txt
native2ascii -reverse i.txt i_nv.txt
打开i_nv.txt文件,内容为“\u00c8\u00db\u00d1\u00d2”。发现转码前后完全一样的。也就是说,等于没有转,或者说思想糊涂,对命名没有理解。


G:将i.txt转换为GBK编码,输出到i_gbk.txt
native2ascii -reverse -encoding GBK i.txt i_gbk.txt
打开i_gbk.txt文件,内容为“\u00c8\u00db\u00d1\u00d2”。发现转码前后完全一样的。也就是说,等于没有转,或者说思想糊涂,对命名没有理解。


H:将u_nv.txt转码到本地编码GBK,输出到控制台
C:\test>native2ascii -reverse -encoding ISO8859-1 i.txt
熔岩
从这个结果看,目标达到到了,编码i.txt为ISO8859-1,转为本地编码后内容为“熔岩”。从这里应该意识到,native2ascii -reverse命令中-encoding指定的编码为源文件的编码格式。而在native2ascii 命令中-encoding指定的编码为(生成的)目标文件的编码格式。这一点非常的重要!切记!!

继续探索,新建文件12a.txt,内容“12axyz”。看看纯字母数字的编码又如何。


I:将纯字母数字的文本文件12a.txt转换为Unicode编码

native2ascii 12a.txt 12a_nv.txt
打开12a_nv.txt文件,内容为“12axyz”。
继续测试,转为ISO8859-1编码看看

native2ascii 12a.txt 12a_nv.txt
打开12a_nv.txt文件,内容为“12axyz”。
继续测试,转为ISO8859-1编码看看
C:\test>native2ascii -encoding ISO8859-1 12a.txt
12axyz
结果还是没有转码。从结果可以得出结论:对于纯数字和字母的文本类型文件(只有ASCII码),转码前后的内容是一样的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值