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 details)

Uploaded Source

Built Distribution

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

i18n_generator-1.2.1-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file i18n-generator-1.2.1.tar.gz.

File metadata

  • Download URL: i18n-generator-1.2.1.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for i18n-generator-1.2.1.tar.gz
Algorithm Hash digest
SHA256 050d9dd468323982e9d466d1b919a700d7fc314fe4fcac3f520e6c5d5dad26cf
MD5 f400323ee3f54c50f46a30a465368248
BLAKE2b-256 8234208d2c5a0e1fa9e01f7e4a13b71b8add30b8c8b63cc249a5cc3a3118f6e9

See more details on using hashes here.

File details

Details for the file i18n_generator-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: i18n_generator-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for i18n_generator-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5ffdfaeed5f1a3bf133fae4f31a40747d375cea265da25721885a7000c5f45d8
MD5 e4692be683b2ec742577aafc0806c1c2
BLAKE2b-256 91bef5bc27dd28b40014a2d4b666445e569c507ce7c6ab49920d116e11c1ca24

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