Django Rest框架本地化 [英] Django Rest Framework Localization

查看:100
本文介绍了Django Rest框架本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果有任何方法可以添加本地化到 django-rest-framework api。因为我想更改默认消息错误。

I was wondering, if is there any way to add localization to django-rest-framework api. Because I want to change default message errors.

推荐答案

这是在Django REST框架3.0中不太好的,不支持

This is not supported well in Django REST framework 3.0, and it's not supported at all in versions before that.

DRF用来显示错误通知的字符串大多数是可翻译的,其中一些与Django相匹配翻译,但在大多数情况下,您需要手动查找翻译字符串并自行进行翻译。另一个选项是覆盖异常处理程序并在其中翻译。

Most of the strings that DRF uses to display things such as error notices are translatable, and some of them match the Django translations, but for the most part you need to manually find out the translation strings and do the translations on your own. The other option is to override the exception handler and translate within there.

正如所述,Django REST框架3.1 提供翻译指南,并与Transifex挂钩。如果您希望在3.1(和其他未来版本)中包含默认翻译,请帮助我们并在Transifex上推荐翻译

With that said, Django REST framework 3.1 provides a guide on translating and is hooked up to Transifex. If you want your translation included by default in 3.1 (and other future releases), help us and recommend translations on Transifex.

这篇关于Django Rest框架本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆