QT -= guiTARGET = ConsoleTestCONFIG += consoleCONFIG -= app_bundleTEMPLATE = appTRANSLATIONS = myapp_ru_RU.tsSOURCES += main.cpp
C#include <QtCore>#include <QtCore/QCoreApplication>#include <QTextCodec>#include <QTranslator>#include <iostream> int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTranslator myappTranslator; bool res = myappTranslator.load("myapp_" + QLocale::system().name()); a.installTranslator(&myappTranslator); std::cout << QObject::tr("Hello!").toStdString() << std::endl; return a.exec();}
XML<?xml version="1.0" encoding="utf-8"?><!DOCTYPE TS><TS version="2.0" language="ru_RU"><context> <name>QObject</name> <message> <location filename="main.cpp" line="18"/> <source>Hello!</source> <translation>Привет!</translation> </message></context></TS>
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("IBM866"));QTextCodec::setCodecForTr(QTextCodec::codecForName("IBM866"));
Cstd::cout << QObject::tr("Hello!").toStdString() << std::endl;
CqDebug() << QObject::tr("Hello!");
.... QCoreApplication app(argc, argv);#ifdef Q_OS_WIN32 QTextCodec::setCodecForLocale(QTextCodec::codecForName("IBM 866"));#endif QTranslator translator;...
C++ (Qt)QTextStream out(stdout);out.setCodec(...);out << QObject::tr("Привет!");