0

There's a Qt/QML app that uses qsTr() for localizing it's strings in .qml files and a Qt plugin (loaded via QPluginLoader) that does the same.

Text { text: qsTr("back") }

Suppose there's a same string that in app has one meaning and in the plugin it has another meaning. Both strings used in the same context (like a component MyWindow.qml)

// plugin: "back" -> go back
// app:    "back" -> not front

When we install different QTranslator into the app, they are looked up in the reverse order which means either app translation gets overwritten by plugin OR plugin translation gets overwritten by app (not to mention when 2 plugins can overwrite one another).

QCoreApplication::instance()->installTranslator(appTranslator);
QCoreApplication::instance()->installTranslator(pluginTranslator);

How to break this loop so in app it uses app translation and in plugin it uses plugin's translation?

Ribtoks
  • 6,634
  • 1
  • 25
  • 37
  • Is that plugin based on a standard Qt plugin or is it a custom plugin? is a qml plugin? – eyllanesc Aug 10 '21 at 06:23
  • @eyllanesc, it is a standard Qt plugin, as defined [here](https://doc.qt.io/qt-5/plugins-howto.html). Plugin has some UI components in it's `qrc`. – Ribtoks Aug 10 '21 at 06:33
  • What class does it inherit from (QAccessibleBridgePlugin, QImageIOPlugin, etc)? I want to create a test and I need info, if you could provide an MRE then that would be great. – eyllanesc Aug 10 '21 at 06:34
  • @eyllanesc What class does what inherit from? It is a raw bare-bones qt plugin which inherits from it's own interface and declares Q_PLUGIN_METADATA as written [here](https://doc.qt.io/qt-5/plugins-howto.html#the-low-level-api-extending-qt-applications). – Ribtoks Aug 10 '21 at 07:49
  • I do not reproduce the problem, my test project: https://github.com/eyllanesc/stackoverflow/tree/master/questions/68721681 – eyllanesc Aug 10 '21 at 09:09
  • @eyllanesc you cannot reproduce because `app.ts` and `plugin.ts` have different context. If your app will have a UI component called `MyWindow.qml` and your plugin will have the same component, both with strings translated differently, then you will repro the issue. – Ribtoks Aug 10 '21 at 13:26
  • 1
    That detail is important, one way to differentiate the translations is the context and that is the cause of the problem. My recommendation: Don't use the same context. – eyllanesc Aug 10 '21 at 17:07

0 Answers0