Skip to main content

Pofile to JSON conversion without pain.

Project description

📦 potojson

PyPI Python versions Tests coveralls-badge-link

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, as_dict=False) ⇒ str

Converts a pofile passed as string or filepath and returns a JSON formatted output. Given this pofile:

#

#, fuzzy
msgid ""
msgstr ""
"Language: es\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"

msgid "msgid"
msgstr "msgstr"

msgctxt "msgctxt"
msgid "msgid"
msgstr "msgstr"

msgid "msgid"
msgid_plural "msgid_plural"
msgstr[0] "msgstr[0]"
msgstr[1] "msgstr[1]"

msgctxt "msgctxt"
msgid "msgid"
msgid_plural "msgid_plural"
msgstr[0] "msgstr[0]"
msgstr[1] "msgstr[1]"

... the output will be:

{
  "": {
    "language": "es",
    "plural-forms": "nplurals=2; plural=n != 1;",
  },
  "msgid": "msgstr",
  "msgctxt": {
    "msgid": "msgstr",
  },
  "msgid": ["msgstr[0]", "msgstr[1]"],
  "msgctxt": {
    "msgid": ["msgstr[0]", "msgstr[1]"],
  }
}

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 extracted from it.
  • plural_forms (str) Plural forms for the language of the translations. Will be inserted in the empty key of the JSON output. If not provided and the passed pofile includes the "Plural-Forms" header, will be extracted from it.
  • as_dict (bool) Returns the output as a Python dictionary.
  • sort_keys (bool) Sort dictionary by key. Combined with as_dict parameter, returns an instance of :py:class:collections.OrderedDict.

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 extracted from it.
  -s PLURAL_FORMS, --plural-forms PLURAL_FORMS
                        Plural forms for the language of the translations. Will be inserted in the empty key of the JSON output. If not provided and the passed pofile includes the "Plural-Forms" header, will be extracted from it.
  -k, --sort-keys       Sort JSON output by key.

Project details


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.13.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

potojson-0.0.13-py2.py3-none-any.whl (7.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file potojson-0.0.13.tar.gz.

File metadata

  • Download URL: potojson-0.0.13.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.5

File hashes

Hashes for potojson-0.0.13.tar.gz
Algorithm Hash digest
SHA256 60e26c9a9f4fedf0c5a8eb3ee528b5d71a12a9d13ca93329dcfd976230c813ad
MD5 8e6ad4ffe7e28ae709db9e666710b913
BLAKE2b-256 3e683938d897267c7be215fd0c47fce7d5ff5f02a0283a76342df5994c2656a7

See more details on using hashes here.

File details

Details for the file potojson-0.0.13-py2.py3-none-any.whl.

File metadata

  • Download URL: potojson-0.0.13-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.5

File hashes

Hashes for potojson-0.0.13-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 84f9238486dd07e965e542c6cf1406adb3171290a21663d6d541fcb00318cd8a
MD5 049c86988c65654dd30c83f912f109c9
BLAKE2b-256 6baa118bbcef9b61dde4aef0c19d1ad3258dd84a73e03bcf0ddbd7ea04767ad7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page