Django-all-auth:语言翻译不起作用 [英] Django-all-auth: language translation doesn't work

查看:215
本文介绍了Django-all-auth:语言翻译不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是韩国人,在我的 Django 项目中使用 django-all-auth

I'm Korean and using django-all-auth in my Django Project.

我检查了 django-all-auth .po >。

I checked that there is Korean .po file in django-all-auth.

但是所有表达式都是英文,不是韩文。

But all expressions are english, not Korean.

我刚刚遵循安装部分和配置部分在 doc

I just followed Installation part and Configuration part in doc.

这里是我的 settings.py

LANGUAGE_CODE = 'ko-kr'

TIME_ZONE = 'Asia/Seoul'

USE_I18N = True

USE_L10N = True

USE_TZ = True

我错过了什么吗?

推荐答案

从现在开始,您的网页已配置为路由到您现在需要的所需国际化提供本地化本身。他们不会自动翻译。你需要自己处理。
为此,您必须使用django.utils中的

Since now your pages are configured to route to the desired internationalization you now need to provide localization yourself. They will not automatically be translated. You need to handle it yourself. To do so you will have to mark the elements that need to be translated by using

from django.utils.translation import ugettext as _

现在使用 ugettext as _ 以下列方式: -

Now mark the text that you need to translate by using ugettext as _in the following way:-

class PollPluginPublisher(CMSPluginBase):
    model = PollPluginModel  # model where plugin data are saved
    module = _("Polls")
    name = _("Poll Plugin")  # name of the plugin in the interface

现在元素被标记为在我们的案例(投票)和(投票插件)中翻译。
处理完这个之后,你可以在根目录中运行以下命令: -

Now the elements are marked to be translated in our case ("Polls") and ("Poll Plugin"). After dealing with this you can run following command in your root directory:-

django-admin makemessages -l de

将最后一个de替换为您的语言区域设置名称。这个命令的作用是它将创建只存储需要翻译的元素的po文件。确保您的 LOCALE_PATH 设置正确。

Replace the last "de" with your language locale name. What this command does is that it will create the po file which will just store the elements that need to be translated. Be sure that your LOCALE_PATH is set properly.

完成后,您可以使用以下django软件包进行翻译: -

After this done you can use the following django-packages for translations:-

1) django-rosetta :- https://django-rosetta.readthedocs.io/en/latest/

2) django-modeltranslation:- http://django-modeltranslation.readthedocs.io/en/latest/

如需进一步参考LOCALIZATION,您可以查看: -

For further reference of LOCALIZATION you can view:-

https://docs.djangoproject.com/en/1.10/topics/i18n/translation/#localization-how-to-create-language-files

这篇关于Django-all-auth:语言翻译不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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