Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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" ) )
                            qApp->installTranslator(&m_tTranslator);
            }
    }

}

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
add comment

1 Answer

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 hub.qgis.org/projects/quantum-gis 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
add comment

Your Answer

 
discard

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.