2

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?

1 Answer 1

1

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.

2
  • 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
    Commented Jun 8, 2012 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. Commented Jun 8, 2012 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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