Translate the result of QLocale::languageToString()
Titles says it all.
I am displaying a list of languages and I use QLocale::languageToString() somewhere in my code.
I was wondering if it is possible to have it returns a string translated so when the program is in German I will get "Deutsch" and not "German"
Thanks a lot guys!
@QString translated = tr(QLocale::languageToString().toAscii());@
This is what I already (and stupidly) wrote in my code (except I wrote ".toLatin1()").
But this obviously does not generate correct translation files. lupdate would have to put all the possible strings in the *.ts files
It is possible that Qt already has a translation file for you there. You would have to add it to your application though.
"possible"? And where would I find this file?
Already looked there. There are translation for Qt programs.
Are you sure of your advice? From the beginning it looks like you just throw a guess and hope it will answer my question. This is not how you help people.
Now the post count is increasing and someone who may actually know the answer won't event look at it.
(Sorry if it sounds mean, I don't want to be rude)
Qt has pretranslated a bunch of things for their own widgets. You can (and should) add that translation file to your application if you use translations. What I'm unsure about is whether the language names are translated, but if they are, this is the place to find them.
Ok, maybe I should add manually the few language names I know I will be using.
I think there is a trick to add string that lupdate can find.
Yes, "Q_TR_NOOP and Q_TRANSLATE_NOOP":http://doc.trolltech.com/latest/linguist-programmers.html#using-qt-tr-noop-and-qt-translate-noop
No, I would not call those macros a "trick". I was referring to the last section of this:
When tr() is Not Enough @ #if 0
qApp->translate( "CustomerDB", "Agency" );
qApp->translate( "CustomerDB", "Company" );
qApp->translate( "CustomerDB", "Foreign" );
qApp->translate( "CustomerDB", "International" );
QLocale::nativeLanguageName() is close to what you're looking for. It returns an endonym for the language so you'll be able to build a list like ( "English", "Deutsch", "Русский", ... )