Skip to main content

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.

Release files for i18n-generator 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for i18n-generator 1.2.1
File Size Uploaded
i18n-generator-1.2.1.tar.gz 23.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for i18n-generator 1.2.1
File Interpreter ABI Platform
i18n_generator-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 48.6 kB

Release files / i18n-generator-1.2.1.tar.gz

Download URL i18n-generator-1.2.1.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
050d9dd468323982e9d466d1b919a700d7fc314fe4fcac3f520e6c5d5dad26cf
BLAKE2b-256 checksum
How to use checksums
8234208d2c5a0e1fa9e01f7e4a13b71b8add30b8c8b63cc249a5cc3a3118f6e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / i18n_generator-1.2.1-py3-none-any.whl

Download URL i18n_generator-1.2.1-py3-none-any.whl
Size 25.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ffdfaeed5f1a3bf133fae4f31a40747d375cea265da25721885a7000c5f45d8
BLAKE2b-256 checksum
How to use checksums
91bef5bc27dd28b40014a2d4b666445e569c507ce7c6ab49920d116e11c1ca24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page