Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with QTranslator (by GNU gettext user)
QtWS25 Last Chance

Problem with QTranslator (by GNU gettext user)

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 249 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    buhtz
    wrote on last edited by
    #1

    Hello,
    usually I do use GNU gettext to localize my Python applications. Today I realized that Qt (PyQt) do not localize; e.g. Yes/No buttons.

    I found code using QTranslator and tried it out. But the buttons in my test application are not translated (to German). I checked the docu but I don't understand the background of it.

    I assume that Qt do need a po/mo file. But how do I know where it is? I assume it was installed while I installed Qt. Shouldn't Qt know for itself where to find its translation and selected it by default based on the current locale?

    Here is my minimal (not so) working Python example.

    #!/usr/bin/env python3
    from PyQt5.QtWidgets import QApplication, QDialogButtonBox
    from PyQt5.QtCore import QTranslator, QLocale, QLibraryInfo
    
    def get_translator():
        translator = QTranslator()
        locale = QLocale.system().name()
        print(f'{locale}')  # <-- de_DE
    
        translator.load('qt_%s' % locale,
                        QLibraryInfo.location(QLibraryInfo.TranslationsPath))
    
        return translator
    
    if __name__ == '__main__':
        app = QApplication([])
        t = get_translator()
        app.installTranslator(t)
    
        buttonBox = QDialogButtonBox(
            QDialogButtonBox.Ok
            | QDialogButtonBox.Cancel
            | QDialogButtonBox.Yes
            | QDialogButtonBox.No
        )
    
        buttonBox.show()
        app.exec()
    
    1 Reply Last reply
    0
    • B Offline
      B Offline
      buhtz
      wrote on last edited by
      #2

      X-Post at StackOverflow

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved