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



  • 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.



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



  • 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?



  • 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.



  • 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?



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.