0

我在 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
4

1 回答 1

3

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

python manage.py makemessages -a

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

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

于 2013-12-06T14:54:02.760 回答