I am a beginner with using: django, the django rest framework and the client-side MVC framework Angularjs.
I would like to ask any developers working or familiar with this stack in any of your projects, how you deal with translations (in many languages)?
What are best practices to do it as efficiently as possible and are there any new language extensions available?
I wanted to use Django with AngularJS and use the same PO files for frontend and backend translations.
In the end I succeeded using django-vinaigrette and angular-translate. I created a model AngularTranslations with two case-sensitive fields, orig and trans, with the same content. (A bit of waste, but OK). I registered the 'trans' field with Vinaigrette, and then I created an API GET-method that outputs the translations as JSON readable by angular-translate. I also allowed POST's to the same method to store missing translations. Vinaigrette then picks them up when running
manage.py makemessages
.Can elaborate more but this is the gist of it.
There's nothing specific to AngularJS about dealing with languages. If you want to handle the choice client-side, make sure to set the
Accept-Language
header. See the django translation docs.If you want to handle language choice server-side, you can use either url patterns, or set the
translation.LANGUAGE_SESSION_KEY
session key.If you need to support translations for storage-backed data (i.e. models), django-modeltranslation is a pretty good package to use. It dynamically adds extra columns for fields you specify, one for each of
settings.LANGUAGES
, then lets you use the original column as a proxy to the value in the current active language.I think good start point for someone, who would like in the future deal with translation in case of REST can be this article:
https://web.archive.org/web/20150504195746/http://codeispoetry.me:80/index.php/django-multilingual-restful-api-i18n-support-with-django-tastypie/
it forces usage of i18n, which is base of e.g django admin trans.