读取和写入mac os x.strings文件
nslocalized的Python项目详细描述
这是什么?
这是一个用于操作mac os x/ios.strings文件的python代码包, 为了支持所有的角色逃逸和 您可能希望使用的Unicode字符。
我怎么用?
要读取.strings文件:
>>> from nslocalized import StringTable >>> st = StringTable.read('/path/to/my/Localized.strings')
或将字符串读入现有的^ {tt1} $:
>>> 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";
在StringTablest:
>>> ls = st.lookup('Very important') >>> print ls.source Very important >>> print ls.target Très important >>> print ls.comment My important string
您还可以使用:
>>> 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)