读取和写入Mac OS X .strings文件
项目描述
这是什么?
这是一个用于操作Mac OS X/iOS .strings文件的Python代码包,它被精心编写以支持您可能希望使用的所有字符转义和Unicode字符。
如何使用它?
要读取(strings文件
>>> from nslocalized import StringTable >>> st = StringTable.read('/path/to/my/Localized.strings')
或将字符串读入现有的StringTable
>>> st.read('/path/to/my/other/Localized.strings')
要写入新的(strings文件
>>> st.write('/path/to/my/new/Localized.strings')
默认情况下,它使用主机端序UTF-16,但您可以指定编码
>>> st.write('/path/to/my/new/Localized.strings', encoding='utf_8')
每个字符串都由一个LocalizedString对象表示;给定字符串文件
/* My important string */ "Very important" = "Très important";
在StringTable st
>>> ls = st.lookup('Very important') >>> print ls.source Very important >>> print ls.target Très important >>> print ls.comment My important string
您还可以使用以下方法向StringTable添加条目
>>> st.store(LocalizedString('One', 'Uno'))
或添加注释
>>> st.store(LocalizedString('MB', 'Mo', 'Megabytes'))
最后,为了简单访问,您可以使用[]运算符
>>> st['GB'] = 'Go' >>> print st['MB'] Mo
在某些情况下,您可能希望在不处理转义的情况下加载字符串表。在这种情况下,您可以这样做
>>> st = StringTable.read('/path/to/my/Localized.strings', process_escapes=False)
这将读取表而不进行任何转义处理。显然,如果您以这种形式读取表,您也将希望不进行转义而写入它
>>> st.write('/path/to/my/new/Localized.strings', escape_strings=False)
项目详情
关闭
nslocalized-0.2.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 46d6f776b26e9da0e0d0c759d99782884882cade59d5c935005a85cba654db9e |
|
MD5 | c61c7dd8819ca2aaedf72b5b7de9560b |
|
BLAKE2b-256 | 77b7610c101e59810d9d54d5308df8531ca401528a2d9cd3014e26d01b7be9e5 |