Skip to content

Instantly share code, notes, and snippets.

@Varnan
Created September 3, 2015 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Varnan/7c2eb085a6b6ee5b8c69 to your computer and use it in GitHub Desktop.
Save Varnan/7c2eb085a6b6ee5b8c69 to your computer and use it in GitHub Desktop.
Model Translation - Multi language support for your Django project
======================= Model Translation ===============================================
Its also very simpleModel Translation, if you want to translate data inside the db, then it will add new field for the languages that you have set in settings.py,
#### Just follow this:
http://django-modeltranslation.readthedocs.org/en/latest/
######### Model stranslation Work flow ####################
Step: 1
Set languages for the site in settings.py file.
Step:2
Install modeltranslation app, using pip install django-modeltranslation,
Step:3
Add modeltranslation to INSTALLED_APPS before contrib.admin,
INSTALLED_APPS = (
'modeltranslation',
'django.contrib.admin', # optional
)
Step:4
Set URL conf as i18n_patterns, import from django.conf.urls.i18n import i18n_patterns, in urls.py file
Example:
urlpatterns = i18n_patterns('',
url(r'^ckeditor/', include(admin.site.urls)),
)
Step:5
create the translation file, like translation.py inside the apps model that you want to translate.
Just follow this link:
http://django-modeltranslation.readthedocs.org/en/latest/registration.html?highlight=translation.py
At last migrate just like this,
1 . python manage.py makemigrations
2. python manage.py migrate
Thats it..
Remaining part will managed by sort of middlewares.
For the complete reference check the link:
http://django-modeltranslation.readthedocs.org/en/latest/index.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment