gnu po文件的分析器
pop的Python项目详细描述
gnu po文件的分析器
安装
使用pip安装:
pip install popy
用法
使用popy分析po文件:
from popy.po_file import PoFile f = PoFile(path='/path/to/your/file.po') messages = f.get_messages() # gets all the messages messages[0] # MessageEntry object messages[0].msgid # First message's msgid messages[1].msgstr # Second message's msgstr as a list
MessageEntry对象
这些是属性:
msgid: str msgstr: list of strings msgid_plural: str msgctxt: str translator_comments: list of strings extracted_comments: list of strings references: list of strings flags: list of strings is_fuzzy: boolean
这些是重要的方法:
fix_newline_matching() # Adds or removes newlines to/from msgstr in order to match msgid and msgstr newlines at the beginning or end. __str__() # Generates a message block
pofile对象
这些是属性:
path: str messages: list of MessageEntry objects
这些是重要的方法:
get_messages() # Reads messages and returns list of MessageEntry objects write_messages() # Writes MessageEntry objects into the file fix_newline_matching() # Applys fix_newline_matching to the whole file __str__() # Generates a message block