Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django internationalization language codes [closed]

Where can I find list of languages and language_code like this.

(Swedish,sv) (English,en) 
like image 773
Hulk Avatar asked Jul 08 '10 06:07

Hulk


People also ask

What is lazy text in Django?

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.

How do I get current language in Django?

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.

What is Django language code?

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 .

Which support Django to use multilingual websites through its built in internationalization system to develop the websites which would support multiple languages?

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.


2 Answers

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 about using settings:

Note that django.conf.settings isn’t a module

like image 114
Thomas Avatar answered Sep 18 '22 01:09

Thomas


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) 
like image 44
vishes_shell Avatar answered Sep 22 '22 01:09

vishes_shell