On using non-English string literals in tr() and then providing English translation file.
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
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
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.
- "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
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.
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.
Try use absolute path in load method.