Search code examples
pythonkivyxgettext

Is it possible to change pattern recognition of xgettext?


I'm using python, gettext and kivy to make a multi-language app.

  1. I have a label with some text Label(text = _("hi")). I made the code to be able to switch language, but that requires to reset the text, Label.text = _(Label.text), but this code is a problem, since once the translation is done, the text to be used as msgid is translated, and therefore, not found in .po files the next time.

  2. I created a workaround, something like MyLabel(textKey = msgid). This solves all the problems, since changing language is done with MyLabel.text = _(MyLabel.textKey).

  3. But this approach has an issue, if I use xgettext to generate the .pot file, msgid is not recognized because it is not written as _(msgid) and it cannot be (point 1).

My question is: is there a way to tell xgettext to recognise textKey = msgid?


Solution

  • I ended up using pygettext, there I can use the -k argument. See docs.