Pofile to JSON conversion without pain.
Project description
📦 potojson
Pofile to JSON conversion without pain.
Installation
pip install potojson
Documentation
API
# pofile_to_json(content, fallback_to_msgid=False, fuzzy=False, pretty=False, indent=2, language=None, plural_forms=None) ⇒ str
Converts a pofile passed as string or filepath and returns a JSON formatted output with next style:
{
"": {
"language": "es",
"plural-forms": "nplurals=2; plural=n != 1;",
},
"msgid": "msgstr",
"msgctxt": {
"msgid": "msgstr",
},
"msgid": ["msgstr[0]", "msgstr[1]", "msgstr[2]"],
"msgctxt": {
"msgid": ["msgstr[0]", "msgstr[1]", "msgstr[2]"],
}
}
This output can be customized tuning the parameters of the function.
- content (str) Content or filepath of the pofile to convert.
- fallback_to_msgid (bool) Use msgid if translation is missing.
- fuzzy (bool) Include fuzzy messages.
- pretty (bool) Pretty-print JSON output.
- indent (int) Number of spaces for indentation used pretty-printing JSON output. Only takes effect if
pretty is True
. - language (str) Language for the translations. Will be inserted in the empty key of the JSON output. If not provided and the passed pofile includes the "Language" header, will be extrated from it.
- plural_forms (str) Plural forms for the language of the translations. Will be insertedin the empty key of the JSON output. If not provided and the passed pofile includes the "Plural-Forms" header, will be extrated from it.
CLI
usage: potojson [-h] [-v] [-m] [-f] [-p] [-i N] [-l LANGUAGE] [-s PLURAL_FORMS] PO_FILEPATH_OR_CONTENT
Pofile to JSON conversion without pain.
positional arguments:
PO_FILEPATH_OR_CONTENT
Path to pofile or pofile content as a string. If not provided, will be read from STDIN.
optional arguments:
-h, --help show this help message and exit
-v, --version Show program version number and exit.
-m, --fallback-to-msgid
Use msgid if translation is missing.
-f, --fuzzy Include fuzzy messages.
-p, --pretty Pretty-print JSON output.
-i N, --indent N Number of spaces for indentation used pretty-printing JSON output. Only takes effect passing '--fuzzy' option.
-l LANGUAGE, --language LANGUAGE
Language for the translations. Will be inserted in the empty key of the JSON output. If not provided and the passed pofile includes the "Language" header, will be extrated from it.
-s PLURAL_FORMS, --plural-forms PLURAL_FORMS
Plural forms for the language of the translations. Will be insertedin the empty key of the JSON output. If not provided and the passed pofile includes the "Plural-Forms" header, will be extrated from it.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
potojson-0.0.2.tar.gz
(6.2 kB
view hashes)
Built Distribution
Close
Hashes for potojson-0.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f98d8badec3f738d53239c41b213f6f3b9b6487bdfffa883fbfbc8c46357f53 |
|
MD5 | 813582982fcf3ac1456c257ddc998000 |
|
BLAKE2b-256 | 8b4f5a42a222094cce6b83278582cb33d95d06f029504994277aa933d4a18c7f |