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. how to define repeated string with qtranslator?
Forum Updated to NodeBB v4.3 + New Features

how to define repeated string with qtranslator?

Scheduled Pinned Locked Moved Unsolved General and Desktop
26 Posts 5 Posters 3.8k 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.
  • C Online
    C Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 1 Dec 2021, 07:36 last edited by
    #21

    It's because the context is wrong - it's not QObject but your class name ('Dll' in your example).
    Still don't understand the reason behind all this. If you want some kind of translation library you should use a proper class with a get() function which takes an enum which represents your string

    class Translator : public QObject
    {
      Q_OBJECT
    public:
      enum class Id
      {
       Hello1,
       Hello2,
      }
      QString translateMe(Id id) const;
    }
    
    ...
    
    QString Translator::translateMe(Id id) const
    {
      switch (id) {
        case Id::Hello1: return tr("Hello1");
        case Id::Hello2: return tr("Hello2");
       }
    }
    

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

    Q 1 Reply Last reply 1 Dec 2021, 07:58
    3
    • C Christian Ehrlicher
      1 Dec 2021, 07:36

      It's because the context is wrong - it's not QObject but your class name ('Dll' in your example).
      Still don't understand the reason behind all this. If you want some kind of translation library you should use a proper class with a get() function which takes an enum which represents your string

      class Translator : public QObject
      {
        Q_OBJECT
      public:
        enum class Id
        {
         Hello1,
         Hello2,
        }
        QString translateMe(Id id) const;
      }
      
      ...
      
      QString Translator::translateMe(Id id) const
      {
        switch (id) {
          case Id::Hello1: return tr("Hello1");
          case Id::Hello2: return tr("Hello2");
         }
      }
      
      Q Offline
      Q Offline
      QtTester
      wrote on 1 Dec 2021, 07:58 last edited by QtTester 12 Jan 2021, 07:58
      #22

      @Christian-Ehrlicher said in how to define repeated string with qtranslator?:

      class Translator : public QObject
      {
      Q_OBJECT
      public:
      enum class Id
      {
      Hello1,
      Hello2,
      }
      QString translateMe(Id id) const;
      }

      QString Translator::translateMe(Id id) const
      {
      switch (id) {
      case Id::Hello1: return tr("Hello1");
      case Id::Hello2: return tr("Hello2");
      }
      }

      That is what I first said: write a common、 stand alone project and call it's API.

      C 1 Reply Last reply 1 Dec 2021, 08:02
      0
      • Q QtTester
        1 Dec 2021, 07:58

        @Christian-Ehrlicher said in how to define repeated string with qtranslator?:

        class Translator : public QObject
        {
        Q_OBJECT
        public:
        enum class Id
        {
        Hello1,
        Hello2,
        }
        QString translateMe(Id id) const;
        }

        QString Translator::translateMe(Id id) const
        {
        switch (id) {
        case Id::Hello1: return tr("Hello1");
        case Id::Hello2: return tr("Hello2");
        }
        }

        That is what I first said: write a common、 stand alone project and call it's API.

        C Online
        C Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 1 Dec 2021, 08:02 last edited by
        #23

        @QtTester said in how to define repeated string with qtranslator?:

        That is what I first said: write a common、 stand alone project and call it's API.

        So what's the actual problem then?

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

        Q 1 Reply Last reply 1 Dec 2021, 08:09
        0
        • C Christian Ehrlicher
          1 Dec 2021, 08:02

          @QtTester said in how to define repeated string with qtranslator?:

          That is what I first said: write a common、 stand alone project and call it's API.

          So what's the actual problem then?

          Q Offline
          Q Offline
          QtTester
          wrote on 1 Dec 2021, 08:09 last edited by
          #24

          @Christian-Ehrlicher said in how to define repeated string with qtranslator?:

          @QtTester said in how to define repeated string with qtranslator?:

          That is what I first said: write a common、 stand alone project and call it's API.

          So what's the actual problem then?

          guys said it is overcomplicate or no need to do this , so i try to find another native way .after a long circle way , you give me the same solution. ha-ha-ha

          1 Reply Last reply
          0
          • C Online
            C Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 1 Dec 2021, 08:37 last edited by
            #25

            I would not use this solution but translate it more than once - it's easier esp. since linguist auto-translates your strings when it already find the exact same match.

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

            Q 1 Reply Last reply 1 Dec 2021, 09:05
            0
            • C Christian Ehrlicher
              1 Dec 2021, 08:37

              I would not use this solution but translate it more than once - it's easier esp. since linguist auto-translates your strings when it already find the exact same match.

              Q Offline
              Q Offline
              QtTester
              wrote on 1 Dec 2021, 09:05 last edited by
              #26

              @Christian-Ehrlicher said in how to define repeated string with qtranslator?:

              e

              How do you solve this situation:

              Project1
                 dll1
                 dll2
                 app
              
              Project2
                 dll3
                 dll4
                 app
              

              Project1 and Project2 or other projects need to use the same string. many many string(like ok, yes, no ...)
              if you translate each BIg Project, you donot need to do the repetitive work?
              and you cannot put dll1.ts to Project2, you mean linguist know it's already translated?

              1 Reply Last reply
              0

              21/26

              1 Dec 2021, 07:36

              • Login

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