Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having issues with the translation of my Qgis plugin.

static const QString sName = QObject::tr( "Editeur Monoscopique 3D" );

MyClass::MyClass( QgisInterface * theQgisInterface ): QgisPlugin( sName) {

QSettings tSettings;
QString qsUserLocale = tSettings.value( "locale/userLocale", "" ).toString();

    if ( ( qsUserLocale != "fr_FR" ) && ( qsUserLocale != "fr" ) )
            QString qsTranslationPath = ":/prefix/en_US.qm" ;
            QFileInfo tFileInfo (qsTranslationPath) ;
            if (tFileInfo.exists())
                    //QTranslator translator;
                    if (m_tTranslator.load( "en_US", ":/prefix" ) )


The problem is that sName is declared before installing the translator
qApp->installTranslator(&m_tTranslator); and so its text is not translated !
How can I fix this?

share|improve this question

You need to implement name() anyway, so I would consider sName as the internal name and set up another member value to hold the user-visible name. Set its final value after installing the translator and most cases should be covered.

share|improve this answer
The problem is that Qgis plugin manager takes what is held in "sName" to be displayed so even if I set up another member value to hold the name it won't be taken to display by the plugin manager ! – QgisTn Jun 8 '12 at 8:56
I suggest you file a bug/feature request on then. C++ plugins bundled with QGIS don't have this problem, since they use the main QGIS translation domain. You could maybe also hack around the issue by abusing the non-const return-by-reference name() variant, but I wouldn't advise it. – lynxlynxlynx Jun 8 '12 at 12:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.