MediaWiki talk:Gadget-TranslationAdder.js
Usage
[edit]General
[edit]After you have made an edit with one of the installed tools (instructions for which are listed below) a blue box appears in the top left corner containing:
- Save page
- Undo
- Redo
No changes made to the page are recorded until you press Save.
Editing translations
[edit]You should see a line at the end of the table something like
- Help : Preview translation More
◻ masc. ◻ fem. ◻ neuter ◻ common gender ◻ plural
- The first box is the ISO 639-1 or ISO 639-3 language code (for common languages you can put in the language name, and it will give you the code).
- The second box is the translation to add. This should normally be one word, if you attempt to add many separated by commas you will get a warning. If you want to request a translation set the word to
{{trreq}}
. - The gender tick-boxes are normally only needed for nouns, "common gender" tends to be used for languages in which masculine and feminine have combined into one class, whereas "neuter" is a separate gender that is neither masculine nor feminine.
- Clicking Preview will try to make the edit, and display the Save page button in the top left.
- Clicking more opens the extra options (really intended only for advanced users)
- The second line contains gender check boxes, normally only one should be ticked. Though occasionally more are needed.
- Transliteration: (tr=) The word as it might be transliterated into the Latin alphabet.
- Qualifier: This is used if the translation only applies in a certain specific context, or under specific conditions. For example: (informally) and (literally).
- Page name: (alt=) the name of the page when the word includes diacritics that are only normally found in a dictionary. This box may be automatically filled in for some languages (even when it is hidden).
- Script template: (sc=) this only needs to be specified if you want something different from what it suggests.
- Nesting: For languages that aren't already present in the translation table, the new language line may be nested under a language family heading. Or you may add translations with orthographic nesting. The syntax for this box is either: "Family Heading", "Family Heading/Language name" or "/Alphabet name".
Balancing translations
[edit]After adding a translation, two buttons will appear in the middle of the table:
- Clicking "←" moves the first translation on the right to the end of the left list.
- Clicking "→" moves the last translation on the left to the start of the right list.
Table Labelling
[edit]If you enable this feature, each translation table has a ± in the corner.
- Clicking on this brings up an edit box for the table's header.
- Type what you want in, normally the first few words in the definition (without linking or formatting)
- Click "Preview" - if you are not happy with the result, click ± again - otherwise click "Save" in the top corner
WARNING: This feature has not been well tested in all browsers yet. Please notify me on this talk page if you have any problems.
Disabling
[edit]- Logged in users
- Go to Special:Preferences and the Gadgets tab, then check "Disable translation table editor buttons"
- Logged out users
- You don't have the current version of the editor.
- NB. Logged in users can disable it here temporarily, using the first method is recommended.
Adding definitions
[edit]The "Toolbox" section of the sidebar on the left includes a button labelled "Add definition". Clicking this will cause a "Definition" box to follow the mouse. Type in a definition and click on an area of a definition list to add the new definition to that list. Clicking anywhere outside of a definition list while the "Definition" box is following the mouse will cause the box to disappear.
Adding rhymes
[edit]You should see a line at the bottom of each "syllables" section of each rhymes page that looks something like this:
- Add new rhyme: Add
Typing in a rhyme and clicking "Add" will preview the addition of the new rhyme to the rhymes page. Clicking the "Save page" button in the blue box that appears in the top left corner will then save the change to the rhymes page, and update the entry of the newly added rhyme(s) to link back to the rhymes list in their pronunciation section(s). The rhymes adder can be disabled by going to the "Gadgets" tab of Special:Preferences and selecting "Disable the rhymes editor".
Coding
[edit]This code adds an input box below the translation table and passes an edit-object to the Editor.js-script when the user press "preview". It stores settings in cookies for every time the user press save on the blue editor-popup.
At the basic level, edits can be made by passing an edit object to the editor. Edit objects consist of a "redo" function which modifies the page HTML to reflect the edit, an "undo" function which does exactly the opposite of "redo", an "edit" function which performs the edit, and a "summary" string to be added to the edit summary.
TODO
[edit]- Bugs/Enhancements
- Handle API errors.
- A field for additional edit summary
- Reset checkboxes and fields when language code is changed
- Features
- Edit existing translations.
- Add translation gloss.
Discussion
[edit]- Old discussion is at here, please feel free to copy it back to this page if it still needs attention.
Mobile browser support?
[edit]Is it easy to do this? Where would I start?--So9q (talk) 14:42, 30 August 2019 (UTC)
- Unfortunately I do not know the gadget very well. It's kind of messy. (People have requested other changes that I couldn't figure out how to implement.) — Eru·tuon 19:25, 30 August 2019 (UTC)
- I found out that MediaWiki:Common.js is not loaded on mobile, only MediaWiki:Mobile.js. commons.js loads MediaWiki:Gadget-AGprefs.js which loads the list MediaWiki:Gadgets-definition which includes translationadder. Adding TranslationAdder manually to Mobile.js should make it run there.--So9q (talk) 15:10, 31 August 2019 (UTC)
- I think I need Interface Administrator rights and play with MediaWiki:Mobile.js to make this work on mobile.--So9q (talk) 18:35, 31 August 2019 (UTC)
- You can experiment with Mobile.js in your username space, but note that ResourceLoader is disabbled by default on mobile. See mw:ResourceLoader/Writing a MobileFrontend friendly ResourceLoader module. --Vriullop (talk) 19:09, 31 August 2019 (UTC)
- Thanks for the tip. I got it working :)--So9q (talk) 21:30, 31 August 2019 (UTC)
- You can experiment with Mobile.js in your username space, but note that ResourceLoader is disabbled by default on mobile. See mw:ResourceLoader/Writing a MobileFrontend friendly ResourceLoader module. --Vriullop (talk) 19:09, 31 August 2019 (UTC)
- So9q, thanks a lot for trying to make this work! Your suggestion that involved editing common.js mostly worked for me. The appearance of the input boxes was a bit weird (they had no border), and I had to scroll to see the preview, but otherwise it worked.
- I'm very interested in making it usable on mobiles without having to edit the personal common.js file. This may be very useful as a microcontribution for people in upcoming languages, especially in Africa.
- If there is a concern that it will cause many unwanted edits, as Chuck Entz says at Wiktionary:Grease_pit/2019/August#Making_TranslationAdder.js_work_on_mobile_browsers, perhaps it can be enabled only for logged-in users first. --Amir E. Aharoni (talk) 19:11, 19 November 2019 (UTC)
- Hi! Thanks for your reply. I hope to see more translations into upcomming languages, however since working on this above I concluded that wiktionary is not the right place to put my translation contributions. I now favour Wikidata Q-items and translate there instead as it is much better adapted to 1) handle a huge number of translations that the wt:Lua enabled templates simply cannot handle 2) has about just as many concepts as wiktionary albeit in a somewhat less userfriendly UI. We could make a simple translate WD Q-items mobile app that works on the basis of word-lists or something like that. I welcome you to join wikidata! — This unsigned comment was added by So9q (talk • contribs) at 20:17, 19 November 2019 (UTC).
- I actually agree that Wiktionary is far from having a very good structure, but at the same time Wikidata is a bit too young and too difficult for new users to contribute to. Also, despite the technical imperfection, Wiktionary has a lot of good content and an active and dedicated community. So at least for the foreseeable future both are useful. --Amir E. Aharoni (talk) 14:05, 20 November 2019 (UTC)
- Hi, Amir, off topic FYI. I've been playing around to show Wikidata labels in translation tables. See ca:parlament. It's just a test, not sure how it will end up, maybe as a tool for helping with translations. --Vriullop (talk) 19:03, 25 November 2019 (UTC)
- Off-topic, but good! --Amir E. Aharoni (talk) 20:15, 25 November 2019 (UTC)
- Hi, Amir, off topic FYI. I've been playing around to show Wikidata labels in translation tables. See ca:parlament. It's just a test, not sure how it will end up, maybe as a tool for helping with translations. --Vriullop (talk) 19:03, 25 November 2019 (UTC)
- I actually agree that Wiktionary is far from having a very good structure, but at the same time Wikidata is a bit too young and too difficult for new users to contribute to. Also, despite the technical imperfection, Wiktionary has a lot of good content and an active and dedicated community. So at least for the foreseeable future both are useful. --Amir E. Aharoni (talk) 14:05, 20 November 2019 (UTC)
- Hi! Thanks for your reply. I hope to see more translations into upcomming languages, however since working on this above I concluded that wiktionary is not the right place to put my translation contributions. I now favour Wikidata Q-items and translate there instead as it is much better adapted to 1) handle a huge number of translations that the wt:Lua enabled templates simply cannot handle 2) has about just as many concepts as wiktionary albeit in a somewhat less userfriendly UI. We could make a simple translate WD Q-items mobile app that works on the basis of word-lists or something like that. I welcome you to join wikidata! — This unsigned comment was added by So9q (talk • contribs) at 20:17, 19 November 2019 (UTC).
Solved: How to test changes to the code?
[edit]Hi, I would like to work on this gadget. How would I go about testing my changes?
I put the code into my common.js. I did not find out where to disable the wikiwide TranslationAdder.js in any of the preferences (that is possible in the danish wiktionary under gadgets).
Now I have 2 translationadder-boxes. Any clues how to disable the wikiwide one?--So9q (talk) 09:28, 31 August 2019 (UTC)
- I found the preference-setting to disabling the translationadder.js: "Enable the buttons that allow editing of translation tables.". Unfortunately it even disables my customized script in my common.js.
- Does anyone know how to work around this?--So9q (talk) 10:58, 31 August 2019 (UTC)
- The problem may be that you haven't loaded the dependencies before loading the translation-adder script. The gadget system automates this, but when you manually install the translation-adder gadget you have to manually load its dependencies. The list of dependencies is found at MediaWiki:Gadgets-definition. (User:Erutuon/scripts/gadgets-definition.js reformats the page to add links and make it a bit more readable.) I think the basic syntax is
mw.loader.using([ /* dependencies as strings: 'ext.gadget.Editor', 'ext.gadget.LegacyScriptsNewNode', ... */ ]).done(function () { /* script requiring dependencies */ });
. You can put the whole translation adder script into the "script" slot (in User:So9q/TranslationAdder.js), or put theimportScript( 'User:So9q/TranslationAdder.js' );
statement there (in User:So9q/common.js), whichever makes more sense to you. Some of the dependencies might have their own dependencies though. — Eru·tuon 18:51, 31 August 2019 (UTC)- Thanks for you reply. It was dependency related and I solved it by adding them as needed based on error messages from the Chrome JS console. --So9q (talk) 04:04, 1 September 2019 (UTC)
- The problem may be that you haven't loaded the dependencies before loading the translation-adder script. The gadget system automates this, but when you manually install the translation-adder gadget you have to manually load its dependencies. The list of dependencies is found at MediaWiki:Gadgets-definition. (User:Erutuon/scripts/gadgets-definition.js reformats the page to add links and make it a bit more readable.) I think the basic syntax is
Added literal translation field
[edit]Hi, I just added that here in my improved version.--So9q (talk) 14:54, 19 September 2019 (UTC)
Sorting of language names
[edit]Is it correct that lines 1097 and 1226 compare language names (Bulgarian, Chinese, Danish) with operator "<", which uses Unicode ordering? Shouldn't it rather use localeCompare()? For English this might not be a problem, but Turkish Wiktionary has seen Çince (Chinese) be placed at the end of the alphabet instead of between B and D. Compare old discussion at MediaWiki_talk:Gadget-TranslationAdder.js/Archive1#Sort order broken for accented character. --LA2 (talk) 19:39, 3 November 2021 (UTC)
Works with id parameter
[edit]Thadh alerted me on Discord that the translation adder gadget wasn't working on sulfur and figured it was because of the |id=
parameter. That was right; the gadget would be thinking the gloss was id=Q682
(though I didn't test it) and I added simple single-level template parsing that fixes the problem with |id=
.
However, before and after the change, the gadget can't find the right translation table if there are templates nested inside trans-top, which happens on 27 pages right now. For instance grain the gloss in the wikitext is {{trans-top|{{frac|4}} carat as measure of gold purity}}
and the gloss in the HTML is data-gloss="<small><sup>1</sup><big>⁄</big><sub>4</sub></small> carat as measure of gold purity"
. To get the gadget to work on that translation table, the parsing has to work on nested templates, and the wikitext gloss has to be expanded so that it matches the HTML gloss. That may be possible but requires a more complicated process (including more web requests) that I don't think is worth it for so few pages. — Eru·tuon 07:00, 17 April 2023 (UTC)
Mobile
[edit]It does not work un smartphones. BoldLuis (talk) 04:37, 3 July 2023 (UTC)
Avoid adding the same translation twice
[edit]The "preview translation" button doesn't update the page instantly, so something I end up clicking twice, which can lead to the translation being added twice (e.g. diff). I think this is something the edit could catch and avoid. Thanks. tbm (talk) 05:03, 29 July 2023 (UTC)
Iranian Persian, Classical Persian and Dari - order of translation
[edit]@Benwing2: Hi, there's a minor bug in the translation adder for fa-ira, fa-cls and prs.
It puts them in the wrong alphabetical order.
It should be
- Persian:
- Classical Persian:
- Dari:
- Iranian Persian:
Are you able to fix this, please? There are a few translations already that I have added using a wrong order but this can be fixed over time. Anatoli T. (обсудить/вклад) 23:38, 16 January 2024 (UTC)
Character replacement for new language codes
[edit]@Erutuon: Hi,
You did a nice job of character replacement when wrong, similar looking characters were used for e.g. Arabic and Persian.
E.g. Arabic letters ك or ي should be replaced with ک and ی for Persian (fa) and the other way around as well.
We now need to expand this for new language codes fa-cls (Classical Persian), prs (Dari) and fa-ira (Iranian Persian). Are you able to point me where that logic code is or make the change, please?
FYI: @Sameerhameedy, @Benwing2 Anatoli T. (обсудить/вклад) 23:48, 16 January 2024 (UTC)
- @Atitarev: Character replacements are in MediaWiki:Gadget-TranslationAdder-Data.js under
orthographicalCorrections
on line 1764. But it looks like you already added the variants of Persian in this edit! — Eru·tuon 07:26, 17 January 2024 (UTC)- @Erutuon: Yay, thanks! I forgot where and how :) Anatoli T. (обсудить/вклад) 07:28, 17 January 2024 (UTC)
- @Anatoli T.Can you change the Iranian Persian code to pes or the Dari code to fa-afg for consistency? RonnieSingh (talk) 05:22, 2 May 2024 (UTC)
- @Erutuon: Yay, thanks! I forgot where and how :) Anatoli T. (обсудить/вклад) 07:28, 17 January 2024 (UTC)