Is there a way to add a language to QTranslator when reimplementing the translate method?
-
I consider subclassing QTranslator in some test cases, so that I can simply put some test data in that subclass reimplementing the translate method.
In that automated test, I do not want to have the overhead of fiddling around with ts and qm files. I thought that it would be easier to simply use a reimplemented translate method.
However, I wonder how I make my own subclassed translators then aware of the language. As far as I see I can only do that untimately when the do_load is called in the private qtranslator.
So I assume that it is not possible at all to add language information for my reimplemented translate method without providing an actual qm file.
Do I overlook something?
-
I was gonna use them in a language switching mechanism, where I provided several QTranslators to that would then have been installed dynamically if they matched the desired language.
Never mind, I will prime the translators with a prebuilt set of qm files, that give them the initial language and then adding my testing strings separately. Those test qm files do not need to contain the actual strings. The language information is sufficient.
My language switcher can then determine the language from that and still use the custom translate method.
-
@devjb You can simply override QTranslator::translate(): https://doc.qt.io/qt-6/qtranslator.html#translate
-
@Christian-Ehrlicher Yeah, that is entirely what I mentioned in my very first sentence in my post.
However, I then can only pass context, source, disambiguation and n as parameters.
And thus, you cannot determine which language that QTranslator provides.
Meaning if you iterating over a number of QTranslators, you cannot get the language from the custom ones. -
@devjb Why you want to know it? And since you instantiate the translator and also derive from QTranslator you also know it's language.
-
I was gonna use them in a language switching mechanism, where I provided several QTranslators to that would then have been installed dynamically if they matched the desired language.
Never mind, I will prime the translators with a prebuilt set of qm files, that give them the initial language and then adding my testing strings separately. Those test qm files do not need to contain the actual strings. The language information is sufficient.
My language switcher can then determine the language from that and still use the custom translate method.
-