[PyQt] Switching languages dynamically example

Giovanni Bajo rasky at develer.com
Wed Dec 8 15:27:12 GMT 2010


On mer, 2010-12-08 at 15:26 +0100, Hans-Peter Jansen wrote:
> Hi,
> 
> I found a Qt example of switching languages dynamically here:
> 
> http://www.qtcentre.org/wiki/index.php?title=Dynamic_translation_in_Qt4_applications
> 
> In addition to the original version, the PyQt version does try to 
> preselect the language intelligently to the current system default.
> 
> Since it isn't completely trivial, it might be a good addition for the 
> contribution section of PyQt?
> 
> Since the original version didn't carry any license, I've put it under 
> the DWTFYW V2 public license (http://sam.zoy.org/wtfpl/COPYING).

Just for discussion...

I would love a library that does this for me without me having to do
anything to support it; writing code that moves translatable string into
a separate function is IMO less readable because strings are useful in
reading Qt UI construction code; also it forces to declares a lot of
useless instance attributes like label1,label2,label3,label4, which are
error prone to match with the correct strings, and also wastes memory
(more so in larger applications) by causing larger __dict__ instances.

I think of a library that walks the QWidget hierarchy, finds all
standard widgets, fetches their current text, translates it, and sets it
back into the widget. For completely custom widgets, there could be an
API like retranslate(), but at least standard dialogs, main windows,
toolabars, tooltips, etc. wouldn't need such a treatment.

IMO it has to be possible to do something like this, it's just that most
people don't think it's worth it, probably :)
-- 
Giovanni Bajo      ::  Develer S.r.l.
rasky at develer.com  ::  http://www.develer.com

Blog: http://giovanni.bajo.it
Last post: Compile-time Function Execution in D



More information about the PyQt mailing list