General developer forum

Translation in context

 
Picture of Dashamir Hoxha
Translation in context
 

In this page I found some nice ideas about translation in contexthttps://docs.moodle.org/dev/Languages_subsystem_improvements_2.0

Since the page is a bit long, I am quoting here the relevant parts:

[begin_quote]

From Martin in Dev chat: if you want crazy ideas, how about get_string returns some special tags and those tags get converted to ajax on the GUI so that translators can translate directly in the main Moodle GUI?

What a cool idea. Could be a special mode you have to turn on in the admin screens. Perhaps even if you turned this mode on, it would still only be active for people with certain roles, or perhaps when it was turned on, it would have to apply to all roles, so that you could edit strings for not-logged-in users. Anyway, when this mode was on, it would:

  1. Adds <span class="moodle-lang-string" id="lang_string|admin|langedit">Language editing</span> around each string on the page - to use one example.
  2. $PAGE->requires->js an extra JS file that adds an on-click handler to all such spans, so that when you click on it, it pops up the language editing UI in a YUI dialogue.
David Mudrak 14:07, 23 November 2009 (UTC): the solution based on wrapping <span> around every string was already considered and dropped. It may badly break XHTML as the string itself may appear as a value of an HTML tag's attribute: 
&lt;img title="&lt;span class="moodle-lang-string" ...
. We are unable to say the scope where the string will appear.
David's contra-proposal: get_string() could track all strings used at the current page and the AJAX form to edit them all could be rendered before the footer(). Or 'Edit system text on this page' link would appear there.

[end_quote]

Both of them are very good ideas. The first one is not impossible if you add an additional parameter to get_string() which tell it something about the scope where it is being used.

The second idea (David's contra-proposal) is a very nice one as well and apparently it does not have any technical difficulties for being implemented. What happened to it? Did it get implemented?

I think that translation in context is very important for the accuracy of translations.

 
Average of ratings: -
Picture of Dashamir Hoxha
Re: Translation in context
 

As an example of the first idea, I have implemented translation in context in this small application:

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.

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>


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.

I should note that there are actually two translation functions: `_()` and `_t()`. The first one returns a decorated translation, while the second one allways returns the original undecorated translation. It is the responsibility of the application itself to use the appropriate function. For example, wherever a decorated translation could break the HTML syntax, it should use the second function.

 
Average of ratings: -
Picture of Dashamir Hoxha
Re: Translation in context
 

If I wanted to implement the David's idea, how and where should I start? For example, can it be implemented as a plugin/module or it has to make patches to the core system? I know almost nothing about the Moodle structure.

 
Average of ratings: -
Picture of David Mudrák
Re: Translation in context
Group Core developersGroup Documentation writersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Plugins guardiansGroup TestersGroup Translators

Hi Dashamir.

Thanks for the reminder. The in-context translation is an issue raised often in moots and other places and we started to talk about it again in the HQ. Actual work on it may be a bit challenging without wider knowledge of Moodle development, but also a good opportunity to dive into it smile

Yes, I think it is doable cleanly via a plugin (a block or admin tool should fit well). Let the plugin provide a custom string manager class to track the strings used at the page, and then the interface on the page (I would prefer JS overlay rather than the footer these days) to translate strings.

 
Average of ratings: -