Doesn’t update language when I select another one in the language dropdown

Thanks for the report! I added a few lines that check if the &language= part of the URL changes. If it does, it reloads the page. I don't actually notice any real functional difference from the default behaviour, except making the script work as it should, and fixing the directionality issue as a bonus, so this should probably have been the default behaviour of Special:Translate in the first place. Do you know if there is a Phabricator task for the underlying issue already?

Jon Harald Søby (talk)02:06, 28 November 2021

A real difference is that language switching is much slower now, which is annoying. Can’t you just reload the gadget instead of the whole page?

Yes, I remember having seen a Phabricator ticket for the directionality issue, but I couldn’t find it right now. Anyways, that should be fixed in Translate, not in this gadget at the price of annoying reloads.

Tacsipacsi (talk)09:41, 28 November 2021

I'm a bit confused. How often do you need to switch languages while on Special:Translate?

Anyways, "just reloading the gadget" isn't really that easy at the moment, because the gadget has already altered the HTML of the source message once it's been loaded, so doing that again would require keeping the original source message somewhere. Not impossible, but not a simple fix either – reloading the entire page is much easier.

Jon Harald Søby (talk)22:40, 28 November 2021

Not that often, but that’s just because I don’t care enough about the formal address Hungarian translation (hu-formal). ;)

It may not be easy to change the already altered HTML, but there’s a solution: you don’t alter the HTML using the wrong language in the first place. :) Actually, I think you don’t even have to check the URL parameter, you can just query the target language when processing the message, and you’ll get the right language, even if there are messages with multiple target languages on the page (I don’t think it’s possible right now, but who knows, maybe it’ll be one time). Assuming $element holds a jQuery object for the <span class="sourcemessage">, you can get the target language with

$element.parents( '.tux-message-editor .editcolumn' ).find( 'textarea' ).attr( 'lang' )
Tacsipacsi (talk)23:52, 28 November 2021

@Tacsipacsi: I've submitted gerrit:745997 to add a hook when the language changes, which should hopefully make this a lot easier. I've also made some preparatory changes to how the processSourcemessage() function in the script works, so that it shouldn't be a problem to process the source message even after it has been altered. (This was also done to make the script update the markup immediately after saving a change instead of just after a reload, as mentioned in the other thread.)

Jon Harald Søby (talk)23:29, 14 December 2021

This issue should be solved now, Tacsipacsi! Feel free to test it out. :-)

Jon Harald Søby (talk)02:07, 14 January 2022