Python Forum

Full Version: Linux - Application translation not load when run from .desktop launcher
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've create an pyqt5 application a year ago which I'm using every day and works fine. Recently I tried to remove the hardcoded texts which are in my native language with english and add translation support. After I found some info on internet I've manage to achive what I wanted and the translation loads and works fine when I'm running the app from command line or via a script.
The problem is that when I create a .desktop file for the app or when I add it to autostart programs(in which again a .desktop file created), then the transaltion doesn't load and all texts in app appears in english language.
I incorporate the translation like this:
def run():
    app = QtWidgets.QApplication(sys.argv)
    ui = MainWindow()
    return app.exec_()
from ui import mainwindow
if __name__ == "__main__":
    import sys
I've create all forms and widgets in qtdesigner and I have "translate" checked for all labels/buttons etc.
I also used to translate all other strings.
I mentioned that when I directly run the app from command line or script, the preferences file I've implement created correct in app's folder, but when I run it from the .desktop file or autostarts at login, then the preferences file created in my user's home directory. So I'm thinking that this problem is related to translations problem. Seems that when it launches from the launcher file then doesn't look for the preferences file or the translation file on the app's folder and subfolders, but on user's home folder only.
Any help? Is this application's problem? Do I need to use some other way to declare the path to .qm file and also to preferences for the app? I don't think that is linux's issue, because I don't have this problems with other python/qt apps which are installed.
Perhaps it cannot find the path of your script, try something like:

    LOCAL_DIR = os.path.dirname(os.path.realpath(__file__))
    translator.load(LOCAL_DIR + "/ui/resources/translations/el_GR.qm")
Thanks, it works with realpath. Didn't work using the path from your post though. The file is inside the "ui' folder, so the path needs to be "/resources/translations/el_GR.qm".