### Status
[](https://travis-ci.org/mdutkin/m2translate)
### About
M2Translate 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 until
you 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 you
specify 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-to
Init your connector:
```python
# json
connector = JSONConnector('path/to/your/json_store')
# redis
redis_host = '127.0.0.1'
redis_port = 6379
redis_db = 0
connector = RedisConnector(redis_host=redis_host, redis_port=redis_port, redis_db=redis_db)
```
Init core:
```python
tr = M2Translate(connector, not_found_val='PH NOT FOUND')
```
You can clear all your store:
```python
tr.clear_store()
```
First, add locale (you can even dump all you store to synchronize placeholders between locales):
```python
tr.add_locale('ru_RU', dump_permanently=False)
```
Set a few placeholders to the CURRENT LOCALE:
```python
tr.set_p('FORM1.NAME', none='Имя')
tr.set_p('FORM1.VISITS', none='визитов', single='визит', multi='визитов')
# or like that - to a different locale
tr.set_p('FORM1.VISITS', none='визитов', single='визит', multi='визитов', l='ru_RU')
```
Add another locale and set it as current:
```python
tr.add_locale('en_US', dump_permanently=False)
tr.set_cur_locale('en_US')
```
And also add a value for placeholder:
```python
tr.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:
```python
tr.dump_locales()
```
Reload your store in RAM (maybe there are some changes in the remote store?):
```python
tr.reload_locales()
```
Check current locale:
```python
print(tr.locale)
```
Or remove useless locale:
```python
tr.remove_locale('en_US', dump_permanently=True)
```
It's time to get our values:
```python
name = input(tr.p('FORM1.NAME'))
visits = 10
print('%s: %s %s' % (name, visits, tr.p('FORM1.VISITS', visits)))
```
### Example
You 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:
```bash
select locale from the following list ['ru_RU', 'en_US', 'fr_FR']: ru_RU
Для того, чтобы увидеть демку, заполните следующие данные
Ваше имя: Максим
Ваша фамилия: Дуткин
Сколько вам лет: 28
Отлично, теперь посмотри, что получилось!
Спасибо, что ты проявил интерес к этому пакету. Сегодня `четверг, 1 марта 2018 г. 23:57:29` (проверка даты локали), тебя зовут Максим Дуткин и тебе сейчас 28 лет!
```
```bash
select locale from the following list ['ru_RU', 'en_US', 'fr_FR']: en_US
For demo purposes, fill data below
Your name: Maxim
Your surname: Dutkin
How old are you: 28
Awesome, 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!
```
```bash
select locale from the following list ['ru_RU', 'en_US', 'fr_FR']: fr_FR
Pour des fins de démonstration, remplissez les données ci-dessous
Votre nom: Maxim
Votre nom de famille: Dutkin
Quel âge avez-vous: 28
Gé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!
``
Metadata
Release files for m2translate 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| m2translate-1.0.3.tar.gz | 7.9 kB | Without provenance | Details for m2translate-1.0.3.tar.gz |
Release files / m2translate-1.0.3.tar.gz
| Download URL | m2translate-1.0.3.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10b1c21b78ce72d0848288dbd7866603fd6a4b9dcffc1bcb68d220e788adaab1
|
|
BLAKE2b-256 checksum How to use checksums |
3ef2291d7032f22cfda92552ef67f19bdb78374f0d1157518e955a0befb721ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for m2translate 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.