Search code examples
pythoninternationalizationpython-babel

Translate string with python babel doesn't work


I have this python line

raise ValueError(_(u'Your password must be {} of characters or longer.'.format(MIN_PASSWORD_LENGTH)))

I added it to the PO file:

msgid "Your password must be {} of characters or longer."
msgstr "Votre mot de passe doit être {} de caractères ou plus."

I compiled it but it doesn't translate it.

All other translations work on this site except this one.

What am I missing here?


Solution

  • On the .po file you need to keep the %s format.

    like this:

    msgid "Your password must be %s characters or longer."
    msgstr "Votre mot de passe doit être %s caractères ou plus."
    

    Or with the python-brace-format

    #: foo/bar.py:32 
    #, python-brace-format
    msgid "Your password must be {n} characters or longer."
    msgstr "Votre mot de passe doit être {n} caractères ou plus."