Skip to main content

Lightweight i18n for Django framework

Project description


django-i18n is a Lightweight i18n library for Django framework


Use the package manager pip to install django-i18n

pip3 install django-i18n


Before using library, you need setup some things in your django project, please follow this steps

  1. Setup all required variables in your
LOCALE = 'es' # Mandatory
LOCALE_FALLBACK = 'en' # Optional, default =  'en'
LOCALES = ['es'] # Mandatory
LOCALES_PATH = os.path.join(BASE_DIR, 'locales') # Optional, default path './locales' folder

  1. After that, you need create a locales folder (Setted in LOCALES_PATH variable in your, inside your folder you need some yml files with EXACT names as you setted in LOCALES variable, next you can see an example
    title: "An incredible title"
    content: "Hello %{name}"

Usage in python files

from import translate, set_locale, handle_orm_errors

# OR
translate('my.content', name='World')

# Set locale
set_locale(locale="en", fallback="es") # Fallback is optional, default value is 'en'

# Handle ORM errors
form = MyForm(data)
handle_orm_errors(list_errors=form.errors, as_json=False)
# List errors is a Django forms errors
#as_json return dict as json string

Usage in template

{% load t from django_i18n %}

    <title>{% t 'my.title' %}</title>
    <h1>{% t 'my.content' name='World' %}</h1>

Fallback response

If you have setted a fallback, each translation may be return

#> Fallback: An incredible title

If that key doesn't exists in your locale and your fallback, this is the response

#> Translation missin my.locale2

To Do

  1. Forms complete support handler
  2. Default messages for Django forms
  3. Other supported formats


Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-i18n, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size django-i18n-1.0.2.tar.gz (4.1 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page