Unicode到8位字符集音译编解码器
translitcodec的Python项目详细描述
此软件包包含用于将ISO 10646文本翻译为 使用较小的编码字符集(ascii, ISO 8859等)。编解码器使用的翻译表来自 markus kuhn的transtab集合。
提供三种类型的音译编解码器:
- “long”, using as many characters as needed to make a natural
- replacement. For example, u00e4 LATIN SMALL LETTER A WITH DIAERESIS ^{tt2}$ will be replaced with ^{tt3}$.
“short”, using the minimum number of characters to make a replacement. For example, u00e4 LATIN SMALL LETTER A WITH DIAERESIS ^{tt2}$ will be replaced with ^{tt5}$.
“one”, only performing single character replacements. Characters that can not be transliterated with a single character are passed through unchanged. For example, u2639 WHITE FROWNING FACE ^{tt6}$ will be passed through unchanged.
使用编解码器很简单:
>>> import translitcodec >>> import codecs >>> codecs.encode(u'fácil € ☺', 'translit/long') u'facil EUR :-)' >>> codecs.encode(u'fácil € ☺', 'translit/short') u'facil E :-)'
默认情况下,编解码器返回Unicode。要接收回bytestring, 将encode()的输出链接到另一个编解码器,或附加 所需字节编码到编解码器名称的名称:
>>> codecs.encode(u'fácil € ☺', 'translit/one').encode('ascii', 'replace') 'facil E ?' >>> u'fácil € ☺'.encode('translit/one/ascii', 'replace') 'facil E ?'
该包还提供了一个“音译”编解码器,一个 “translit/long”。
Translitcodec更改
0.4
2015年5月11日发布
- 增加了python 3兼容性
0.3
2011年2月14日发布
- 修复了transtab表重建工具。
- 添加了Translitcodec。uuu版本
0.2
2011年1月27日发布
- 解决“typeerror:字符映射必须返回整数, “无”或“Unicode”,当为空值时(例如:n{zero width space}u200b) 是编码的。Unicode空白现在返回。
- 翻译中不再包含ascii范围内的字符 桌子。
0.1
2008年12月28日发布
- 初始打包发布。