Monday 18 February 2013

Multilingual support in Django

  1. Go to settings.py file and
    USE_I18N = True
    USE_L10N = True
    Go to middleware_classes section
    add "'django.middleware.locale.LocaleMiddleware"
  2. Create Template and write code
    {%load i18n %}
    {% trans "Hi I am Prashant Gaur" %}  (you need to put all data in trans or any django template block)
  3. Create language files:
    go to project directory-
    mkdir locale
    django-admin.py makemessages -l en      (english
    django-admin.py makemessages -l sv       (swedish)   
    If you are getting any error so it means you are missing xgettext (ubuntu)
    sudo apt-get install gettext
  4. python manage.py compilemessages
  5. Now change language in browser to swedish it will automatically convert into swedish .
  6. You can create many language files and multilingual environment is ready
     

No comments:

Post a Comment