Skip to main content

prop-tool: Java *.properties file sync checker and syncing tool.

Project description

prop-tool

prop-tool - Java *.properties file checker and syncing tool.

This utility can be used to check if translation files stay in sync with base file. It can also create translation files adding missing keys based on the content of base file.

$ proptool -b mark -l pl -v
Base: mark.properties
  Found 6 errors in "mark_pl.properties":
    Trailing white characters: 3
      W: line 2: In comment: 2
      E: line 4: In "question" entry: 1
      E: line 5: In "exclamation" entry: 1
    Punctuation mismatch: 3
      E: line 2: "question" ends with " ". Expected "?".
      E: line 3: "exclamation" ends with " ". Expected "!".
      E: line 4: "newline" ends with "". Expected "\n".

Based on *.properties file format docs.

Installation

You can install prop-tool from PyPi:

pip install prop-tool

Alternatively, you can download *.whl archive and install it manually by issuing:

pip install --upgrade <FILE>.whl

You may also want to setup virtual environment first.

Validation

The main purpose of prop-tool is to ensure all property files are correct and that translation files are in sync with the reference file. For that reason you need to have at least two *.properties files to use prop-tool. One is your base language (usually English texts) used as reference and all the others are your translations. Translation file is in sync with base when:

  1. All keys present in base file are also present in translation file.
  2. There's no dangling keys (not existing in base) present in translation file.
  3. Trailing punctuation marks of translation match base strings.

NOTE: as this is quite common that translation file may not be updated instantly, prop-tool considers key presence condition fulfilled also when given key exists in B file but is commented out and follow expected comment format:

# ==> KEY =

Default format can changed using --tpl argument.

If you want to ensure that all keys are in fact translated, use --strict mode while checking. When running with --strict option, keys in commented out form are ignored.

Fixing files

You can use prop-tool to update your translation files by using --fix option. In such case prop-tool will completely rewrite translation files, adding missing keys (in commented out form).

NOTE: Be aware that --fix do NOT update existing translation file but builds it completely using base file as reference and existing translations (if present). No other content of translation files (for example additional comments etc) will be preserved.

Usage examples

Check if de translation of test.properties exists and is in sync:

prop-tool --base test.properties --lang de

You can omit .properties suffix in command line argument. NOTE: that file name must contain .properties suffix, otherwise it will not be found:

prop-tool --base test --lang de

it will then look for test_de.properties file in the same folder test.properties resides and check it.


Check if de, pl and fr translations of test.properties and gui.properties exist and are in sync:

prop-tool --base test gui --lang de pl fr

it will then look for and validate following files

test_de.properties
test_pl.properties
test_fr.properties
gui_de.properties
gui_pl.properties
gui_fr.properties

Check if es translation of gui.properties is in sync and if there are any missing keys, rewrite translation file to contain all keys from base:

prop-tool --base gui --lang es --fix

Check if pt translation of gui.properties is in sync and if there are any missing keys, rewrite translation file to contain all keys from base using own comment format:

prop-tool --base gui --lang es --fix --tpl "COM >~=-> KEY SEP"

Limitations

  • As of now prop-tool do not handle multiline entries.

License

  • Written and copyrighted ©2021 by Marcin Orlowski <mail (#) marcinorlowski (.) com>
  • prop-tool is open-sourced software licensed under the MIT license

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

prop-tool-1.1.0.tar.gz (10.3 kB view hashes)

Uploaded Source

Built Distribution

prop_tool-1.1.0-py3-none-any.whl (18.6 kB view hashes)

Uploaded Python 3

Supported by

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