{ "info": { "author": "Maxim Dutkin", "author_email": "max@dutkin.ru", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Topic :: Software Development :: Localization" ], "description": "# M2Translate localization / translation package\n\n### Status\n\n[![Build Status](https://travis-ci.org/mdutkin/m2translate.svg?branch=master)](https://travis-ci.org/mdutkin/m2translate)\n\n\n### About\n\n\nM2Translate is a package for localization / translation everything you want in your Python projects. \nYou can store all your translations in JSON files or Redis. Once initialised, it sits in a memory until \nyou save it to store.\n\nThe main concept is that you have a bunch of locales, and each of them has it's own set of placeholders. \nPlaceholders are synchronised while dumping to store. Each placeholder has three values: `none`, `single`, \n`multi`. When you put placeholder somewhere and try to get it's value - you simply get `none` value. But if you \nspecify a numeric value - you get placeholder value depending on it (`none` for `0`, `single` for `1` and `multi` \nfor `> 1`).\n\n\n### The list of main features:\n\n* **supports JSON store and Redis store. You can add support of any store you want by implementing \n`StoreConnector` interface**\n\n* **as fast as your RAM**\n\n* **great API offers you methods to modify existing locales and placeholders**\n\n* **have nice docs**\n\n\n### How-to\n\nInit your connector:\n\n```python\n# json\nconnector = JSONConnector('path/to/your/json_store')\n\n# redis\nredis_host = '127.0.0.1'\nredis_port = 6379\nredis_db = 0\nconnector = RedisConnector(redis_host=redis_host, redis_port=redis_port, redis_db=redis_db)\n```\n\nInit core:\n\n```python\ntr = M2Translate(connector, not_found_val='PH NOT FOUND')\n```\n\nYou can clear all your store:\n\n```python\ntr.clear_store()\n```\n\nFirst, add locale (you can even dump all you store to synchronize placeholders between locales):\n\n```python\ntr.add_locale('ru_RU', dump_permanently=False)\n```\n\nSet a few placeholders to the CURRENT LOCALE:\n\n```python\ntr.set_p('FORM1.NAME', none='\u0418\u043c\u044f')\ntr.set_p('FORM1.VISITS', none='\u0432\u0438\u0437\u0438\u0442\u043e\u0432', single='\u0432\u0438\u0437\u0438\u0442', multi='\u0432\u0438\u0437\u0438\u0442\u043e\u0432')\n# or like that - to a different locale\ntr.set_p('FORM1.VISITS', none='\u0432\u0438\u0437\u0438\u0442\u043e\u0432', single='\u0432\u0438\u0437\u0438\u0442', multi='\u0432\u0438\u0437\u0438\u0442\u043e\u0432', l='ru_RU')\n```\n\nAdd another locale and set it as current:\n\n```python\ntr.add_locale('en_US', dump_permanently=False)\ntr.set_cur_locale('en_US')\n```\n\nAnd also add a value for placeholder:\n\n```python\ntr.set_p('FORM1.NAME', none='Name')\ntr.set_p('FORM1.VISITS', none='visits', single='visit', multi='visits')\n```\n\nSave everything you have in RAM to store:\n\n```python\ntr.dump_locales()\n```\n\nReload your store in RAM (maybe there are some changes in the remote store?):\n\n```python\ntr.reload_locales()\n```\n\nCheck current locale:\n\n```python\nprint(tr.locale)\n```\n\nOr remove useless locale:\n\n```python\ntr.remove_locale('en_US', dump_permanently=True)\n```\n\nIt's time to get our values:\n\n```python\nname = input(tr.p('FORM1.NAME'))\nvisits = 10\nprint('%s: %s %s' % (name, visits, tr.p('FORM1.VISITS', visits)))\n```\n\n### Example\n\nYou can try example in `example/live_example.py`, or take a view at tests.\n\nLet's see the example output for `example/live_example.py` in different locales:\n\n```bash\nselect locale from the following list ['ru_RU', 'en_US', 'fr_FR']: ru_RU\n\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0434\u0435\u043c\u043a\u0443, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\n\u0412\u0430\u0448\u0435 \u0438\u043c\u044f: \u041c\u0430\u043a\u0441\u0438\u043c\n\u0412\u0430\u0448\u0430 \u0444\u0430\u043c\u0438\u043b\u0438\u044f: \u0414\u0443\u0442\u043a\u0438\u043d\n\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u043c \u043b\u0435\u0442: 28\n\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c!\n\u0421\u043f\u0430\u0441\u0438\u0431\u043e, \u0447\u0442\u043e \u0442\u044b \u043f\u0440\u043e\u044f\u0432\u0438\u043b \u0438\u043d\u0442\u0435\u0440\u0435\u0441 \u043a \u044d\u0442\u043e\u043c\u0443 \u043f\u0430\u043a\u0435\u0442\u0443. \u0421\u0435\u0433\u043e\u0434\u043d\u044f `\u0447\u0435\u0442\u0432\u0435\u0440\u0433, 1 \u043c\u0430\u0440\u0442\u0430 2018 \u0433. 23:57:29` (\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0434\u0430\u0442\u044b \u043b\u043e\u043a\u0430\u043b\u0438), \u0442\u0435\u0431\u044f \u0437\u043e\u0432\u0443\u0442 \u041c\u0430\u043a\u0441\u0438\u043c \u0414\u0443\u0442\u043a\u0438\u043d \u0438 \u0442\u0435\u0431\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 28 \u043b\u0435\u0442!\n```\n\n```bash\nselect locale from the following list ['ru_RU', 'en_US', 'fr_FR']: en_US\nFor demo purposes, fill data below\nYour name: Maxim\nYour surname: Dutkin\nHow old are you: 28\nAwesome, check out the output!\nGreat 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!\n```\n\n```bash\nselect locale from the following list ['ru_RU', 'en_US', 'fr_FR']: fr_FR\nPour des fins de d\u00e9monstration, remplissez les donn\u00e9es ci-dessous\nVotre nom: Maxim\nVotre nom de famille: Dutkin\nQuel \u00e2ge avez-vous: 28\nG\u00e9nial, consultez la sortie!\nG\u00e9nial que vous avez montr\u00e9 de l'int\u00e9r\u00eat pour ce package. Aujourd'hui est `Ven 2 mar 00:14:45 2018` (v\u00e9rification de la date locale), votre nom complet est Maxim Dutkin et vous avez 28 ans!\n``", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mdutkin/m2translate", "keywords": "", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "m2translate", "package_url": "https://pypi.org/project/m2translate/", "platform": "", "project_url": "https://pypi.org/project/m2translate/", "project_urls": { "Homepage": "https://github.com/mdutkin/m2translate" }, "release_url": "https://pypi.org/project/m2translate/1.0.3/", "requires_dist": null, "requires_python": "", "summary": "M2Translate localization / translation package", "version": "1.0.3" }, "last_serial": 3633384, "releases": { "1.0.3": [ { "comment_text": "", "digests": { "md5": "bba78c1ae5bbca6bcaa51bd6dbc63711", "sha256": "10b1c21b78ce72d0848288dbd7866603fd6a4b9dcffc1bcb68d220e788adaab1" }, "downloads": -1, "filename": "m2translate-1.0.3.tar.gz", "has_sig": false, "md5_digest": "bba78c1ae5bbca6bcaa51bd6dbc63711", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7949, "upload_time": "2018-03-02T23:33:52", "url": "https://files.pythonhosted.org/packages/3e/f2/291d7032f22cfda92552ef67f19bdb78374f0d1157518e955a0befb721ea/m2translate-1.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bba78c1ae5bbca6bcaa51bd6dbc63711", "sha256": "10b1c21b78ce72d0848288dbd7866603fd6a4b9dcffc1bcb68d220e788adaab1" }, "downloads": -1, "filename": "m2translate-1.0.3.tar.gz", "has_sig": false, "md5_digest": "bba78c1ae5bbca6bcaa51bd6dbc63711", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7949, "upload_time": "2018-03-02T23:33:52", "url": "https://files.pythonhosted.org/packages/3e/f2/291d7032f22cfda92552ef67f19bdb78374f0d1157518e955a0befb721ea/m2translate-1.0.3.tar.gz" } ] }