[Qtscript-bindings] Making scripts translatable

Kent Hansen khansen at trolltech.com
Thu Aug 28 12:33:00 CEST 2008


Girish Ramakrishnan wrote:
> I haven't spent a lot of time thinking about this, but here goes.
>
> 1. It should behave just like Qt's i18n system. IOW, it should look into
> .qm files, translators should be able to use linguist and all that. tr
> should be able to get the strings out the script in put it in .qs.
>   

Yup.
> 2. Scripts are (to me) like plugins. Which means, plugin writers might
> want to provide their own translation file for their script. Hence, we
> need a QTranslator per script. If not, we fallback to application's
> translator. QTranslator for the script should be settable in C++ and script.
>   

Why settable in script? (Well, if you have imported the Qt bindings you 
can do it of course... :-) )
> 3. We need context for script strings. So, a mechanism to set the
> default context for strings in script and C++ and for lupdate. Also,
> provide a translate() for non-default context. Maybe, we can have some
> fancy way of detecting context from function names but I fear this might
> lead to conflicts with c++ context (in the case, where we run lupdate on
> a project that has embedded scripts).
>   

Yes, the context is the tricky part. Currently I'm using the script 
filename (without the path), which means the C++ dev has to remember to 
pass the filename as the second argument to QScriptEngine::evaluate() 
(otherwise the context will be the empty string). You might get 
conflicts then if you have several scripts with same name that reside in 
different subdirs. The only alternative I can think of is to make a 
setContext() function available to the script, like you mention. Maybe 
use the filename as default, and provide setContext() so you can 
explicitly set it, how's that for reasonable behavior.
> Girish
>   

Thanks Girish, this feedback is reassuring. :-)

Kent



More information about the Qtscript-bindings mailing list