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
Core developersDocumentation writersMoodle HQParticularly helpful MoodlersPlugin developersPlugins guardiansTestersTranslators

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: -
Picture of Dashamir Hoxha
Re: Translation in context
 

Hi David.

I could not find enough time to jump into this issue (implementing "in-context translation" plugin). But I am thinking that maybe this can be a good project for the next GSoC.

What should I do to promote this project idea? Should I start by creating a new feature request on the tracker?

 
Average of ratings: -
Picture of David Mudrák
Re: Translation in context
Core developersDocumentation writersMoodle HQParticularly helpful MoodlersPlugin developersPlugins guardiansTestersTranslators

Should I start by creating a new feature request on the tracker?

No. You should start searching if it has been already reported smile If you can't find anything (I believe it must have been raised before), please feel encouraged to create a new one. Thanks!

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

I couldn't find anything and I tried to create a new one. But the interface refused to create it saying that I should search first (why does it think that I did not search?!).

Anyway, here is the description of the feature that I tried to create:

-----------8<------------

Translation in context means that you can see where the translated string is being used, and you can correct it in place. It is very important for the accuracy of translations.

There are a couple of ways for implementing it, which are discussed here: https://moodle.org/mod/forum/discuss.php?d=347843

The most feasible one is the David's proposal to implement it by a plugin (block or admin tool) that does the following:

  1. The plugin provides a custom string manager class to track the strings used at the page (function `get_string()` could track all strings used at the current page).
  2. This list of strings and their (current) translations can be appended to the page.
  3. At the footer of the page (or on the menu) will appear a link that says "Edit translations on this page".
  4. When this link (or menu item) is clicked, an AJAX form or JS overlay should appear, which allows to edit the translations of these strings.
  5. When changes are saved, the page is refreshed and the new translations appear on it.
  6. Translation changes made over time should be able to be exported and to be uploaded to the server of translations (lang.moodle.org) for review and acceptance by language admins.

The last point can be done from the admin interface of the plugin. On the admin interface can also be a switch to enable/disable this in-context translation feature (maybe for performance reasons).

--------------->8-------------------------

Could you please create it? And feel free to make the additions/changes that you find suitable.

By the way, the organization applications for GSoC start on Jan 4 (https://developers.google.com/open-source/gsoc/timeline)

 
Average of ratings: -