Skip to main content

String localization tests

Project description

localizationkit

localizationkit is a toolkit for ensuring that your localized strings are the best that they can be.

Included are tests for various things such as:

  • Checking that all strings have comments
  • Checking that the comments don't just match the value
  • Check that tokens have position specifiers
  • Check that no invalid tokens are included

with lots more to come.

Getting started

Configuration

To use the library, first off, create a configuration file that is in the TOML format. Here's an example:

default_language = "en"

[has_comments]
minimum_comment_length = 25
minimum_comment_words = 8

[token_matching]
allow_missing_defaults = true

[token_position_identifiers]
always = false

This configuration file sets that en is the default language (so this is the language that will be checked for comments, etc. and all tests will run relative to it). Then it sets various settings for each test. Every instance of [something_here] specifies that the following settings are for that test. For example, the test has_comments will now make sure that not only are there comments, but that they are at least 25 characters in length and 8 words in length.

You can now load in your configuration:

from localizationkit import Configuration

configuration = Configuration.from_file("/path/to/config.toml")

Localization Collections

Now we need to prepare the strings that will go in. Here's how you can create an individual string:

from localizationkit import LocalizedString

my_string = LocalizedString("My string's key", "My string's value", "My strings comment", "en")

This creates a single string with a key, value and comment, with its language code set to en. Once you've created some more (usually for different languages too), you can bundle them into a collection:

from localizationkit import LocalizedCollection

collection = LocalizedCollection(list_of_my_strings)

Running the tests

At this point, you are ready to run the tests:

import localizationkit

results = localizationkit.run_tests(configuration, collection)

for result in results:
    if not result.succeeded():
        print("The following test failed:", result.name)
        print("Failures encountered:")
        for violation in result.violations:
            print(violation)

Not running the tests

Some tests don't make sense for everyone. To skip a test you can add the following to your config file at the root:

blacklist = ["test_identifier_1", "test_identifier_2"]

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

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

localizationkit-0.1.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

localizationkit-0.1.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file localizationkit-0.1.0.tar.gz.

File metadata

  • Download URL: localizationkit-0.1.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Darwin/18.7.0

File hashes

Hashes for localizationkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4a6210ce6716a461a1da83504a7e176ba7af7552be8e8bb8ab1c14470eeedaf7
MD5 4b32e3f905fdcaa2627166859c4db64b
BLAKE2b-256 b311ff7466c9ca434a173c9f830de5cfd9e05b9efd6aaec863445db5f04ac41d

See more details on using hashes here.

File details

Details for the file localizationkit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: localizationkit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Darwin/18.7.0

File hashes

Hashes for localizationkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3d1dfc9640e976fa6bdd283b44a8ea676c9aa121941cd41100c73a5ff373aa7
MD5 a6cc829723003ede4ee2f57716bceb44
BLAKE2b-256 0fbe8bf20c4f4a4d06f88ea2b0a83e31a4bea0304abdeebcab3804c2a3c4410d

See more details on using hashes here.

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