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. On using non-English string literals in tr() and then providing English translation file.
Forum Updated to NodeBB v4.3 + New Features

On using non-English string literals in tr() and then providing English translation file.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 2.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.
  • J Offline
    J Offline
    joonhwan
    wrote on last edited by
    #1

    Hi.

    Can I use string literals in my mother language(Korean) in tr() and then provide English Translation later?
    I've just tried like following steps but failed. Am i missing something or ...? (I'm using Qt4)

    Step1. In main() function, I did for my language

    @QTextCodec::setCodecForTr(QTextCodec::codecForName("euck-kr"))@

    Step2. Use tr like tr("한국어") not tr("Korean")

    Step3. run "lupdate -codecfortr="euc-kr" . -ts test.ts"

    Step4. run linguist and translate it back to english

    Step5. release it and let my test app load it by doing following

    @QTranslator myappTranslator;
    myappTranslator.load("test");
    app.installTranslator(&myappTranslator);
    @

    I checked the return value of QTranslator::load() and it was true, but displayed message was not English but all Korean as I wrote into.

    Any help would be appreciated.

    joonhwan at gmail dot com

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2
      • "Documentation":http://qt-project.org/doc/qt-4.8/qtextcodec.html#setCodecForTr specifies a different name for Korean encoding. I'm far from being an expert on Asia, though, so maybe that is OK
      • be sure to change the codec and apply QTranslator after QApplication is initialised but before you initialise any translatable objects (say you are using QMainWindow. It should be initialised after QTextCodec and QTranslator). This may seem a detail, but is actually crucial
      • you have done this as far as I can see, but for the record: make sure your source files are encoded with UTF-8

      (Z(:^

      1 Reply Last reply
      0
      • J Offline
        J Offline
        joonhwan
        wrote on last edited by
        #3

        Thanks for kind lessons in neat summary.

        On utf-8, yes, I wrote my code in utf-8 with signature but damn visual studio 2008 c++ compiler turns every string literal in utf-8 text file into euc-kr which is the code page for my windows7(I tried change system locale to latin1("us", cp1297.. whatever) but then korean literal string cannot be filed into utf-8 but ugly characters. This is the delema for me to get approach the subject of this article.
        Which is bad news for me to get ready for Qt5 where no QTextCodec::setCodecForTr() exists.

        I still cannot show english translation for my sample app in Korean, and at least found that Qt does not handle properly korean characters when building up a hash value to search target translation in its data structures from qm file.

        No luck today.

        joonhwan at gmail dot com

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

          It's probably not the answer you were looking for but to be honest source code with characters out of ASCII range is in my experience always asking for trouble at some point. This is due to different compilers, text editors, db systems, source controlling etc. out there that mixed in certain way can take away long hours and a lot of energy from your life.

          If it is at all possible I would recommend to stick to the English version in the source code and providing translation files in your native language. This makes life easier not only for you, but for any other foreign developer that will deal with your code in the future (I'm Polish and often work with legacy German comments in VS2008 so I know the pain).
          Even if you're not planning for your app to be multilingual it is just way less trouble to load your native strings from eg. resource file.

          Of course this is not applicable to all scenarios, but if it is for yours - consider it.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Hostel
            wrote on last edited by
            #5

            Try use absolute path in load method.

            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