源文本不会更新

时间:2013-12-06 11:02:41

标签: python django dictionary poedit

我在Django中有一个字典,其中一个已翻译的字符串在.po文件中不会更新,即使它在模型中已更改。

我所做的是改变徽章条件(游戏化网站):

'Wrote %(arg_0)d comments to %(arg_1)d different questions (comments has got at least %(arg_2)d points)'

为...

'Wrote %(arg_0)d comments to %(arg_1)d different questions'

当我用Poedit打开.po文件时,旧的条件仍然是源文本,即使它在模型中已更改。当我在Poedit中更改源文本(即删除最后的 arg )并保存文件时, arg 会回来并且编辑器会抱怨 arg 在翻译文本中缺失。

我做错了什么?

来自模型的

代码(badges.py):

class Commentor_Badge(AbstractBadge):

    badge_name='Commentor'
    description=_('Wrote %(arg_0)d comments to %(arg_1)d different questions')
    #description=_('Wrote %(arg_0)d comments to %(arg_1)d different questions (comments has got at least %(arg_2)d points)')
    trigger_model=get_model("comments","Comment")

    @classmethod
    def listener(cls,instance,**kwargs):
        user=instance.user
        super(Commentor_Badge,cls).listener(user=user,**kwargs)

    @classmethod
    def check_condition_met(cls,params,user):
        num_comments=params[0]
        num_questions=params[1]
        #num_wtfs=params[2]
        question_type=get_model("contenttypes","ContentType").objects.get_for_model(get_model("QAManager","Question"))
        all_comms=get_model("comments","Comment").objects.filter(user=user,content_type=question_type)
        diff_comms=all_comms.values('object_pk').distinct().order_by()
        return all_comms.count()>=num_comments and diff_comms.count()>=num_questions

    @classmethod
    def create_badge_in_db(cls):
        super(Commentor_Badge,cls).create_badge_in_db('Kommenterare',"{'bronze':(5,5,0),'silver':(20,10,0),'gold':(100,50,0),}")
        # super(Commentor_Badge,cls).create_badge_in_db('Kommenterare',"{'bronze':(5,5,2),'silver':(20,10,5),'gold':(100,50,5),}")

    @classmethod
    def get_description(cls,level):
        dic=cls.get_description_args(level)
        return _('Wrote %(arg_0)d comments to %(arg_1)d different questions')%dic
        #return _('Wrote %(arg_0)d comments to %(arg_1)d different questions (comments has got at least %(arg_2)d points)')%dic

1 个答案:

答案 0 :(得分:3)

要将.po文件内容与源代码中的字符串同步,请执行以下操作:

python manage.py makemessages -a

您似乎认为您不需要这样做,因为您使用Poedit和" Poedit将.po文件转换为.mo文件" 。将.po文件编译为.mo文件是一个完全不同的过程,以及不同的Django管理命令 - python manage.py compilemessages

首先,您使用makemessages将源代码中的字符串转换为.po文件,然后翻译它们,然后使用compilemessages进行编译。