PDA

View Full Version : What is needed to set language for resource (qrc) to use?



neuronet
27th January 2015, 03:51
(Note I am working in Python (PySide))

I have something like the following in my .qrc file (some other stuff is deleted):

<!DOCTYPE RCC>
<RCC version="1.0">

<qresource>
<file>qt_fr.qm</file>
</qresource>

<qresource>
<file alias="index.html">help/index.html</file>
</qresource>

<qresource lang="fr">
<file alias="index.html">help/index_fr.html</file>
</qresource>

</RCC>

To my chagrin, I'm not sure how to activate the 'fr' language trigger so that the correct alias is chosen, and index_fr.html is used.

What I have right now in main() is:


locale = 'fr'
app = QtGui.QApplication(sys.argv)
qtTranslator = QtCore.QTranslator()
if qtTranslator.load("qt_" + locale, ":/"):
app.installTranslator(qtTranslator)
form = HelpForm("index.html")
form.show()
sys.exit(app.exec_())

Where HelpForm basically displays index.html. But even though I have 'fr' as my locale, it is still just showing me the index.html file, not index_fr.html, as I thought I had asked for in the qrc file (which successfully compiled and I loaded the resource_rc.py file in my module).

Can anyone help me find the minimal requirements to get this to work?

anda_skoa
27th January 2015, 07:58
You don't seem to set the locale, so Qt will still see whatever the system has set.

See QLocale::setDefault().

Cheers,
_

neuronet
27th January 2015, 13:48
You don't seem to set the locale, so Qt will still see whatever the system has set.
See QLocale::setDefault().

That fixes it. For Python users, I just added the following (recall locale='fr'):

newLocale = QtCore.QLocale(locale)
QLocale.setDefault(newLocale) And it works.