Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get_available_languages in views.py

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?

like image 631
J0ANMM Avatar asked Jun 27 '17 18:06

J0ANMM


People also ask

How to translate in Django?

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.

What is Django Gettext_lazy?

gettext_lazy is a callable within the django. utils. translation module of the Django project.

What are templates in Django?

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.


1 Answers

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')),
]
like image 79
Diego Puente Avatar answered Nov 15 '22 00:11

Diego Puente