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. Translatable strings in unexpected context

Translatable strings in unexpected context

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 1.1k Views 4 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.
  • PerdrixP Perdrix

    But it isn't - those entries should be in context DSS::StackingDlg not DSS shouldn't they?

    All the other classes I have in that namespace place their translatables into DSS::ClassName context!

    David

    Chris KawaC Offline
    Chris KawaC Offline
    Chris Kawa
    Lifetime Qt Champion
    wrote on last edited by
    #4

    those entries should be in context DSS::StackingDlg not DSS shouldn't they?

    They should and they are for me. Can you make a small reproducible example when that doesn't happen?

    1 Reply Last reply
    0
    • PerdrixP Offline
      PerdrixP Offline
      Perdrix
      wrote on last edited by Perdrix
      #5

      I wish I could - I've been banging my head on it for some hours.

      I have zipped up StackingDlg.cpp and .h and uploaded the zip file to:

      http://www.perdrix.co.uk/StackingDlg.zip

      I know they won't compile, but I think you should be able to run lupdate against them.

      M 1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #6

        It works like this:

        namespace DSS
        {
           class StackingDlg : public QObject
           {
              void foo() { tr("Works!"); }
           };
        }
        

        so you must be doing something else in your code. I can't help you with code I can't see, sorry.

        1 Reply Last reply
        2
        • PerdrixP Perdrix

          I wish I could - I've been banging my head on it for some hours.

          I have zipped up StackingDlg.cpp and .h and uploaded the zip file to:

          http://www.perdrix.co.uk/StackingDlg.zip

          I know they won't compile, but I think you should be able to run lupdate against them.

          M Offline
          M Offline
          mpergand
          wrote on last edited by mpergand
          #7

          @Perdrix
          Looking at your looooooong file ,
          since your using the Designer for this dialog, I think you must specify the namespace in the "Promote To" dialog for the "Promoted class name" field.

          Here what I am doing with custom classes in a namespace:

          1 Reply Last reply
          0
          • PerdrixP Offline
            PerdrixP Offline
            Perdrix
            wrote on last edited by
            #8

            Thanks for looking - yes of course the problem had to arise with one of the largest source files!

            I am specifying the namespace for the embedded widgets

            dbee5984-7dcf-4282-8eeb-8af9b9dcca76-image.png

            Thanks again, David

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by Chris Kawa
              #9

              Well... that's odd :-)

              I did a little bit of testing. There's a line in StackingDlg::eventFilter method like this:

              if (QKeyEvent::matches(QKeySequence::keyBindings(QKeySequence::SelectAll))
              

              QKeyEvent::matches is not static, so this should rather be keyEvent->matches(..., but that's beside the point.
              This code is inside #if (0), so it shouldn't matter at all, but for whatever reason it seems to trip the linguist parser.
              If I comment that line out or remove it entirely the context for the entire class is fixed.

              I guess you've struck some odd corner case bug in the parser? I've no idea, but that's how you can workaround it.

              Btw. you have code like this in couple places:

              OUTPUTLIST_FILTERS.append(tr(filter.toLocal8Bit(), "IDS_LISTFILTER_OUTPUT"));
              

              This will not translate. Linguist is an offline tool. It can't gather dynamically resolved strings like that. You need to translate the source strings and use them already translated.

              1 Reply Last reply
              2
              • PerdrixP Offline
                PerdrixP Offline
                Perdrix
                wrote on last edited by
                #10

                Thank you Sir!

                How on earth did you find out what was wrong?

                D.

                1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by Chris Kawa
                  #11

                  How on earth did you find out what was wrong?

                  Just the usual - divide and conquer. Since the simple example I posted worked I started to remove large chunks of code until it worked. When it did I added a little bit back and so on. At the end it turned out to be just that one line that made difference. Good thing the code doesn't need to be complete or compile for linguist to work on it.

                  Reduction is often a good debugging tool :)

                  EDIT Hah, I just spotted what the issue is. Count the number of opening and closing brackets in that line. It's missing the last closing ), so the parser got lost. So it's not a linguist issue after all. That's good.

                  1 Reply Last reply
                  3
                  • PerdrixP Offline
                    PerdrixP Offline
                    Perdrix
                    wrote on last edited by
                    #12

                    Nice one thanks again.

                    Also for the pointer to the issue with the use of tr(). Is there a clean way to resolve that?

                    David

                    Chris KawaC 1 Reply Last reply
                    0
                    • PerdrixP Perdrix

                      Nice one thanks again.

                      Also for the pointer to the issue with the use of tr(). Is there a clean way to resolve that?

                      David

                      Chris KawaC Offline
                      Chris KawaC Offline
                      Chris Kawa
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      You need to mark the source strings for translation. See QT_TRANSLATE_NOOP macro. It's for this exact case.

                      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