I am trying to get in my views.py
a list of all the languages I have available.
This is easily done in a template through the tag
{% get_available_languages as LANGUAGES %}
(docs here), but I do not find its equivalent for the views.
Is there any simple way to get it?
In order to make a Django project translatable, you have to add a minimal number of hooks to your Python code and templates. These hooks are called translation strings.
gettext_lazy is a callable within the django. utils. translation module of the Django project.
A Django template is a text document or a Python string marked-up using the Django template language. Some constructs are recognized and interpreted by the template engine. The main ones are variables and tags. A template is rendered with a context.
from django.conf import settings
settings.LANGUAGES
anyways you have to config LANGUAGES
in settings before like this:
from django.utils.translation import ugettext_lazy as _
LANGUAGES = [
('de', _('German')),
('en', _('English')),
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With