Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. I18n how to?
Forum Updated to NodeBB v4.3 + New Features

I18n how to?

Scheduled Pinned Locked Moved Language Bindings
3 Posts 2 Posters 1.9k Views 1 Watching
  • 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.
  • O Offline
    O Offline
    onekk
    wrote on last edited by
    #1

    I'm driving mad in i18n with Pyside. I followed some tutorials but have some problem in tranlsating some QmessageBox dialog and some other parts of the project.

    There is a manner to put most the strings in external py file and import it in the app and translating all the hard to translate string here.

    as example if i do

    import messages ad MS

    and refer to them as MS.msg001 in the code so i have i translated as simple string in the messages.py file?

    Thanks to all

    Carlo D.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tripanarium
      wrote on last edited by
      #2

      I believe that you could create QTranslate() strings and use them after.
      Did you take a look to the format function?
      @
      myBestMessage = QtGui.QApplication.translate("TestSoft", "This is my secret: <br>{0}<br>Do you like it?", None)

      When you use it make something like:

      mySecret = "1234ABCDE...."
      myResult = myBestMessage.format(mySecret)
      @
      Remember that translations should hardcoded (that's what I thing I've heard of).

      Einstein: "God does not play dice."
      Bohr: "Einstein, stop telling God what to do... No, no, you're not thinking; you're just being logical."

      1 Reply Last reply
      0
      • O Offline
        O Offline
        onekk
        wrote on last edited by
        #3

        Many Thanks, I've solved putting them in the init part of the class so they are translated properly and refer to these messages in a derived QMessageBox, some QmessageBox fails About seems to work but Question (i didn't remember well fails to translate properly the messages).

              @
           
            self.toolcyl = self.tr("Cylindrical")
            self.toolsph = self.tr("Spherical (Ball)")        
            self.tooltor = self.tr("Toroidal (Bull)") 
            self.toolcon = self.tr("Conical") 
        
            glb.shape[0] = self.toolcyl
            glb.shape[1] = self.toolsph
            glb.shape[2] = self.tooltor
            glb.shape[3] = self.toolcon
        
            # End of the tool shapes definition        
            #
            ######################################################################
        
            EC_L.readTooltable(self)
            EC_UA.populateUI(self)
            
            ######################################################################        
            #        
            # Translatable string goes here i didn't find a method to make it 
            # work flawlessy in some QMessageBox 
            #
            ######################################################################
        
            # Exit Dialog        
            self.msg_01t = self.tr("<b>Exit Dialog</b>")
            self.msg_01m = self.tr("Are You sure you want to exit?")
        
            # About EuroCAM Box
            self.msg_02t = self.tr("About ")
            self.msg_02m = self.tr("<b>SomeProgram</b> is a program. <br> \
                           <br> It generates some output to help you in \
                           figuring out the life, the universe and all other things.")        
        
            # @
        

        I'm using them in the About widget without too many problem like this:

        @QMessageBox.about(self,self.msg_02t,self.msg_02m) @

        For the others MessageBox i have written a def like this:

        @
        def closeEvent(self, event):
        msgBox = QMessageBox()
        msgBox.setText(self.msg_01t)
        msgBox.setInformativeText(self.msg_01m)
        msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel)
        msgBox.setDefaultButton(QMessageBox.Yes)
        msgBox.setIcon(QMessageBox.Question)
        ret = msgBox.exec_()
        event.ignore()
        if ret == QMessageBox.Yes:
        # Do Something
        event.accept()
        elif ret == QMessageBox.Cancel:
        event.ignore()@

        In this manner it works as expected and if you note in the first lines of the examples i have translate some messages that are referenced in another module of the program. After struggling with this behavior I have found this solution that isn't too bad and not too unelegant, but the readability of the code suffers a little.

        Regards
        Carlo D.

        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