Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Lupdate creates garbled source string when source files contain non-ASCII (utf8) strings
Forum Updated to NodeBB v4.3 + New Features

Lupdate creates garbled source string when source files contain non-ASCII (utf8) strings

Scheduled Pinned Locked Moved Qt Creator and other tools
6 Posts 2 Posters 5.2k 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.
  • E Offline
    E Offline
    eflarup
    wrote on last edited by
    #1

    I need to use non-ASCII characters in my source strings (copyright and trademark symbols, for instance), so I want to use UTF-8 as my source encoding. That seems to work OK, but when I try to use lupdate to extract the strings to .ts files the non-ASCII strings are garbled.

    My source string (including random Cyrillic characters): this кгыышфт?
    The result in the .ts file: this кгыышфт?

    I have included these statements in my .pro file:
    CODECFORTR = UTF-8
    CODECFORSRC = UTF-8

    If I convert the non-ASCII characters in my source file to unicode escapes, like this:
    this \u043a\u0433\u044b\u044b\u0448\u0444\u0442?

    the string gets extracted just fine to my .ts file using lupdate. I assume there is a way to get lupdate to work with non-escaped UTF-8 source strings, otherwise what is the point of having the codec option. So I must be doing something wrong/missing something. Any pointers would be greatly appreciated.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Are you sure, your sources files actualle are in UTF-8?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • E Offline
        E Offline
        eflarup
        wrote on last edited by
        #3

        I am indeed sure. Have verified version on disk independently from IDE. And have several colleagues who have tried the same thing independently. We all get the exact same result. Plus, all our source files for our other development projects are all in UTF-8, so it's not as if UTF-8 is something new for us (Qt is though). Have you tried this and gotten it to work?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          Yes, we have all our source files in UTF-8, including German Umlauts (ä, ö, ü, ß, € Euro sign and some more) and it works like a charm.

          We have in the .pro file:

          @
          CODECFORTR = UTF-8
          CODECFORSRC = UTF-8
          @

          And in the main method:

          @
          QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
          QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
          @

          As that's exactly what you do too, that's a weird situation. If you put the offending file somewhere where we can download it and have a look.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • E Offline
            E Offline
            eflarup
            wrote on last edited by
            #5

            OK, I think I know why it works for you - your code is C++, and not QML? I just created a translation string in my C++ file, and it got extracted just fine. But from my QML files it gets garbled.

            I had assumed that the QTextCodec::setCodecForTr function would work for the QML qsTr function as well, but apparently not? Or do you have this working in QML as well?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              Hm, sorry, I never got my fingers on translating a QML file, so I cannot comment on that. Hopefully someone else can jump in here.

              http://www.catb.org/~esr/faqs/smart-questions.html

              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