Where can I find list of languages and language_code like this.
(Swedish,sv) (English,en)
Use the lazy versions of translation functions in django. utils. translation (easily recognizable by the lazy suffix in their names) to translate strings lazily – when the value is accessed rather than when they're called. These functions store a lazy reference to the string – not the actual translation.
get_language() which returns the language used in the current thread. See documentation. Caveat: Returns None if translations are temporarily deactivated (by deactivate_all() or when None is passed to override()). Before Django 1.8, get_language() always returned LANGUAGE_CODE when translations were deactivated.
language code. Represents the name of a language. Browsers send the names of the languages they accept in the Accept-Language HTTP header using this format. Examples: it , de-at , es , pt-br .
Multilingual Support − Django supports multilingual websites through its built-in internationalization system. So you can develop your website, which would support multiple languages. Framework Support − Django has built-in support for Ajax, RSS, Caching and various other frameworks.
If you want something you can use from within django, try:
from django.conf import settings
this will be in the format above, making it perfect for assignment in one of your models choices= fields. (i.e. user_language = models.CharField(max_length=7, choices=settings.LANGUAGES)
)
LANGUAGES = ( ('ar', gettext_noop('Arabic')), ('bg', gettext_noop('Bulgarian')), ('bn', gettext_noop('Bengali')), etc.... )
Note that django.conf.settings isn’t a module
Previous answers mention only getting LANGUAGE
from settings.py, hovewer there is a big chance that this variable will be overwritten. So, you can get the full list from django.conf.global_settings.LANGUAGES
from django.db import models from django.conf.global_settings import LANGUAGES class ModelWithLanguage(models.Model): language = models.CharField(max_length=7, choices=LANGUAGES)
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