你如何处理在Django的REST框架使用angularjs转换(多语言)web服务?如何处理、多语言、框架、Django

2023-09-13 03:41:48 作者:仅剩那点余温

我是一个初学者使用。Django的,Django的休息框架和客户端的MVC框架Angularjs

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?

推荐答案

有什么具体到关于处理语言AngularJS。如果你要处理的选择,客户端,请务必将接受语言头。请参阅 Django的翻译文档。

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.

如果你想处理语言选择的服务器端,您可以使用的 URL模式的,或设置 translation.LANGUAGE_SESSION_KEY 会话密钥。

If you want to handle language choice server-side, you can use either url patterns, or set the translation.LANGUAGE_SESSION_KEY session key.

如果你需要支持的存储支持数据转换(即型号), Django的modeltranslation 是pretty包好使用。它动态地添加字段的指定,每一个 settings.LANGUAGES 的额外列,然后让你在当前活跃的语言使用原始列作为代理的值。

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.