{ "info": { "author": "Alexander Oblovatniy", "author_email": "oblovatniy@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Libraries :: Application Frameworks", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "verboselib\n==========\n\n|Build Status| |Coverage Status| |PyPi package| |PyPi downloads|\n\nA little L10N framework for Python libraries and applications.\n\n**Table of contents**\n\n.. contents::\n :local:\n :depth: 1\n :backlinks: none\n\n\nKey points\n----------\n\n``verboselib`` can help you to add verbosity to stand-alone libraries or\napplications. This includes:\n\n- support of usual and lazy translatable messages;\n- support of setting and disabling current active language at runtime for\n current thread globally;\n- tools to help you to update and compile catalogs of translations.\n\nIn short, all this looks like `translation in Django`_, but without Django.\n\n A samurai without a sword is like a samurai with one, but only without one.\n\n\nInstallation\n------------\n\nInstall from `PyPI `_:\n\n.. code-block:: bash\n\n $ pip install verboselib\n\n\nAPI overview\n------------\n\nHere's a quick usage example:\n\n.. code-block:: python\n\n >>> from verboselib import use_language\n >>> from verboselib.factory import TranslationsFactory\n\n >>> translations = TranslationsFactory(domain=\"example\", locale_dir=\"locale\")\n >>> _ = translations.ugettext_lazy\n\n >>> message = _(\"Hi there!\")\n >>> use_language('en')\n >>> print(message)\n 'Hi there!'\n >>> use_language('sv')\n >>> print(message)\n 'Hej d\u00e4r!'\n\n\nTranslationsFactory\n^^^^^^^^^^^^^^^^^^^\n\nThe key point here is usage of an instance of a ``TranslationsFactory`` class\ncalled ``translations``. You need to use its methods to make translatable\nmessages. This is done to make sure your translations are really initialized,\nthat they are initialized only once and stored in a single place only.\n\n **TIP**: instantiate ``TranslationsFactory`` at some convenient place\n (e.g. top-level ``__init__.py``, ``utils.py``, ``translations.py`` or any\n other place you like). Then you will be able to import that instance from\n any other module, e.g.:\n\n .. code-block:: python\n\n from .utils import translations\n\nTo create an instance of a ``TranslationsFactory`` class you need to tell a\n``domain`` name and path to directory, where your translation catalogs are\nstored (``locale_dir``).\n\n **TIP**: to keep things simple you can\n\n 1. set domain name same as the name of your library, application or just\n a package;\n 2. place ``locale_dir`` at the top level of your package;\n\n..\n\n **STRONG RECOMMENDATION**: tell the absolute path of your ``locale_dir``\n while instantiating your translations. This is especially vital if you are\n going to distribute a public library. Example:\n\n .. code-block:: python\n\n # Example '__init__.py'\n\n import os\n from verboselib.factory import TranslationsFactory\n\n\n here = os.path.abspath(os.path.dirname(__file__))\n locale_dir = os.path.join(here, \"locale\")\n translations = TranslationsFactory(\"example\", locale_dir)\n\nSo, you want to get your translated messages. There some way to do that. List\nof currently supported methods includes:\n\n- ``gettext`` - get a localized translation of message, based on the global\n language in current thread;\n- ``ugettext`` - same as ``gettext``, but returns translated message as a\n Unicode string (equal to ``gettext`` for Python 3);\n- ``gettext_lazy`` - get a lazy translation of message, will be evaluated in\n future accordingly to the global language in current thread;\n- ``ugettext_lazy`` same as ``gettext_lazy``, but returns evaluated message as a\n Unicode string (equal to ``gettext_lazy`` for Python 3);\n\n..\n\n **TIP**: Don't be afraid to use different aliases for different translation\n methods, e.g.:\n\n .. code-block:: python\n\n from .utils import translations\n\n _, U_ = translations.gettext, translations.ugettext\n L_, UL_ = translations.gettext_lazy, translations.ugettext_lazy\n\n\nSetting and getting default language\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nIf you are developing some application, it makes sence to specify a **global**\ndefault language. This language will be used if current language is not\nspecified. Example:\n\n.. code-block:: python\n\n from verboselib import set_default_language, get_default_language\n\n get_default_language() # ==> 'None'\n set_default_language('en')\n get_default_language() # ==> 'en'\n\n..\n\n **TIP**: set default language somewhere near the place you instantiate the\n ``TranslationsFactory`` class at.\n\nIf both current and default languages are not set, original messages will be\nreturned instead of their translations.\n\n\nSetting up current language\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nYou can set up current **global** language for current thread from any place:\n\n.. code-block:: python\n\n from verboselib import use_language\n\n use_language('fr')\n\n\nQuerying current language\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\nYou can get the value of currently used language:\n\n.. code-block:: python\n\n from verboselib import get_language\n\n get_language()\n\nIf current value is ``None``, this means that neither current nor default\nlanguage is set and original messages will be returned.\n\n\nClearing current language\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\nYou can clear the value of current **global** language, so next translations\nwill use default language:\n\n.. code-block:: python\n\n from verboselib import drop_language\n\n drop_language()\n\n..\n\n **TIP**: sometimes it makes sence to restore previous language instead of\n dropping it, e.g.:\n\n .. code-block:: python\n\n from verboselib import get_language, use_language\n from .utils import translations\n\n _ = translations.ugettext\n\n\n def send_greeting_email(user):\n saved = get_language()\n use_language(user.language)\n\n subject = _(\"Welcome to our service\")\n message = _(\"Hello, {:}! Glad to see you among our users!\").format(user.first_name)\n\n use_language(saved)\n send_email(subject, message, user.email)\n\n\nDisabling translations\n^^^^^^^^^^^^^^^^^^^^^^\n\nIf you wish, you can totally disable translations, so original messages will be\nused:\n\n.. code-block:: python\n\n from verboselib import use_language_bypass\n\n use_language_bypass()\n\nAfter this ``get_language`` function will return ``None``.\n\nUse ``use_language`` to enable translations again.\n\n\nLocale-to-language conversions\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n``verboselib`` comes up with a couple of hepler function for converting language\nto locale:\n\n.. code-block:: python\n\n >>> from verboselib.heplers import to_locale\n >>> to_locale('en-us')\n 'en_US'\n >>> to_locale('en-us', to_lower=True)\n 'en_us'\n\nand vice versa, for converting locale to language:\n\n.. code-block:: python\n\n >>> from verboselib.heplers import to_language\n >>> to_language('en_US')\n 'en-us'\n\n\nManaging catalogs of translations\n---------------------------------\n\n``verboselib`` comes up with management script called ``verboselib-manage``.\nIts purpose is to help you to extract translatable messages from your sources\nand to compile catalogs of translations.\n\n.. code-block::\n\n $ verboselib-manage\n Execute management commands for verboselib.\n Available commands:\n\n - compile (compile '*.po' files into '*.mo' binaries).\n - extract (extract 'gettext' strings from sources).\n - help (list available commands or show help for a particular command).\n - version (show current version of verboselib).\n\n..\n\n **TIP**: You can use management script even if you are not going to use\n ``verboselib`` itself. It can make your life a bit easier anyway.\n\nAs you can see, there are 4 currently available commands.\n\n\nGetting help\n^^^^^^^^^^^^\n\nUse ``help`` to get commands list or to show help for some command, e.g.:\n\n.. code-block::\n\n $ verboselib-manage help help\n usage: help [COMMAND]\n\n List available commands or show help for a particular command.\n\n\nExtracting messages\n^^^^^^^^^^^^^^^^^^^\n\n``extract`` command will help you to extract or update your messages:\n\n.. code-block::\n\n $ verboselib-manage help extract\n usage: extract [-d DOMAIN] [-l LOCALE] [-a] [-o OUTPUT_DIR] [-k KEYWORD]\n [-e EXTENSIONS] [-s] [-i PATTERN] [--no-default-ignore]\n [--no-wrap] [--no-location] [--no-obsolete] [--keep-pot] [-v]\n\n Extract 'gettext' strings from sources.\n\n optional arguments:\n -d DOMAIN, --domain DOMAIN\n The domain of the message files (default: \"messages\").\n -l LOCALE, --locale LOCALE\n Create or update the message files for the given\n locale(s) (e.g. en_US). Can be used multiple times.\n -a, --all Update the message files for all existing locales\n (default: false).\n -o OUTPUT_DIR, --output-dir OUTPUT_DIR\n Path to the directory where locales will be stored,\n a.k.a. 'locale dir' (default: \"locale\").\n -k KEYWORD, --keyword KEYWORD\n Look for KEYWORD as an additional keyword (e.g., L_).\n Can be used multiple times.\n -e EXTENSIONS, --extension EXTENSIONS\n The file extension(s) to examine. Separate multiple\n extensions with commas, or use multiple times.\n -s, --symlinks Follows symlinks to directories when examining sources\n for translation strings (default: false).\n -i PATTERN, --ignore PATTERN\n Ignore files or directories matching this glob-style\n pattern. Use multiple times to ignore more.\n --no-default-ignore Don't ignore the common glob-style patterns 'CVS',\n '.*', '*~', '*.pyc' (default: false).\n --no-wrap Don't break long message lines into several lines.\n (default: false).\n --no-location Don't write '#: filename:line' lines (default: false).\n --no-obsolete Remove obsolete message strings (default: false).\n --keep-pot Keep .pot file after making messages. Useful when\n debugging (default: false).\n -v, --verbose Use verbose output (default: false).\n\nHelp output is quite comprehensive. First 5 options are considered to be used\nmost often.\n\nIf you had no translations before, you will need to specify target ``locale``\n(or their list) to create translation files for:\n\n.. code-block:: bash\n\n $ verboselib-manage extract --locale 'uk' -l 'en' -l 'it'\n\nIf you want just to update all existing files, you may use ``--all`` argument.\n\nDefault keywords to look for are: ``gettext``, ``gettext_lazy``, ``ugettext``,\n``ugettext_lazy`` and ``_``. Use ``--keyword`` (``-k``) argument to add extra\nkeyword, e.g.:\n\n.. code-block:: bash\n\n $ verboselib-manage extract --keyword 'L_' -k 'U_' -k 'UL_'\n\n\nCompiling translation catalogs\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nUse ``compile`` command to compile all translation files inside a single\n``locale dir``:\n\n.. code-block::\n\n $ verboselib-manage help compile\n usage: compile [-l LOCALE] [-d LOCALE_DIR]\n\n Compile '*.po' files into '*.mo' binaries.\n\n optional arguments:\n -l LOCALE, --locale LOCALE\n Locale(s) to process (e.g. en_US). Default is to\n process all. Can be used multiple times.\n -d LOCALE_DIR, --locale-dir LOCALE_DIR\n Path to the directory where locales are stored\n (default: \"locale\").\n\n..\n\n **Just for information**:\n `locale `_\n directory for tests was built using management script.\n\n\nChangelog\n---------\n\n* `0.2.1`_ (Jul 16, 2017)\n\n * Fix ``version`` command.\n * Rename ``verboselib-manage.py`` executable to simply ``verboselib-manage``.\n\n* `0.2.0`_ (Dec 31, 2014)\n\n * Add ``get_default_language()`` method.\n * Use default translation classes from ``gettext`` module.\n\n* `0.1.0`_ (Jul 17, 2014)\n\n Initial version\n\n\nCredits\n-------\n\nCreation of this library was inspired by ``translations`` package from `Django`_\nand ``locale`` module from `Sphinx`_.\n\nSome blocks of code were taken from Django and adopted for general-purpose\nusage. Links to original sources are included into docstrings.\n\nI would like to thank `3noch`_ for accepting my proposed changes for\n`stringlike`_ library which provides support of lazy strings for ``verboselib``.\n\n\nFuture plans and thoughts\n-------------------------\n\n- This library is in alpha state currently, because ``lgettext``, ``ngettext``,\n ``lngettext``, ``ungettext``, ``dgettext`` and other nice methods are not\n implemented now. This is a nice point to start work on the next version from.\n- Currently ``verboselib`` supports global language for current thread only.\n Seems, it would be good if support of global language for the whole process\n will be implemented.\n- Though support for merging translation catalogs is already implemented,\n ``TranslationsFactory`` accepts only one domain now. Maybe multiple domains is\n a nice feature to implement too. Same thing about ``locale_dir``.\n\n.. |Build Status| image:: http://img.shields.io/travis/oblalex/verboselib.svg?style=flat&branch=master\n :target: https://travis-ci.org/oblalex/verboselib\n.. |Coverage Status| image:: http://img.shields.io/coveralls/oblalex/verboselib.svg?style=flat&branch=master\n :target: https://coveralls.io/r/oblalex/verboselib?branch=master\n.. |PyPi package| image:: http://img.shields.io/pypi/v/verboselib.svg?style=flat\n :target: http://badge.fury.io/py/verboselib/\n.. |PyPi downloads| image:: http://img.shields.io/pypi/dm/verboselib.svg?style=flat\n :target: https://crate.io/packages/verboselib/\n\n.. _translation in Django: https://docs.djangoproject.com/en/1.7/topics/i18n/translation/\n\n.. _0.2.1: https://github.com/oblalex/verboselib/releases/tag/v0.2.0...v0.2.1\n.. _0.2.0: https://github.com/oblalex/verboselib/releases/tag/v0.1.0...v0.2.0\n.. _0.1.0: https://github.com/oblalex/verboselib/releases/tag/v0.1.0\n\n.. _Django: https://www.djangoproject.com/\n.. _Sphinx: http://sphinx-doc.org/\n\n.. _3noch: https://github.com/3noch\n.. _stringlike: https://pypi.python.org/pypi/stringlike\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/oblalex/verboselib", "keywords": "library", "license": "LGPLv3", "maintainer": "", "maintainer_email": "", "name": "verboselib", "package_url": "https://pypi.org/project/verboselib/", "platform": "any", "project_url": "https://pypi.org/project/verboselib/", "project_urls": { "Homepage": "https://github.com/oblalex/verboselib" }, "release_url": "https://pypi.org/project/verboselib/0.2.1/", "requires_dist": null, "requires_python": "", "summary": "A little L10N framework for libraries and applications", "version": "0.2.1" }, "last_serial": 3026970, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "980621aa1841a0e9a0d27279f91ae2b2", "sha256": "21ac2ad35ad910a789ae9ad6a202f66e4f73af0b5b1088907c72ca6f84413325" }, "downloads": -1, "filename": "verboselib-0.1.0.tar.gz", "has_sig": false, "md5_digest": "980621aa1841a0e9a0d27279f91ae2b2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18009, "upload_time": "2014-07-17T07:40:23", "url": "https://files.pythonhosted.org/packages/3e/4d/48c100383b5230274906538265d9ab36d32f9253d838a89bbd51a801daae/verboselib-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "d24361d1414ff00eafdbcc38b1b0384f", "sha256": "cac16dca9ac01c2d1b4107a9b56e6ab4828b99eca8d87fb003a165524659dbb1" }, "downloads": -1, "filename": "verboselib-0.2.0.tar.gz", "has_sig": false, "md5_digest": "d24361d1414ff00eafdbcc38b1b0384f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18165, "upload_time": "2014-12-31T21:05:38", "url": "https://files.pythonhosted.org/packages/4c/16/578858c06746a5aab6f6b71ad77f7ac776032bb6ae97ac585e6bac55aa32/verboselib-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "b3666b86f96f76376bc421437a79bb1d", "sha256": "fd3f752064c17703a232a22674d4d989e8ebde817d817de881474f0d52fff41f" }, "downloads": -1, "filename": "verboselib-0.2.1.tar.gz", "has_sig": false, "md5_digest": "b3666b86f96f76376bc421437a79bb1d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22356, "upload_time": "2017-07-16T18:07:00", "url": "https://files.pythonhosted.org/packages/8c/12/1e70412325eb564e24af5c0717be4cd95d7499c051777e7facf2b3c57fd8/verboselib-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b3666b86f96f76376bc421437a79bb1d", "sha256": "fd3f752064c17703a232a22674d4d989e8ebde817d817de881474f0d52fff41f" }, "downloads": -1, "filename": "verboselib-0.2.1.tar.gz", "has_sig": false, "md5_digest": "b3666b86f96f76376bc421437a79bb1d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22356, "upload_time": "2017-07-16T18:07:00", "url": "https://files.pythonhosted.org/packages/8c/12/1e70412325eb564e24af5c0717be4cd95d7499c051777e7facf2b3c57fd8/verboselib-0.2.1.tar.gz" } ] }