, instance()
this->currentTranslator = new QTranslator(instance());
, , :
RESOURCES += \
resources.qrc
(resources.qrc - , . , .)
resources.qrc? , translation/? :
<RCC>
<qresource prefix="/">
<file>translation/YourProjectName_en.qm</file>
</qresource>
</RCC>
YourProjectName_en.qm translation/.
, ;:
main.cpp:
QApplication app(argc, argv);
QApplication::setApplicationName("MyApplication");
QApplication::setApplicationVersion("4.4");
QApplication::setOrganizationName("FUBAR");
QApplication::setOrganizationDomain("www.fu.bar");
QTranslator translator;
translator.load(app.applicationName() + "_" + QLocale::system().name(), ":/ts");
app.installTranslator(&translator);
resources.qrc:
<RCC>
<qresource prefix="/">
<file>resources/pixmaps/exit.png</file>
<file>ts/MyApplication_en.qm</file>
<file>ts/MyApplication_es.qm</file>
</qresource>
</RCC>
in MyApplication.pro:
TRANSLATIONS += \
ts/MyApplication_en.ts \
ts/MyApplication_es.ts
RESOURCES += \
resources.qrc
win32 {
RC_FILE = win32.rc
}
OTHER_FILES += \
win32.rc \
TODO.txt
:
MyApplication
βββ resources
β βββ pixmaps
β βββ ...
βββ (sources are here)
βββ MyApplication.pro
βββ resources.qrc
βββ TODO.txt
βββ ts
β βββ MyApplication_en.qm
β βββ MyApplication_en.ts
β βββ MyApplication_es.qm
β βββ MyApplication_es.ts
βββ win32.rc
, .
Edit:
, , . ,
if (this->currentTranslator->load(":/translation/myApp_en.qm"))
if (this->currentTranslator->load("myApp_en.qm", ":/translation/"))