{ "info": { "author": "Antonio Cuni", "author_email": "anto.cuni@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Internationalization" ], "description": "=============================\ni18n - Translations made easy\n=============================\n\nThis package tries to simplify the workflow and development of\ninternationalized applications. It is a thin wrapper around existing tools, in\nparticular gettext_ and babel_.\n\n.. _gettext: http://docs.python.org/library/gettext.html\n.. _babel: http://babel.edgewall.org/\n\n\nBasic usage\n===========\n\n::\n\n # demo.py\n #\n from i18n.translator import Translator\n supported_languages = ['it_IT', 'fr_FR', 'de_DE']\n # activate italian translations\n tr = Translator('/path/to/root', supported_languages, 'it_IT')\n print tr._('Hello world!')\n\nwhere ``/path/to/root/`` is the root directory of your project. When\ninstantiated, the ``Translator`` class automatically creates a directory\ncalled ``/path/to/root/languages`` where the translations are stored.\n\nExtracting messages\n===================\n\nBefore doing the actual translation, you need to **extract** the messages from\nyour source files, by invoking the ``extract`` command on the ``i18n`` module,\nwhich is a wrapper around ``pybabel extract`` and ``pybabel update``::\n\n $ python -m i18n --root=/path/to/root --languages=it_IT,fr_FR,de_DE extract\n\n``extract`` looks for all the messages wrapped inside calls to ``_()``,\n``gettext()`` or ``ngettext()`` and produces a file called\n``languages/template.pot``. This is a standard `gettext po file`` which\ncontains all the messages found in the application.\n\nMoreover, ``extract()`` also creates a **message catalog** file for each of\nthe supported languages as ``languages/$CODE/LC_MESSAGES/messages.po``, where\n``$CODE`` is one of the languages listed in ``supported_languages`` (it_IT,\nfr_FR and de_DE in the example above).\n\nThe catalog files are now ready to be translated using one of the many\nexisting tools, for example `QT Linguist`_ or Poedit_. For the correct\nfunctioning of the application, the entire ``languages/`` hierarchy needs to\nbe preserved. We suggest to track the various ``messages.po`` files in Version\nControl System together with the other files belonging to the application.\n\n.. _`QT Linguist`: http://qt.nokia.com/products/developer-tools?currentflipperobject=cf2f1a5149cecc583f8f2733206343ca#qt-tools-at-a\n.. _Poedit: http://www.poedit.net/\n\n\nUpdating messages\n=================\n\nDuring the development of the application, you will surely add new messages to\nbe translated. The ``extract`` command automatically handle this case: if it\nfinds existing catalog files, their content (including the existing\ntranslations) is merged with the newly extracted messages.\n\n\nCompiling catalogs\n==================\n\nIt is necessary to compile the catalog files before using them with\ngettext. By default, our ``Translator`` object automatically compiles all the\ncatalogs found in ``languages/``, producing the corresponding ``.mo``\nfiles. The compilation is done only when the catalog file has been modified.\nThis means that in most cases you do not have to worry about the compilation\nof the catalogs.\n\nIf you prefer to have more control on this step, you can pass\n``autocompile=False`` to the constructor of ``Translator`` and compile them\nmanually from the command line::\n\n $ python -m i18n --root=/path/to/root --languages=it_IT,fr_FR,de_DE compile\n\n\n\nStoring translations in a database\n==================================\n\nFor some applications it is useful to let the user to define new translations\nand/or override the default ones. ``i18n`` supports this use case with the\n``DBTranslator`` class, which is a subclass of ``Translator``. When\ntranslating, ``DBTranslator`` first looks in the database: if the message is\nnot found, it delegates to the standard gettext behavior.\n\n``DBTranslator`` is based on sqlalchemy_. Its constructor takes an additional\n``engine`` parameter::\n\n from i18n.dbtranslator import DBTranslator\n from sqlalchemy import create_engine\n\n engine = create_engine('sqlite:///db.sqlite')\n ROOT = '/path/to/root'\n LANGUAGES = ['it_IT', 'fr_FR']\n DEST_LANGUAGE = 'it_IT'\n tr = DBTranslator(ROOT, LANGUAGES, DEST_LANGUAGE, engine=engine)\n print tr._(\"hello world\")\n\n``DBTranslator`` automatically creates the table ``translation_entries`` in\nthe DB. Then, it is up to the application to provide an user interface to\nmanipulate the table. For testing, you can use the ``add_translation()``\nmethod to insert a new translation in the DB::\n\n tr.add_translation(\"it_IT\", \"hello world\", \"ciao mondo\")\n print tr._(\"hello world\") # prints \"ciao mondo\"\n\n\n.. _sqlalchemy: http://www.sqlalchemy.org/\n\nHow to use a global Translator\n==============================\n\nBy design, ``i18n`` tries to completely avoid any global state. This means\nthat you can instantiate as many ``Translator`` and ``DBTranslator`` as you\nwant, each one referring to a different directory and/or database. This is\nespecially useful for testing.\n\nHowever, in practice most projects want to use a global translator which knows\nabout the messages of all the components in the project. The demo application\nshows a way to do it in the ``translate.py`` module::\n\n import py\n from i18n.translator import Translator\n\n # set the root of the project to the directory containing this file\n ROOT = py.path.local(__file__).dirpath()\n LANGUAGES = ['it_IT', 'fr_FR', 'de_DE']\n\n tr = Translator(ROOT, LANGUAGES, 'it_IT')\n _ = tr._\n ngettext = tr.ngettext\n\n if __name__ == '__main__':\n tr.cmdline(sys.argv)\n\nThis way, the rest of the application can simply import and use ``_()`` and\n``ngettext()`` from ``translate.py``. Or, at your preference, import directly\nthe ``tr`` object and use ``tr._()`` and ``tr.ngettext()`` to translate\nmessages.\n\nThe last two lines of the code enables a convenient way to call ``extract``\nand ``compile`` from the command line without having to manually specify the\nroot dir and the supported languages. Just run::\n\n $ python translate.py extract # ...or compile\n\nAcknowledgments\n================\n\nThe development of this package has been generously funded by `S3 s.r.l.`_.\n\n.. _`S3 s.r.l.`: http://s3srl.com/", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://bitbucket.org/antocuni/i18n", "keywords": "i18n gettext pybabel translation", "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "i18n", "package_url": "https://pypi.org/project/i18n/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/i18n/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://bitbucket.org/antocuni/i18n" }, "release_url": "https://pypi.org/project/i18n/0.2/", "requires_dist": null, "requires_python": null, "summary": "Simplify the development of internationalized applications", "version": "0.2" }, "last_serial": 704861, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "8ba3f875af08690ae94f6270fb632541", "sha256": "351cf8ed39676f7e6ec0af27dc0ed6968ffdaf4bdbefbc60ff671bd87f819905" }, "downloads": -1, "filename": "i18n-0.1.tar.gz", "has_sig": false, "md5_digest": "8ba3f875af08690ae94f6270fb632541", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5905, "upload_time": "2012-05-30T14:39:52", "url": "https://files.pythonhosted.org/packages/0f/7c/31ca36ad8ab2375f70d7348c480799193b97efeff2ff30c12dceac11d15c/i18n-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "4463da4ad3678728741b757b3a6aa55a", "sha256": "a6206172b184887c57a5a209d8be7aa5f70d36a7a66aa7506754e9e377d2fb4c" }, "downloads": -1, "filename": "i18n-0.2.tar.gz", "has_sig": false, "md5_digest": "4463da4ad3678728741b757b3a6aa55a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6500, "upload_time": "2012-10-31T19:18:29", "url": "https://files.pythonhosted.org/packages/06/f7/5252ff5349e5b39320a7aee118c48fa890baebb0aa33b76968a41f4ed151/i18n-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4463da4ad3678728741b757b3a6aa55a", "sha256": "a6206172b184887c57a5a209d8be7aa5f70d36a7a66aa7506754e9e377d2fb4c" }, "downloads": -1, "filename": "i18n-0.2.tar.gz", "has_sig": false, "md5_digest": "4463da4ad3678728741b757b3a6aa55a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6500, "upload_time": "2012-10-31T19:18:29", "url": "https://files.pythonhosted.org/packages/06/f7/5252ff5349e5b39320a7aee118c48fa890baebb0aa33b76968a41f4ed151/i18n-0.2.tar.gz" } ] }