跳转到主要内容

读取和写入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 (6.1 kB 查看哈希值)

上传时间

由以下支持