0

I have a dictionary in Django and one of the strings that's translated won't get updated in the .po file even though it's changed in the model.

What i've done is to change a badge condition (gamificated site) from:

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

to...

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

When I open the .po file with Poedit the old condition is still there as source text, even though it's changed in the model. When I change the source text (i.e. removes the last arg) in Poedit and save the file the arg comes back and the editor complains about the arg is missing in the translated text.

What am I doing wrong?

code from the model (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
holyredbeard
  • 19,619
  • 32
  • 105
  • 171
  • have you checked that poedit (i'm assuming you are using poedit) generates the translation file on save? see here for details http://supertuxkart.sourceforge.net/translating_with_poedit – Liam Sorsby Dec 06 '13 at 11:04
  • @LiamSorsby The thing is that it won't save (and therefore generate the .mo file) because of the missing _arg_ in the translation. Even if I remove the _arg_ from the source text and save it comes back. – holyredbeard Dec 06 '13 at 11:05
  • 1
    Did you run makemessages ? You don't mention it. – jpic Dec 06 '13 at 11:45
  • @jpic: Is that really needed when I use Poedit? Poedit converts .po files to .mo files. – holyredbeard Dec 06 '13 at 12:16

1 Answers1

3

To sync your .po files content with strings from your source code, do this:

python manage.py makemessages -a

You seem to think that you don't need to do this, because you use Poedit and "Poedit converts .po files to .mo files". Compiling .po files to .mo files is an entirely different process, and a different Django management command - python manage.py compilemessages.

First you get strings from your source code to .po files with makemessages, then you translate them, and only then you compile them using compilemessages.

Ludwik Trammer
  • 24,602
  • 6
  • 66
  • 90