[Interest] Support of russian language in QJson-classes
Till Oliver Knoll
till.oliver.knoll at gmail.com
Tue Aug 20 12:56:24 CEST 2013
Am 19.08.2013 um 14:29 schrieb Dmitrii Volosnykh <dmitrii.volosnykh at gmail.com>:
> Here is example code I use:
> #include <QtCore/QCoreApplication>
> #include <QtCore/QtDebug>
> #include <QtCore/QFile>
> #include <QtCore/QJsonDocument>
> #include <QtCore/QJsonObject>
> int main(int argc, char *argv)
> QCoreApplication a(argc, argv);
> QJsonObject object;
> const QString& test = QString::fromUtf8("тесто");
> object[test] = test;
> QJsonDocument document(object);
This off course assumes that a) your source file is stored in UTF8 (or Unicode?) as well and most importantly b) that your compiler is actually able to process UTF8 (Unicode) sources.
Since your source seems to compile and you say that you get at least one value correct (the actual "value") in the generated text file and hence the problem only affects the "key" there probably follows that a) and b) hold and the problem is probably somewhere else.
However I would still recommend that when supporting i18n you /always/ use english (or any other language where the "US-ASCII" charset is sufficient, that is: no äöü and é etc. characters) for "user visible strings" in your source and that you then use the Qt i18n mechanism to translate your strings (which can then be really stored as UTF-16).
Assuming that your QJsonDocument construction happened in an actual QObject derived class (*) then you could say:
const QString& test = tr("rectangle");
object[test] = test;
The call to QObject::tr() would then lookup the actual (UTF16 encoded) QString, according to the currently active QTranslator.
Off course don't forget to set the actual charset (at least UTF8) when generating the text file (I think you did - can't remember...).
(*) If you don't have a QObject derived class, no worries: check the i18n Qt docs about translating "non-QObject classes".
More information about the Interest