这一行表示什么: - Django CMS PollPluginPublisher中的模块= _("民意调查")

时间:2016-11-02 06:46:32

标签: django-cms

我正在尝试学习Django Cms,但这里是我遇到的问题。在下面的Django CMS官方文档代码中 链路: - http://docs.django-cms.org/en/release-3.4.x/introduction/plugins.html

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from polls_cms_integration.models import PollPluginModel
from django.utils.translation import ugettext as _


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

    def render(self, context, instance, placeholder):
        context.update({'instance': instance})
        return context

plugin_pool.register_plugin(PollPluginPublisher)  # register the plugin

我无法使用line module = _("民意调查")

1 个答案:

答案 0 :(得分:0)

from django.utils.translation import ugettext as _

Django I18N documentation

  

为了使Django项目可翻译,您必须在Python代码和模板中添加最少量的钩子。这些钩子称为翻译字符串。他们告诉Django:“如果用这种语言提供该文本的翻译,这篇文章应该翻译成最终用户的语言。”你有责任标记可翻译的字符串;系统只能翻译它知道的字符串。

     

...

     

使用函数ugettext()指定翻译字符串。通常将其作为较短的别名_导入,以节省输入。