![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
django-translation-flags
Advanced tools
Internationalization with flags of main languages, It lets easy to integrate the Django i18n in yours templates
|Build Status| |Maintainability| |codecov| |PyPI - Downloads| |PyPI - Version|
This Django app provides integration for translation options in templates with some most common standard world languages. This is useful fow when you need to display language options in yours Django Apps.
Django Translation Flags require Django Internationalization and localization properly configured. You can see more about these settings in https://docs.djangoproject.com/en/2.1/topics/i18n/
Basically you need to:
LANGUAGES
list on settings.py
with tuples,
i.e:.. code:: python
from django.utils.translation import gettext_lazy as _
LANGUAGES = [ ('de', _('German')), ('en', _('English')), ('pt-br', _('Brazilian Portuguese')) ]
Only languages listed in the LANGUAGES
setting can be selected. This
example restricts languages that are available for automatic selection
to German, English and Brazilian Portuguese
To use LocaleMiddleware, add ‘django.middleware.locale.LocaleMiddleware’ to your MIDDLEWARE setting. Because middleware order matters, follow these guidelines:
For example, your MIDDLEWARE might look like this:
.. code:: python
MIDDLEWARE = [ 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', ]
The format of .po
files is straightforward. Each .po
file
contains a small bit of metadata, such as the translation maintainer’s
contact information, but the bulk of the file is a list of messages –
simple mappings between translation strings and the actual translated
text for the particular language.
For instance, if your Django app contained a translation string for the text “Welcome to my site.”, like so:
.. code:: python
from django.utils.translation import gettext_lazy as _ _("Welcome to my site.")
…then django-admin makemessages
will have created a .po
file
containing the following snippet – a message:
.. code:: text
#: path/to/python/module.py:23 msgid "Welcome to my site." msgstr ""
.. code:: bash
django-admin makemessages -l de -l en -l pt_BR
.. code:: bash
django-admin compilemessages
For more detailed information on how to create language files it is suggested to read the documentation: https://docs.djangoproject.com/en/2.1/topics/i18n/translation/#how-to-create-language-files
Install from PyPI:
::
pip install django-translation-flags
Add django-translation-flags
to your list of INSTALLED_APPS
in
settings.py:
.. code:: python
INSTALLED_APPS = [ ... 'django_translation_flags', ... ]
Add the Django Translation Flags URLs to urls.py
:
.. code:: python
from django.conf.urls import url, include
urlpatterns = [ ... path('i18n/', include('django_translation_flags.urls')), ... ]
Inject the required meta tags in your base.html
(or wherever your
HTML is defined):
.. code:: html
{% load flags %}
By default it will show the rectangular icons, but you can change it to
square
:
.. code:: html
{% load flags %}
Optionally you can set your custom class for HTML tags:
.. code:: html
{% load flags %}
The languages
template tags accept **kwargs
to configure the
class to HTML tags. So you can set the classes to these HTML tags:
li_class: Class to li
tag (Default: empty)
a_class: Class to a
tag (Default: empty)
The HTML structure is:
.. code:: html
The Django Translation Flags has a CSS
file where all the most
important languages flags are configured.
The avaliable flags are:
af
: Afrikaans, ar
: Arabic, az
: Azerbaijani, de
: German,
en
: English, en-au
: Australian English, es
: Spanish,
es-ar
: Argentinian Spanish, es-mx
: Mexican Spanish, fr
:
French, hi
: Hindi, hu
: Hungarian, id
: Indonesian, it
:
Italian, ja
: Japanese, ko
: Korean, nl
: Dutch (Nederlands),
pl
: Polish, pt
: Portuguese, pt-br
: Brazilian Portuguese,
ru
: Russian, sv
: Swedish, tr
: Turkish, uk
: Ukrainian,
zh-cn
: Simplified Chinese, zh-hans
: Simplified Chinese and
zh-hant
: Traditional Chinese.
|image5|
The App get the language code from LANGUAGES
on settings.py
and
then it concatenates the language codes with the name of the icon class
and shows the correct flags..
See the all Django supported languages in module
django.conf.locale.LANG_INFO
LANG_INFO is a dictionary structure to
provide meta information about languages.
Feedback and pull requests are strongly encouraged and kindly appreciated (-:
Python ^^^^^^
.. code:: console
git clone https://github.com/silviolleite/django-translation-flags cd django-translation-flags python -m venv .venv .venv/bin/activate pip install -r requirements.txt python runtests.py
Less to CSS ^^^^^^^^^^^
You will need of node
and npm
previously installed.
/assets/less/
.. code:: console
npm install npm run build
All files in this repository are distributed under the MIT license.
.. |Build Status| image:: https://travis-ci.org/silviolleite/django-translation-flags.svg :target: https://travis-ci.org/silviolleite/django-translation-flags .. |Maintainability| image:: https://api.codeclimate.com/v1/badges/1d00a2cbf958477ca97e/maintainability :target: https://codeclimate.com/github/silviolleite/django-translation-flags/maintainability .. |codecov| image:: https://codecov.io/gh/silviolleite/django-translation-flags/branch/master/graph/badge.svg :target: https://codecov.io/gh/silviolleite/django-translation-flags .. |PyPI - Downloads| image:: https://img.shields.io/pypi/dd/django-translation-flags.svg :target: https://pypi.org/project/django-pwa/ .. |PyPI - Version| image:: https://img.shields.io/pypi/v/django-translation-flags.svg :target: https://pypi.org/project/django-translation-flags .. |image5| image:: assets/img/flags.png
FAQs
Internationalization with flags of main languages, It lets easy to integrate the Django i18n in yours templates
We found that django-translation-flags demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.