#include <QtGui/QApplication>#include <QTextCodec>#include <QTranslator>#include <QLocale>#include "mainwindow.h"int main(int argc, char *argv[]){ QApplication app(argc, argv); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTranslator qtTranslator; if (!qtTranslator.load("test_" + QLocale::system().name())) printf("error!\r\n"); printf("%s\r\n", (const char *)QLocale::system().name().toUtf8()); app.installTranslator(&qtTranslator); MainWindow w; w.setWindowTitle(QObject::tr("Фигня")); w.show(); return app.exec();}
TARGET = testTEMPLATE = appSOURCES += main.cpp\ mainwindow.cppHEADERS += mainwindow.hFORMS += mainwindow.uiTRANSLATIONS = test_en.tsCODECFORSRC = UTF-8CODECFORTR = UTF-8
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE TS><TS version="2.0" language="en_US"><defaultcodec>UTF-8</defaultcodec><context> <name>QObject</name> <message> <location filename="main.cpp" line="10"/> <source>Фигня</source> <translation>Fignya</translation> </message></context></TS>
export LANG=en_US.UTF-8
QTranslator qtTranslator; if (!qtTranslator.load("test_en")) printf("error!\r\n"); app.installTranslator(&qtTranslator);
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));