uwerat / qskinny

A lightweight framework on top of the Qt scene graph and only few classes from Qt/Quick. It is usable from C++ and/or QML.
1.45k stars 293 forks source link

How to switch languages #417

Closed hestrro closed 2 months ago

hestrro commented 2 months ago

I can not change the language by QskWindow's setlocal()

uwerat commented 2 months ago

By setLocale you change the locale of the window and all QskControls in the object hierarchy below this item, that do not have a locale, that has been set explicitly. Note, that you can change the locale of the complete application by QLocale::setDefault. You can adjust a control to the new locale by implementing an event handler for QEvent::LocaleChange or by connecting to the QskControl::localeChanged signal.

Changing the language field of the locale might have an impact on library functions, that are i18n aware ( f.e printf ) - but it does not change the message catalog of your user interface automatically. If this is what you are looking for: have a look at https://doc.qt.io/qt-6/i18n-source-translation.html.

Unfortunately a control ( f.e a QskTextLabel ) can't retranslate itself automatically as the index of this text in the message catalogs gets lost when passing it as QString. Here QML has an advantage as its runtime engine knows them. I thought about introducing QskText ( QString + index ) to automatic retranslations possible - however this is a rather complex change of the API.