Package: m2translate
# M2Translate localization / translation package### Status[![Build Status](https://travis-ci.org/mdutkin/m2translate.svg?branch=master)](https://travis-ci.org/mdutkin/m2translate)### AboutM2Translate is a package for localization / translation everything you want in your Python projects.You can store all your translations in JSON files or Redis. Once initialised, it sits in a memory untilyou save it to store.The main concept is that you have a bunch of locales, and each of them has it's own set of placeholders.Placeholders are synchronised while dumping to store. Each placeholder has three values: `none`, `single`,`multi`. When you put placeholder somewhere and try to get it's value - you simply get `none` value. But if youspecify a numeric value - you get placeholder value depending on it (`none` for `0`, `single` for `1` and `multi`for `> 1`).### The list of main features:* **supports JSON store and Redis store. You can add support of any store you want by implementing`StoreConnector` interface*** **as fast as your RAM*** **great API offers you methods to modify existing locales and placeholders*** **have nice docs**### How-toInit your connector:```python# jsonconnector = JSONConnector('path/to/your/json_store')# redisredis_host = '127.0.0.1'redis_port = 6379redis_db = 0connector = RedisConnector(redis_host=redis_host, redis_port=redis_port, redis_db=redis_db)```Init core:```pythontr = M2Translate(connector, not_found_val='PH NOT FOUND')```You can clear all your store:```pythontr.clear_store()```First, add locale (you can even dump all you store to synchronize placeholders between locales):```pythontr.add_locale('ru_RU', dump_permanently=False)```Set a few placeholders to the CURRENT LOCALE:```pythontr.set_p('FORM1.NAME', none='Имя')tr.set_p('FORM1.VISITS', none='визитов', single='визит', multi='визитов')# or like that - to a different localetr.set_p('FORM1.VISITS', none='визитов', single='визит', multi='визитов', l='ru_RU')```Add another locale and set it as current:```pythontr.add_locale('en_US', dump_permanently=False)tr.set_cur_locale('en_US')```And also add a value for placeholder:```pythontr.set_p('FORM1.NAME', none='Name')tr.set_p('FORM1.VISITS', none='visits', single='visit', multi='visits')```Save everything you have in RAM to store:```pythontr.dump_locales()```Reload your store in RAM (maybe there are some changes in the remote store?):```pythontr.reload_locales()```Check current locale:```pythonprint(tr.locale)```Or remove useless locale:```pythontr.remove_locale('en_US', dump_permanently=True)```It's time to get our values:```pythonname = input(tr.p('FORM1.NAME'))visits = 10print('%s: %s %s' % (name, visits, tr.p('FORM1.VISITS', visits)))```### ExampleYou can try example in `example/live_example.py`, or take a view at tests.Let's see the example output for `example/live_example.py` in different locales:```bashselect locale from the following list ['ru_RU', 'en_US', 'fr_FR']: ru_RUДля того, чтобы увидеть демку, заполните следующие данныеВаше имя: МаксимВаша фамилия: ДуткинСколько вам лет: 28Отлично, теперь посмотри, что получилось!Спасибо, что ты проявил интерес к этому пакету. Сегодня `четверг,  1 марта 2018 г. 23:57:29` (проверка даты локали), тебя зовут Максим Дуткин и тебе сейчас 28 лет!``````bashselect locale from the following list ['ru_RU', 'en_US', 'fr_FR']: en_USFor demo purposes, fill data belowYour name: MaximYour surname: DutkinHow old are you: 28Awesome, check out the output!Great that you showed interest to this package. Today is `Fri Mar  2 00:13:36 2018` (locale date check), your fullname is Maxim Dutkin and you are 28 years old!``````bashselect locale from the following list ['ru_RU', 'en_US', 'fr_FR']: fr_FRPour des fins de démonstration, remplissez les données ci-dessousVotre nom: MaximVotre nom de famille: DutkinQuel âge avez-vous: 28Génial, consultez la sortie!Génial que vous avez montré de l'intérêt pour ce package. Aujourd'hui est `Ven  2 mar 00:14:45 2018` (vérification de la date locale), votre nom complet est Maxim Dutkin et vous avez 28 ans!``