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. Is there a way to add a language to QTranslator when reimplementing the translate method?
Forum Updated to NodeBB v4.3 + New Features

Is there a way to add a language to QTranslator when reimplementing the translate method?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 318 Views 2 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.
  • D Offline
    D Offline
    devjb
    wrote on last edited by devjb
    #1

    I consider subclassing QTranslator in some test cases, so that I can simply put some test data in that subclass reimplementing the translate method.

    In that automated test, I do not want to have the overhead of fiddling around with ts and qm files. I thought that it would be easier to simply use a reimplemented translate method.

    However, I wonder how I make my own subclassed translators then aware of the language. As far as I see I can only do that untimately when the do_load is called in the private qtranslator.

    So I assume that it is not possible at all to add language information for my reimplemented translate method without providing an actual qm file.

    Do I overlook something?

    Christian EhrlicherC 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @devjb Why you want to know it? And since you instantiate the translator and also derive from QTranslator you also know it's language.

      D Offline
      D Offline
      devjb
      wrote on last edited by
      #5

      @Christian-Ehrlicher

      I was gonna use them in a language switching mechanism, where I provided several QTranslators to that would then have been installed dynamically if they matched the desired language.

      Never mind, I will prime the translators with a prebuilt set of qm files, that give them the initial language and then adding my testing strings separately. Those test qm files do not need to contain the actual strings. The language information is sufficient.

      My language switcher can then determine the language from that and still use the custom translate method.

      1 Reply Last reply
      0
      • D devjb

        I consider subclassing QTranslator in some test cases, so that I can simply put some test data in that subclass reimplementing the translate method.

        In that automated test, I do not want to have the overhead of fiddling around with ts and qm files. I thought that it would be easier to simply use a reimplemented translate method.

        However, I wonder how I make my own subclassed translators then aware of the language. As far as I see I can only do that untimately when the do_load is called in the private qtranslator.

        So I assume that it is not possible at all to add language information for my reimplemented translate method without providing an actual qm file.

        Do I overlook something?

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @devjb You can simply override QTranslator::translate(): https://doc.qt.io/qt-6/qtranslator.html#translate

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        D 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @devjb You can simply override QTranslator::translate(): https://doc.qt.io/qt-6/qtranslator.html#translate

          D Offline
          D Offline
          devjb
          wrote on last edited by devjb
          #3

          @Christian-Ehrlicher Yeah, that is entirely what I mentioned in my very first sentence in my post.

          However, I then can only pass context, source, disambiguation and n as parameters.
          And thus, you cannot determine which language that QTranslator provides.
          Meaning if you iterating over a number of QTranslators, you cannot get the language from the custom ones.

          Christian EhrlicherC 1 Reply Last reply
          0
          • D devjb

            @Christian-Ehrlicher Yeah, that is entirely what I mentioned in my very first sentence in my post.

            However, I then can only pass context, source, disambiguation and n as parameters.
            And thus, you cannot determine which language that QTranslator provides.
            Meaning if you iterating over a number of QTranslators, you cannot get the language from the custom ones.

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @devjb Why you want to know it? And since you instantiate the translator and also derive from QTranslator you also know it's language.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            D 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @devjb Why you want to know it? And since you instantiate the translator and also derive from QTranslator you also know it's language.

              D Offline
              D Offline
              devjb
              wrote on last edited by
              #5

              @Christian-Ehrlicher

              I was gonna use them in a language switching mechanism, where I provided several QTranslators to that would then have been installed dynamically if they matched the desired language.

              Never mind, I will prime the translators with a prebuilt set of qm files, that give them the initial language and then adding my testing strings separately. Those test qm files do not need to contain the actual strings. The language information is sufficient.

              My language switcher can then determine the language from that and still use the custom translate method.

              1 Reply Last reply
              0
              • D devjb has marked this topic as solved on

              • Login

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