Implementing "translation in context"

Dashamir Hoxha dashohoxha at gmail.com
Fri Sep 18 08:17:16 BST 2015


Hi,

I have implemented what I call "translation in context" in this application:
 - http://v.btranslator.org/
 - http://v.btranslator.org?proj=ICT_de&lng=de
<http://v.btranslator.org/?proj=ICT_de&lng=de>
 - http://v.btranslator.org?proj=ICT_fr&lng=fr
<http://v.btranslator.org/?proj=ICT_fr&lng=fr>
 - http://v.btranslator.org?proj=ICT_it&lng=it
<http://v.btranslator.org/?proj=ICT_it&lng=it>

It works like this: when the user makes a Ctrl+Click on a string/translation
anywhere on the UI, a browser tab/window is opened automatically
with the correct url in the translation server (web application), where he
can
give a translation or a new suggestion for the selected string.
Of course, for a normal Click  the UI works as normally it should.

The funny thing is that this is a mobile application and in a mobile
application
you cannot make a Ctrl+Click. But for translation purposes it can be opened
in a desktop browser. Anyway, it serves to illustrate/demonstrate the idea
of "translation in context" (or whatever it can be called).

The implementation details are not so complicated. This app uses a
gettext-like localization system, where there is a JavaScript function `_()`
that is used to mark the strings that need to be translated, like this:
_("string")
It returns the corresponding "translation", which is then used in the
application.

I have overridden the function `_()` so that it does not return just the
plain
"translation", but it returns instead a decorated translation like this:

    <span class="gettext" sguid="id-of-the-string">translation</span>

See:
https://github.com/FreeSoft-AL/vocabulary/blob/gh-pages/js/_app/translate_in_context.js#L43-L54

Then I assign with jQuery an event-handler for the event Ctrl+Click
to all the elements of the class "gettext". This event handler gets the
id of the string and opens a tab with the proper URL for translating that
string
in the translation server.
See:
https://github.com/FreeSoft-AL/vocabulary/blob/gh-pages/js/_app/translate_in_context.js#L82-L98

My question is:
Is it possible to implement something like this for KDE (Qt) applications?
I think it would be a great feature for improving the quality of
translations
and for helping users to give feedback and suggestions to the translators.

The most difficult part in my opinion is how to mark (or decorate)
the translated string, so that it can respond to a Ctrl+Click event.
Then you can construct the correct url and open it in browser.
It can be designed to work with B-Translator, or Pootle, or some other
online translation system. But maybe it can also work with local desktop
applications like Virtaal, Lokalize, etc.

Does anybody has detailed/deep knowledge about Qt and about the translation
system in KDE, so that he can give any hints about how to solve this
problem?

Thanks,
Dashamir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20150918/48a07522/attachment.htm>


More information about the kde-core-devel mailing list