Search code examples
pythontranslationgettext

Why do pygettext translates strings in tuples but not strings in a list of tuples?


I used pygettext to translate a python module, and it created the po file correctly, but when it comes to translating, it does not translate everything. For example:

txt=(_("Wait"),_("shutting"),_("down..."))

The strings in the tuple get translated correctly

Menu_Main = [
    (_("Begin Exam"), "test(duration=env['TEST_DURATION'])"),
    (_("Back to Parameters Monitor"), "menu_return(True)"),
]

The strings in this tuples list don't get translated. Why?

I installed the language this way:

lang = "it"
gettext.textdomain('domain')
gettext.bindtextdomain('domain', '/usr/share/locale')
la = gettext.translation('domain', '/usr/share/locale',languages=lang.split(),fallback=True)
_ = la.gettext
la.install(names=['gettext'])

I tried to use xgettext instead of pygettext but nothing changed


Solution

  • Ok, i found the solution to the problem. I had the tuples nested in a list, and a menu which was iterating over them, so i had to use defferred translations. Inside the for loop:

    draw.text((dt_x, dt_y) , _(mytext), font=myfont, fill="white")
    

    I had to wrap mytext (the tuple of strings) with the _() function.