开发者

Django form errors translate

开发者 https://www.devze.com 2023-02-11 15:52 出处:网络
Hi i do simple interface to add message with author name. It have two fields one with name second with message. My function сheks form.is_valid() if that true the element are added to database else i

Hi i do simple interface to add message with author name. It have two fields one with name second with message. My function сheks form.is_valid() if that true the element are added to database else i render template with error form and message 'This field is required.' appearead. It's cool that so few lines of code lead to this开发者_运维百科 result. But my users speak not on English language and they do not understand 'This field is required.' message. How can i change this message continuing to use form.as_table?


Django comes with built-in internationalization, see the i18n docs. In case of form error messages, they are all marked for translation and translated already in Django. All you need to do is make sure Django selects the right language for the user (see How Django discovers language preference). If all your users speak in (for example) German, you can just put this in your settings:

gettext = lambda x: x

LANGUAGE_CODE = 'de_DE'
LANGUAGES = (
    ('de', gettext('German')),
)
0

精彩评论

暂无评论...
验证码 换一张
取 消