覆盖默认的 Django 翻译 [英] Override default Django translations

查看:25
本文介绍了覆盖默认的 Django 翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的模板:

{% trans "Log out" %}

这由 Django 自动翻译成西班牙语为 Terminar sesión.不过我想把它翻译成Cerar sesión.

This is translated automatically by Django to Spanish as Terminar sesión. However I would like to translate it as Cerrar sesión.

我曾尝试将此文字添加到 .po 文件中,但是当我编译消息时,我收到一条错误消息,提示此文字重复.

I have tried to add this literal to the .po file, however I get an error saying this literal is duplicated when I compile the messages.

有没有办法改变/覆盖默认的 Django 翻译?

Is there a way to change/override default Django translations?

谢谢.

推荐答案

最简单的方法是收集 django.contrib.admin locale 文件夹中的 .po 文件并重新编译它(你可以使用 POEdit 这样做).

The easiest way is to collect the .po file found in the django.contrib.admin locale folder and re-compiling it (you can use POEdit for doing so).

您还可以覆盖 django.contrib.admin 模板,方法是将它们放在项目模板文件夹中(例如:yourproject/templates/admin/change_form.html),然后从项目根目录运行 makemessages(尽管不再支持此功能对于 django 1.4 alpha,如果我是正确的)

You could also override the django.contrib.admin templates by putting them in your projects templates folder (for example: yourproject/templates/admin/change_form.html) then running makemessages from the project root (although this is no longer supported for django 1.4 alpha if i'm correct)

Robert Lujo 的答案是干净的方法

edit: Robert Lujo's answer is the clean method

这篇关于覆盖默认的 Django 翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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