How you deal with translation (multilanguage) webservices in Django Rest Framework using angularjs?

随声附和 提交于 2019-12-06 05:58:39

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.

thomaspaulb

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!