What’s the correct way to set up Django translation?

Add LOCALE_PATHS to settings.py and set it as below: import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) LOCALE_PATHS = ( os.path.join(BASE_DIR, ‘locale’), ) Note that LOCALE_PATHS must be a tuple (look at the comma at the end of the path). Now based on LOCALE_PATHS, the locale folder should be in the root of your project. And be sure … Read more

Django internationalization for admin pages – translate model name and attributes

Important things not mentioned in the Django documentation: run django-admin compilemessages, e.g. as a part of your build process. Thanks stevejalim! apply django’s ugettext_lazy() to model names ( Meta class and verbose_name ) attribute (model field verbose_name) names can also be translated with ugettext_lazy() use lazy translation in your model metadata, otherwise the translation happens … Read more

Django internationalization language codes [closed]

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 … Read more

“gettext()” vs “gettext_lazy()” in Django

gettext() vs. gettext_lazy() In definitions like forms or models you should use gettext_lazy because the code of this definitions is only executed once (mostly on django’s startup); gettext_lazy translates the strings in a lazy fashion, which means, eg. every time you access the name of an attribute on a model the string will be newly … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)