Raised when there is an error parsing the content of a MO file.
Raised when there is an error parsing the content of a PO file.
Raised when there is an error unescaping a string.
This error is not directly raised by the parsing functions, only is useful when you are calling unescape
.
Parse a PO file by path or content and returns a POFile
object.
Can raise a SyntaxError
if a problem is found parsing the file.
Parse a MO file by path or content and returns a MOFile
object.
Can raise an IOError
if a problem is found parsing the file.
Create a new POFile
object, by default empty.
Returns a copy of the entries of the file.
Sets the entries of the file.
from rspolib import POFile, POEntry
po = POFile()
po.entries = [
POEntry(msgid="Hello", msgstr="Hola"),
POEntry(msgid="Goodbye", msgstr="Adiós"),
]
Returns a copy of the header of the file.
Sets the header of the file.
Returns a copy of the metadata of the file.
Sets the metadata of the file.
Updates the metadata of the file.
The previous metadata fields will be overwritten by the new one.
Removes a metadata field from the file.
Returns whether the metadata is fuzzy.
Sets whether the metadata is fuzzy.
Save the file to a path.
Removes an entry from the file.
Removes an entry from the file by its msgid
.
Removes an entry from the file by its msgid
and msgctxt
.
Appends an entry to the file.
find(value: str, by: str = "msgid", include_obsolete_entries: bool = False, msgctxt: Optional[str] = None) -> List[POEntry]
Finds entries by a given value.
value
: The value to search.by
: The field to search. Can bemsgid
,msgstr
,msgctxt
,msgid_plural
,previous_msgid
,previous_msgid_plural
orprevious_msgctxt
.include_obsolete_entries
: Whether to include obsolete entries in the search.msgctxt
: The context to match against too while searching. Only used whenby
is notmsgctxt
.
If you are doing a search by
msgid
ormsgid
+msgctxt
the functionsfind_by_msgid
andfind_by_msgid_msgctxt
are more efficient.
Finds an entry by its msgid
.
Finds an entry by its msgid
and msgctxt
.
Returns the percentage of translated entries.
Returns a list with copies of the translated entries.
Returns a list with copies of the untranslated entries.
Returns a list with copies of the obsolete entries.
Returns a list with copies of the fuzzy entries.
Returns the number of entries in the file.
Returns whether the file contains an entry.
from rspolib import POFile, POEntry
file = POFile()
entry = POEntry(msgid="Hello", msgstr="Hola")
file.append(entry)
assert entry in file
Returns an entry from the file.
from rspolib import POFile, POEntry
file = POFile()
entry = POEntry(msgid="Hello")
file.append(entry)
assert file[0].msgid == "Hello"
Returns the content of the file as a string.
Returns whether two files are equal or not comparing by their produced contents.
Returns an iterator over the entries of the file.
from rspolib import POFile, POEntry
file = POFile()
file.append(POEntry(msgid="Hello"))
file.append(POEntry(msgid="Goodbye"))
for entry in file:
print(entry.msgid)
Possible magic numbers for MO files.
Indicate that the bytes of the file must be read in little endian (MAGIC
) or big endian byte order (MAGIC_SWAPPED
).
Creates a new MOFile
object, by default empty.
Returns the magic number of the file.
Returns the revision number of the file.
Returns a list with copies of the entries of the file.
Sets the entries of the file.
from rspolib import MOFile, MOEntry
file = MOFile()
file.entries = [
MOEntry(msgid="Hello", msgstr="Hola"),
MOEntry(msgid="Goodbye", msgstr="Adiós"),
]
Returns a copy of the metadata of the file.
Sets the metadata of the file.
Updates the metadata of the file.
The previous metadata fields will be overwritten by the new one.
Removes a metadata field from the file.
Save the file to a path.
Removes an entry from the file.
Removes an entry from the file by its msgid
.
Removes an entry from the file by its msgid
and msgctxt
.
Appends an entry to the file.
find(value: str, by: str = "msgid", include_obsolete_entries: bool = False, msgctxt: Optional[str] = None) -> List[MOEntry]
Finds entries by a given value.
value
: The value to search.by
: The field to search. Can bemsgid
,msgstr
,msgctxt
,msgid_plural
,previous_msgid
,previous_msgid_plural
orprevious_msgctxt
.include_obsolete_entries
: Whether to include obsolete entries in the search.msgctxt
: The context to match against too while searching. Only used whenby
is notmsgctxt
.
If you are doing a search by
msgid
ormsgid
+msgctxt
the functionsfind_by_msgid
andfind_by_msgid_msgctxt
are more efficient.
Finds an entry by its msgid
.
Finds an entry by its msgid
and msgctxt
.
Returns the number of entries in the file.
Returns whether the file contains an entry.
Returns an entry from the file.
Returns the content of the file as a string.
Returns whether two files are equal or not comparing by their produced contents.
Returns an iterator over the entries of the file.
msgid: str = ""
: The singular form of the message.msgstr: Optional[str] = None
: The translation of the message.msgid_plural: Optional[str] = None
: The plural form of the message.msgstr_plural: List[str] = []
: The translations of the plural of the message.msgctxt: Optional[str] = None
: The context of the message.tcomment: Optional[str] = None
: A generated comment for translators.comment: Optional[str] = None
: A generated comment for machines.flags: List[str] = []
: A list of flags.
Returns the line number of the entry in the file.
Returns whether the entry is fuzzy.
Convenient way to check "fuzzy" in entry.flags
.
Returns whether the entry is translated.
Merges the entry with another one.
msgid: str = ""
: The singular form of the message.msgstr: Optional[str] = None
: The translation of the message.msgid_plural: Optional[str] = None
: The plural form of the message.msgstr_plural: List[str] = []
: The translations of the plural of the message.msgctxt: Optional[str] = None
: The context of the message.
Returns whether the entry is translated.
Merges the entry with another one.
Unescapes a PO file string.
Can raise an EscapingError
if one of the next problems is found:
- A escape character is escaping a character that should not be escaped.
- There is an escape character at the end of the string.
Escapes a PO file string.