Skip to main content

Python package for i18n implementation and locales generation

Project description

i18n-generator-logo

i18n Generator, a powerful library to easily internationalize projects

License: GPL v3 Build Tests PyPI version Coverage Status Downloads

What is it ?

i18n-generator is a Python package that provides a fast way to internationalize your app, based on your native language. Translation is done using these technologies depending of language classification :

For the rarest languages and by default if one service is not available : Google Translate

Where to get it ?

The source code is currently hosted on GitHub at: https://github.com/LPauzies/i18n-generator

Binary installers for the latest released version are available at the Python Package Index (PyPI).

pip install i18n-generator

How to use it

i18n-generator generates the translation from a native language to a list of other languages. To use it, you will need a main.json file that is containing a json document

Command line

Help

python -m i18ngenerator -h

Version

python -m i18ngenerator -v

Using configuration file

python -m i18ngenerator --config config.yaml

With config.yaml :

main-file: ~/main.json # Path to main file
from-language: fr # Should always be a short locale
to-language: # Should be a list of short locale
- en
- zh
- ru
- pt

You can find the list of i18n locales here. For France for example, the short locale would be "fr". For China, the short locale would be "zh".

Using CLI arguments

# Example of use with CLI arguments
python -m i18ngenerator --main-file main.json --from-language fr --to-language es,zh,en

With main.json as main json file containing values to translate from french (fr) to spanish, chinese and english (es,zh,en)

Python package

From JSON file

from i18ngenerator.i18ngenerator import I18nGenerator
from i18ngenerator.languages import Language
import pathlib

# Using json file
json_file = pathlib.Path("path/to/main.json")
from_language = Language.ENGLISH
to_language = [
    Language.FRENCH,
    Language.CHINESE
]

i18n_generator = I18nGenerator()
i18n_generator.generate_translation_from_json(json_file, from_language, to_language)

From Python dict

from i18ngenerator.i18ngenerator import I18nGenerator
from i18ngenerator.languages import Language

# Using dict object
json_dict = {"dummy_key_1": "Hello", "dummy_key_2": "I am Lucas ! I am 24 years old."}
from_language = Language.ENGLISH
to_language = Language.FRENCH

i18n_generator = I18nGenerator()
result = i18n_generator.generate_translation_from_dict(json_dict, from_language, to_language)
print(result)
>>> {"dummy_key_1": "Bonjour", "dummy_key_2": "Je suis Lucas! J'ai 24 ans."}

Just for translation

from i18ngenerator.translator import Translator
from i18ngenerator.languages import Language

text = "Bonjour, je suis Lucas."
from_language = Language.FRENCH
to_language = Language.ENGLISH
translated_text = Translator.translate_text(text, from_language, to_language)
print(translated_text)
>>> "Hello, I am Lucas."

Dependencies

Build from sources

Download the sources : here

python setup.py install

License

GPLv3

How to contribute ?

Open Source Helpers

All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.

FAQ & Troubleshooting

  • Which languages can I use ?

You can consider using these lines of code to see which languages are supported by i18n-generator

from i18ngenerator.languages import Language

print(list(Language))
>>> [<Language.ENGLISH: 'en'>, <Language.CHINESE: 'zh'>, <Language.FRENCH: 'fr'>, ...]
  • Why is it sometimes slow to generate my translated files ?

This package is based on translators which is a free package and free to use. It is using Google translate API to make translation and sometimes, it is not instantly generated. The algorithm providing the translation then need to wait a bit for the translation.

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

i18n-generator-1.2.1.tar.gz (23.2 kB view hashes)

Uploaded Source

Built Distribution

i18n_generator-1.2.1-py3-none-any.whl (25.3 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