{ "info": { "author": "Erkan Durmus", "author_email": "derkan@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Flask-Locale\n=================\n\nImplements i18n and l10n support for Flask. This is based on the old [Flask-Locale](http://github.com/whtsky/whtsky-locale/) extension. Uses files or database to get translations.\n\nYou can use this extension to translate your applications really easily. No babel preperation is needed. Just put your English text and its translation in a file.\n\nInstall\n-------\n\n pip install Flask-Locale\n\n\nQuick Start\n-----------\n\n- Py3 ready\n- For very quick test look at `demo` directory.\n\n- Create a directory `translations` at app root. \n- Create file `translations/tr_TR.csv` with this content:\n\n\n \"Hello %(name)s\",\"Merhaba %(name)s\"\n \n \"Hello\",\"Merhaba\"\n\n- Create `templates` directory at app root.\n\n- Create `locale.html` file with this content:\n\n>>>\n \n \n \n \n Flask-Locale\n \n \n

Translate with parameters in template

\n {{ _('Hello %(name)s', name=name) }}\n
\n

Translated in Python Code:

\n {{ py_translated }}\n \n \n\n-- Create your application main file `demo.py`:\n\n>>>\n # -*- coding: utf-8 -*- \n from flask import Flask, request, render_template, g\n from flask_locale import Locale, _ \n app = Flask(__name__)\n app.config['LOCALE_PATH'] = 'translations' \n locale = Locale(app) \n @locale.localeselector\n def get_locale():\n # if a user is logged in, use the locale from the user settings \n user = getattr(g, 'user', None)\n if user is not None:\n return user.locale\n # otherwise try to guess the language from the user accept\n # header the browser transmits. We support tr/fr/en in this\n # example. The best match wins.\n return request.accept_languages.best_match(['tr_TR', 'fr_FR', 'en_US'])\n @app.route(\"/\")\n def index():\n # How we do translation in python code:\n py_translated = _('Hello')\n # How we do translation in template:\n return render_template('locale.html', name='Erkan', \n py_translated=py_translated)\n if __name__ == '__main__':\n app.run(debug=True)\n\n- Run your app:\n\n>>> python demo.py\n\n\n- Now access your app: `http://127.0.0.1:5000/`\n\nUsage\n-----\n\n**Loading translations from a file:**\n\nLoads translations from CSV files having locale extension in a directory. File should be `utf-8` encoded.\n\nTranslations are strings with optional Python-style named placeholders (e.g., ``\"My name is %(name)s\"``) and their associated translations.\n\nThe directory should have translation files of the form filename: LOCALE, e.g. tr_TR. \n\nTranslation files should have two or three columns: string, translation, and an optional plural indicator. Plural indicators should be one of ``\"plural\"`` or ``\"singular\"``. \n\nA given string can have both singular and plural forms. For example ``\"%(name)s liked this\"`` may have a different verb conjugation depending on whether %(name)s is one name or a list of names. There should be two rows in the CSV file for that string, one with plural indicator \"singular\", and one \"plural\".\n\nFor strings with no verbs that would change on translation, simply\nuse ``\"unknown\"`` or the empty string (or don't include the column at all).\n\nThe file is read using the csv module in the default \"excel\" dialect.\nIn this format there should not be spaces after the commas.\n\nExample translation tr_TR.csv:\n\n>>>\n \"I love you\",\"Seni seviyorum\"\n \"%(name)s liked these\",\"A %(name)s bunlar\u0131 sevdi\",\"plural\"\n \"%(name)s liked this\",\"A %(name)s bunu sevdi\",\"singular\"\n\n\n**Loading translations from database:**\n\n\n>>>\n @locale.db_loader\n def get_translations():\n \"\"\"Translations selector for db\"\"\"\n sql = select(\n [Locale.c.code, TranslationKey.c.name, Translation.c.translated, Translation.c.singular],\n from_obj=[Locale.join(Translation).join(TranslationKey)])\n q = db.session.execute(sql)\n data = q.fetchall()\n q.close()\n return list(data)\n\n\n**Reloading translations**\n\nWhen user's locale is changed, call `refresh()` method:\n\n>>>\n user.locale = request.form['locale']\n locale.refresh()\n flash(_('Language is changed'))\n\n**Translate Functions**\n\n`translate()` (or its alias `_()`) method does a lazy translation, that means its actual translate function is called when you access it. So you can use translate functions in your forms before Flask-Locale is initialized.\n\n\n>>>\n from flask.ext.wtf import Form\n from wtforms.fields import TextField, PasswordField\n from wtforms.validators import Required, Email\n from extensions import _ \n class EmailPasswordForm(Form):\n email = TextField(_('Email'), validators=[Required(), Email()])\n password = PasswordField(_('Password'), validators=[Required()])\n\n\nIf you want immediate translation, use `do_translate` method.\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/derkan/flask-locale", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "Flask-Locale", "package_url": "https://pypi.org/project/Flask-Locale/", "platform": "any", "project_url": "https://pypi.org/project/Flask-Locale/", "project_urls": { "Homepage": "http://github.com/derkan/flask-locale" }, "release_url": "https://pypi.org/project/Flask-Locale/1.0.4/", "requires_dist": null, "requires_python": "", "summary": "Adds i18n/l10n support to Flask applications easily. Uses CSV files(or database) to load translations.", "version": "1.0.4" }, "last_serial": 4006224, "releases": { "0.2": [ { "comment_text": "", "digests": { "md5": "005f2c8540c91f5392489eb219e5c0e1", "sha256": "ee147d3659cb33f77a4c07a46eec9b887bac56beea7cacb26d0b709ecf3f4142" }, "downloads": -1, "filename": "Flask-Locale-0.2.tar.gz", "has_sig": false, "md5_digest": "005f2c8540c91f5392489eb219e5c0e1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4830, "upload_time": "2015-10-09T14:46:47", "url": "https://files.pythonhosted.org/packages/01/02/2d93e5b19912320db5bb822b38aafb5e1e90c9a17603f6fba133003c312f/Flask-Locale-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "fc6541808be1ec0120a9253e2a125830", "sha256": "545826ea7a10c04b6fc239c60c6820fb5e5b7cd42e7767a78fb9c8fc10bd0fe0" }, "downloads": -1, "filename": "Flask-Locale-0.3.tar.gz", "has_sig": false, "md5_digest": "fc6541808be1ec0120a9253e2a125830", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4846, "upload_time": "2015-10-09T14:56:41", "url": "https://files.pythonhosted.org/packages/71/90/220310a00334fe3921d039037a09b4ca6c768412fd72dd4f3f42ecf06739/Flask-Locale-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "c194fcfa0402f69c868139025505967b", "sha256": "d59fc24e0abf06f8477d62d04f470077174b2465cb2bd07bb17b43def089bde2" }, "downloads": -1, "filename": "Flask-Locale-0.4.tar.gz", "has_sig": false, "md5_digest": "c194fcfa0402f69c868139025505967b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4859, "upload_time": "2015-10-15T10:45:35", "url": "https://files.pythonhosted.org/packages/5d/d8/ea80995c35542a78c5a66de64fee8c4a5556e8fd19a1ac3bdf0cb5ae8108/Flask-Locale-0.4.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "15f4a05ed6eeeedb34035b13c1204970", "sha256": "8dd6a06ebf67a3588d626ea7ea2ca64d17bbb3b4487ea3b794ddfb1a7790ea69" }, "downloads": -1, "filename": "Flask-Locale-0.4.1.tar.gz", "has_sig": false, "md5_digest": "15f4a05ed6eeeedb34035b13c1204970", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4867, "upload_time": "2015-10-15T11:09:26", "url": "https://files.pythonhosted.org/packages/17/6f/a3d401be6ae967439417ad2d4caa458ed0c22cda248dc501d90ffa52f194/Flask-Locale-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "52184766b820ea691f1ab909ac96a269", "sha256": "13c3cfb97e920d636a96c224f2509fb524312265cef6b45896fa851422c1cdb2" }, "downloads": -1, "filename": "Flask-Locale-0.4.2.tar.gz", "has_sig": false, "md5_digest": "52184766b820ea691f1ab909ac96a269", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4915, "upload_time": "2015-12-14T07:39:21", "url": "https://files.pythonhosted.org/packages/41/79/4a4be404777c5c00bef630a25a1310d7c580e8f0ade40e32c2b0f7340f03/Flask-Locale-0.4.2.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "a1ca5f0fbd0e85339c2d21c64eaa0dbe", "sha256": "ee9d290967785de8ab374577365fb67e3b60abc78195e921aa11f50ddc046b23" }, "downloads": -1, "filename": "Flask-Locale-1.0.0.tar.gz", "has_sig": false, "md5_digest": "a1ca5f0fbd0e85339c2d21c64eaa0dbe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4944, "upload_time": "2016-09-16T12:33:05", "url": "https://files.pythonhosted.org/packages/0f/00/f03b61ff3171b0c264fa8e9d97f458715a10c7e3d408182625a47fd63be7/Flask-Locale-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "0023d84cb12790d9514390b529d4e528", "sha256": "9eacbdfe5b16e06f9caf0f6db1215867dfaaaa799c378a6e4193553fed082224" }, "downloads": -1, "filename": "Flask-Locale-1.0.1.tar.gz", "has_sig": false, "md5_digest": "0023d84cb12790d9514390b529d4e528", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6515, "upload_time": "2016-09-16T12:36:20", "url": "https://files.pythonhosted.org/packages/f9/f8/d4b8d871dfed3b3be4b12c2e3cb2c656ae4f6befc4bada343d7decc84323/Flask-Locale-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "b6acb79511658df69ead13c458f1ab55", "sha256": "ff40a546fa8be1e7a40e492260ce6510be2774eeaff3a7693eb2431c0a1d2a66" }, "downloads": -1, "filename": "Flask-Locale-1.0.2.tar.gz", "has_sig": false, "md5_digest": "b6acb79511658df69ead13c458f1ab55", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7036, "upload_time": "2016-09-16T12:46:49", "url": "https://files.pythonhosted.org/packages/ed/07/e648b03de49a75f06d306162c65b4aa1bb0bd8c6d49e29b636ad3c2aeb05/Flask-Locale-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "0847427eac75d67ef0b2528896a8eed5", "sha256": "8ad857b776172bed447e0d618918fcca66491bb6f8d403932bcb40faf2df0fea" }, "downloads": -1, "filename": "Flask-Locale-1.0.3.tar.gz", "has_sig": false, "md5_digest": "0847427eac75d67ef0b2528896a8eed5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7052, "upload_time": "2018-02-26T09:10:10", "url": "https://files.pythonhosted.org/packages/13/fa/b03e908e1e1025a99cf7a058226b7978efa6cc385870fa736d8b019fd14c/Flask-Locale-1.0.3.tar.gz" } ], "1.0.4": [ { "comment_text": "", "digests": { "md5": "5670db5a73f0dbd5eee349e9c866fa01", "sha256": "85e943e80eb692eed16f6a79ca3c49129e1bf976050ffed8c340b8c39e0fb117" }, "downloads": -1, "filename": "Flask-Locale-1.0.4.tar.gz", "has_sig": false, "md5_digest": "5670db5a73f0dbd5eee349e9c866fa01", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7048, "upload_time": "2018-06-27T07:09:17", "url": "https://files.pythonhosted.org/packages/4c/6b/c9956d78351786fb2ac860683ebf3cf58f4e2967e4e752fc8d56aaed2a9c/Flask-Locale-1.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5670db5a73f0dbd5eee349e9c866fa01", "sha256": "85e943e80eb692eed16f6a79ca3c49129e1bf976050ffed8c340b8c39e0fb117" }, "downloads": -1, "filename": "Flask-Locale-1.0.4.tar.gz", "has_sig": false, "md5_digest": "5670db5a73f0dbd5eee349e9c866fa01", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7048, "upload_time": "2018-06-27T07:09:17", "url": "https://files.pythonhosted.org/packages/4c/6b/c9956d78351786fb2ac860683ebf3cf58f4e2967e4e752fc8d56aaed2a9c/Flask-Locale-1.0.4.tar.gz" } ] }