void FooClass::someFunc(){ QString translatedText = QCoreApplication::translate("FooClass", QT_TRANSLATE_NOOP("FooClass", "А text to be translated")); ...}
QString QObject::tr ( const char * sourceText, const char * disambiguation = 0, int n = -1 ) [static]
C++ (Qt)#if 0class MainWindow // for tr{ Q_OBJECT#endif void someFunc(){ QString translatedText = MainWindow::tr( "А text to be translated" ); ...} #if 0};#endif
C++ (Qt)#if 0#define tr(x) xclass FooClass // for tr{ Q_OBJECT#endif void FooClass::someFunc(){ QString translatedText = QCoreApplication::translate("FooClass", tr("A text to be translated")); ...} #if 0#undef tr};#endif
void FooClass::someFunc(){ QString translatedText = QCoreApplication::translate("FooClass", tr("A text to be translated")); ...}
void FooClass::someFunc(){ QString translatedText = tr("A text to be translated"); ...}
C++ (Qt)#if 0class FooClass // for tr{ Q_OBJECT#endif #define tr(s) QCoreApplication::translate("FooClass", s); void FooClass::someFunc(){ QString translatedText = tr("A text to be translated"); ...} #undef tr#if 0};#endif
class FooClass // for tr{#if 0 Q_OBJECT#endif void someFunc();};#define tr(s) QCoreApplication::translate("FooClass", s)void FooClass::someFunc(){ QString translatedText = tr("A text to be translated");}#undef tr
class MyClass { Q_DECLARE_TR_FUNCTIONS(MyClass) public: MyClass(); ... };
#pragma once#include <QtCore/QString>#define Akon_QtCore_DECLARE_TR_FUNCTIONS(ClassName) \static QString tr(const char *sourceText, const char *disambiguation = 0); \static QString trUtf8(const char *sourceText, const char *disambiguation = 0); \static QString tr(const char *sourceText, const char *disambiguation, int n); \static QString trUtf8(const char *sourceText, const char *disambiguation, int n);
#pragma once#include <QtCore/QCoreApplication>#define Akon_QtCore_IMPLEMENT_TR_FUNCTIONS(ClassName) \QString ClassName::tr(const char *sourceText, const char *disambiguation) \{ \ return QCoreApplication::translate(#ClassName, sourceText, disambiguation); \} \QString ClassName::trUtf8(const char *sourceText, const char *disambiguation) \{ \ return QCoreApplication::translate(#ClassName, sourceText, disambiguation, \ QCoreApplication::UnicodeUTF8); \} \QString ClassName::tr(const char *sourceText, const char *disambiguation, int n) \{ \ return QCoreApplication::translate(#ClassName, sourceText, disambiguation, \ QCoreApplication::CodecForTr, n); \} \QString ClassName::trUtf8(const char *sourceText, const char *disambiguation, int n) \{ \ return QCoreApplication::translate(#ClassName, sourceText, disambiguation, \ QCoreApplication::UnicodeUTF8, n); \}