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 :
- Koreanic : Papago
- Chinese : Iflytek
- Japonic : Iciba
- Latin : Bing
- German : Bing
- Cyrillic : Google Translate
For the rarest languages and by default if one service is not available : Google Translate
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
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
python -m i18ngenerator -h
python -m i18ngenerator -v
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".
# 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)
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 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."}
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."
- translators - Translators is a library which aims to bring free, multiple, enjoyable translation
- nltk - The Natural Language Toolkit (NLTK) is a Python package for natural language processing
- pyyaml - YAML parser and emitter for Python
Download the sources : here
python setup.py install
All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.
- 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.