Skip to main content

Translatable-Enums is a i18n tool which uses built-in Enums as an convenient way to store translation keys.

Project description

Translatable-Enums

Lib logo

GitHub GitHub release (latest by date) PyPI - Downloads Coverage

Translatable-Enums is an i18n tool which uses built-in Enums as a convenient way to store translation keys.

Installation

You can use PIP:

pip install translatable-enums

Or Poetry:

poetry add translatable-enums

Getting-Started

from i18n import (
    TranslatableEnum,
    set_domain,
    set_language
)


class Messages(TranslatableEnum):
    HELLO = 'Hello,'
    WORLD = 'World!'


set_domain('app', './resources/languages')
set_language('en_US')

print(Messages.HELLO, Messages.WORLD)  # Hello, World!

set_language('uk_UA')

print(Messages.HELLO, Messages.WORLD)  # Привіт, Світ!

set_language('fr_FR')

print(Messages.HELLO, Messages.WORLD)  # Bonjour le monde!

print(Messages.HELLO.language('uk'), Messages.WORLD.language('en'))  # Привіт, World!

Extraction-Tools

To extract the translation-keys from application:

python -m i18n main.py application.pot

You will obtain a .pot file like this:

msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: \n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "Hello,"
msgstr ""

msgid "World!"
msgstr ""

Status

0.0.2 - RELEASED

Licence

Translatable-Enums is released under the MIT License. See the bundled LICENSE file for details.

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

translatable_enums-0.0.2.tar.gz (6.1 kB view hashes)

Uploaded Source

Built Distribution

translatable_enums-0.0.2-py3-none-any.whl (9.5 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