def gettext(ui_file_path):
    """
    Let you use gettext instead of the Qt tools for l18n
    """
    with open(ui_file_path, 'r') as fin:
        content = fin.read()

    # replace ``_translate("context", `` by ``_(``
    content = re.sub(r'_translate\(".*",\s', '_(', content)
    content = content.replace(
        '        _translate = QtCore.QCoreApplication.translate', '')

    with open(ui_file_path, 'w') as fout:
        fout.write(content)
Let you use gettext instead of the Qt tools for l18n