Jump to content

MediaWiki talk:Gadget-SidebarTranslate.js

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

This is the current revision of this page, as edited by Kuldeepburjbhalaike (talk | contribs) at 09:53, 11 July 2023 (Bug: displaying repeated language links). The present address (URL) is a permanent link to this version.

(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
[edit]

Hi Equazcion, Legoktm, Edokter,

Apparently this gadget overrides the Compact Language Links beta feature when both are enabled.

Would any of you mind trying making them work together?

Thanks! --Amir E. Aharoni (talk) 12:38, 16 May 2016 (UTC)[reply]

OK, so there's a message here at the top that asks to discuss changes in the talk page before changes, which is what I did back in May, but there's no reply :/
Some things in this gadget break when used together with the Compact Language Links beta feature, and I'm going to attempt to fix them myself.
Initially, I don't plan to make any functional changes, but only to fix the JS errors that are caused by completely rewriting the link elements. They should rather be kept as-is, with the lang attribute, even though the name is written in English, because this attribute is used by other scripts. The language name in English should be inserted in its own <span> tag with the lang="en" attribute.
Mentioning Equazcion, Legoktm and Edokter again in the hope that somebody will notice... --Amir E. Aharoni (talk) 09:42, 10 September 2016 (UTC)[reply]
I'm working on my version in a "branch" of sorts at User:Amire80/Gadget-SidebarTranslate.js. --Amir E. Aharoni (talk) 11:35, 10 September 2016 (UTC)[reply]
TL;DR: Please review User:Amire80/Gadget-SidebarTranslate.js. It should resolve all the issues with Compact Language Links, and it fixes several other bugs along the way. If it works for you, please replace the gadget code with that version, but remove the style (marked with XXX).
OK, so here's my report of working on this over the weekend:
The issue with Compact Language Links is that it produces a JS error: "Cannot read property 'toLowerCase' of null TypeError: Cannot read property 'toLowerCase' of null". The message is different in Firefox, but the reason for it is the same: It is trying to apply a toLowerCase method on the lang attribute, which doesn't exist on the Google Translate link. A full solution for this is suggested in https://phabricator.wikimedia.org/T135378 . Until it's resolved, I worked around it by applying a semi-invalid "tokipona" language code to the Google Translate links. It's a very weird and undesirable hack, but it resolves the issue for now.
Some other issues that I resolved:
  • The code is refreshed according to the Wikimedia JavaScript coding conventions: whitespace, $ signs for jQuery variables, triple-equal signs.
  • The issue with the be-x-old language is resolved. Its name had an invisible control character. It is now properly handled by hardLangs.
  • The Google Translate link is now in a separate variable, which is more readable and easier to manipulate.
  • The lang and style attributes are not removed from the list items. It was mostly unnecessary and it broke ULS. The English language name is now in a separate element with the "en" lang. It's also a bit weird, but gadgets are weird to begin with :)
  • Bhojpuri and South Azerbaijani are added to hardLangs.
With all these changes applied, the gadget works together with Compact Language Links enabled, shows all the language names in English and doesn't produce JS errors.
Since this affects hundreds of users, it would be nice if somebody could review this. If it looks OK, please replace the gadget code with the version at User:Amire80/Gadget-SidebarTranslate.js, but remove the line with XXX, which applies a style, because when this code is used as a gadget that line is unnecessary.
Thank you. --Amir E. Aharoni (talk) 09:55, 11 September 2016 (UTC)[reply]
I removed the extra-weird "tokipona" hack, because it didn't work well anyway and replaced it with a CSS solution and using the standard "en" language code. It's still a hack, but a relatively cleaner one. Merging https://gerrit.wikimedia.org/r/#/c/309731/ is still a cleaner solution. --Amir E. Aharoni (talk) 09:41, 12 September 2016 (UTC)[reply]

... Aaaaand, because I'm impatient, I just applied the changes :)

Nothing seems to be broken, but if something does break, please revert, accept my apology, and let me know. Thanks!

These people may be curious: Equazcion, Legoktm, Edokter, Runab WMF, Whatamidoing (WMF), Elitre (WMF). --Amir E. Aharoni (talk) 11:06, 14 September 2016 (UTC)[reply]

Titles with en dash

[edit]

The bug reported at User talk:Equazcion/SidebarTranslate#Titles with en dash is still in the gadget. PrimeHunter (talk) 00:34, 5 June 2017 (UTC)[reply]

Interface-protected edit request on 10 February 2020

[edit]

For background, see the previous section and phab:T244715

Please change the value of LangReg to /(.* – )?(.*)/ (my proposed fix) or /(.*? – )?([^–]*)/ (Dcljr's proposed fix in 2016). I do not know which is more suitable. GZWDer (talk) 15:31, 10 February 2020 (UTC)[reply]

@GZWDer: I've implemented your fix (I don't think Dcljr's works). Thanks, Writ Keeper  18:57, 10 February 2020 (UTC)[reply]

Bug: Need to remove lang tags

[edit]
Screenshot showing incorrect fonts used in Firefox

Hi, I'd like to report a bug that I've noticed using Vector 2022. In the new skin, each of the links includes a 'lang' attribute indicating the language of the link's destination (e.g. the HTML for a link to Chinese Wikipedia looks like this: <a class="autonym" dir="ltr" href="https://zh.wikipedia.org/wiki/..." title="... – 中文" lang="zh">Chinese</a>).

Because this gadget changes all the links to be in English, the 'lang' attribute is no longer correct and needs to be stripped out. This incorrect use causes display issues, as some browsers use the 'lang' attribute to decide which font to use. I've included a screenshot showing how the words "Chinese" and "Korean" are in a different font to the rest of the page. This is because my browser (Firefox 109.0 on Ubuntu 22.04.1) uses a different font to render Chinese and Korean text, and the 'lang' attribute is causing my browser to incorrectly believe those words are written in Chinese and Korean respectively. Thanks, IagoQnsi (talk) 23:57, 21 January 2023 (UTC)[reply]

[edit]
Gadget-SidebarTranslate Bug

This gadget displaying repeated language links of 1 language KuldeepBurjBhalaike (Talk) 09:44, 11 July 2023 (UTC)[reply]