{ "info": { "author": "Silvio Luis Leite", "author_email": "silviolleite@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 2.1", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries" ], "description": "Django Translation Flags\n========================\n\n|Build Status| |Maintainability| |codecov| |PyPI - Downloads| |PyPI -\nVersion|\n\nThis Django app provides integration for translation options in\ntemplates with some most common standard world languages. This is useful\nfow when you need to display language options in yours Django Apps.\n\nRequirements\n============\n\nDjango Translation Flags require Django Internationalization and\nlocalization properly configured. You can see more about these settings\nin https://docs.djangoproject.com/en/2.1/topics/i18n/\n\nBasically you need to:\n\n1. Define a custom ``LANGUAGES`` list on ``settings.py`` with tuples,\n i.e:\n\n.. code:: python\n\n from django.utils.translation import gettext_lazy as _\n\n LANGUAGES = [\n ('de', _('German')),\n ('en', _('English')),\n ('pt-br', _('Brazilian Portuguese'))\n ]\n\nOnly languages listed in the ``LANGUAGES`` setting can be selected. This\nexample restricts languages that are available for automatic selection\nto German, English and Brazilian Portuguese\n\n2. Add Middleware\n\nTo use LocaleMiddleware, add \u2018django.middleware.locale.LocaleMiddleware\u2019\nto your MIDDLEWARE setting. Because middleware order matters, follow\nthese guidelines:\n\n- Make sure it\u2019s one of the first middleware installed.\n- It should come after SessionMiddleware, because LocaleMiddleware\n makes use of session data. And it should come before CommonMiddleware\n because CommonMiddleware needs an activated language in order to\n resolve the requested URL. If you use CacheMiddleware, put\n LocaleMiddleware after it.\n\nFor example, your MIDDLEWARE might look like this:\n\n.. code:: python\n\n MIDDLEWARE = [\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.locale.LocaleMiddleware',\n 'django.middleware.common.CommonMiddleware',\n ]\n\n3. Markup the text to translation:\n\nThe format of ``.po`` files is straightforward. Each ``.po`` file\ncontains a small bit of metadata, such as the translation maintainer\u2019s\ncontact information, but the bulk of the file is a list of messages \u2013\nsimple mappings between translation strings and the actual translated\ntext for the particular language.\n\nFor instance, if your Django app contained a translation string for the\ntext \u201cWelcome to my site.\u201d, like so:\n\n.. code:: python\n\n from django.utils.translation import gettext_lazy as _\n _(\"Welcome to my site.\")\n\n\u2026then ``django-admin makemessages`` will have created a ``.po`` file\ncontaining the following snippet \u2013 a message:\n\n.. code:: text\n\n #: path/to/python/module.py:23\n msgid \"Welcome to my site.\"\n msgstr \"\"\n\n4. Generate and compile it using the commands bellow:\n\n- The first step is to create a message file for a new language:\n\n.. code:: bash\n\n django-admin makemessages -l de -l en -l pt_BR\n\n- Compiling message files after creating your message file:\n\n.. code:: bash\n\n django-admin compilemessages\n\nFor more detailed information on how to create language files it is\nsuggested to read the documentation:\nhttps://docs.djangoproject.com/en/2.1/topics/i18n/translation/#how-to-create-language-files\n\nInstall\n=======\n\nInstall from PyPI:\n\n::\n\n pip install django-translation-flags\n\nConfiguration\n=============\n\nAdd ``django-translation-flags`` to your list of ``INSTALLED_APPS`` in\nsettings.py:\n\n.. code:: python\n\n INSTALLED_APPS = [\n ...\n 'django_translation_flags',\n ...\n ]\n\nAdd the Django Translation Flags URLs to ``urls.py``:\n\n.. code:: python\n\n from django.conf.urls import url, include\n\n urlpatterns = [\n ...\n path('i18n/', include('django_translation_flags.urls')),\n ...\n ]\n\nInject the required meta tags in your ``base.html`` (or wherever your\nHTML
is defined):\n\n.. code:: html\n\n {% load flags %}\n\n