User:Kbrown (WMF)/autoTranslationMarkup

From Meta, a Wikimedia project coordination wiki
This page contains changes which are not marked for translation.

This is the documentation space for a script currently in development that automates some aspects of translation markup. This script is still buggy; do not save wikitext it generates without checking your work.

Goals: what exactly am I trying to do?[edit]

The process of adding translation markup to a page on Meta, especially if the page is lengthy, is a long, manual grind. Though "Insertable wiki markup" below the edit window allows you to highlight text to wrap in translation tags, you still have to scroll through the whole page, adding them to one segment at a time. What if you could open edit window, click a "mark this up" button, and have a script do 90% of the tedious adding of tags for you?

About the script[edit]

The script currently lives here, in my userspace.

It is still a work in progress. Currently the script can handle all the markup of "typical" wikimarkup prose (paragraphs, bullet points, indentation) as well as table headers and table rows (including those that contain sub-markup like bullets). However, there are almost certainly some edge cases of wikimarkup where the script will choke or will garble text instead of helping it. Note that some of the tags this script inserts are known to be less-than-ideal translation markup; while I do intend to improve this as I refine the script, it's currently a tradeoff between ease of implementation and perfection of markup. Even if the script's markup doesn't break anything, you will likely want to give its output a once-over to add or remove tags that need it, as well as to fill in things like <tvar|></> tags.

This script will not insert the <languages/> bar for you, nor will it mark the page for translation and send it out to the translation queue. You will need a translation administrator to perform the latter action.

How to use it[edit]

  1. Install the script into your personal common.js (not global.js; this script will only work on Meta) by inserting the following line:

    importScript('User:Kbrown (WMF)/autoTranslationMarkup.js');

  2. Open a page on Meta that you want to mark up. Notice that at the top right of your personal links bar (at the top of your browser window, with "Talk, Preferences, Watchlist", etc), you now also have a link that says "EasyTranslate"
  3. Once you've opened the page you need to mark, click "edit" or "edit source" (whichever your preferences are set to use to direct you to the wikitext editor. This script will not work in VisualEditor)
    • The script will only work if you are in the wikitext editor; if you click the link while just viewing a page, nothing will happen
    • This script pulls wikitext from the API rather than directly from Meta. If you have very recently edited the page you are marking up, you may need to purge your cache in order for the API-generated version of the page to contain your newest updates
  4. Click in the edit box (to put the window's focus there)
  5. Click the "EasyTranslate" link in your links bar. There may be a slight wait as the script processes, depending on the size of the page you're marking up
  6. The script will automatically mark up the contents of the edit window.
    • There is currently no implemented way to select only some text within the edit window for markup; the script will simply do the entirety of the edit window's content. If you want to mark up less than a full page, I suggest either editing the page in sections, or placing the part that you want marked up into a sandbox page and then transferring it back to the main edit window
  7. Always preview changes this script inserts. You are responsible for your own edits.
    • To force you to do this, the script will disable the "save page" button when you call it by clicking the "EasyTranslate" link. Once this has happened, you will need to either tick the confirmation box under the edit window to confirm that you have checked your changes, or click the "preview" button to check your changes. Once you've done one of these things, the "Save" button will be re-enabled.
  8. Save the page. Check your edits again to confirm that nothing is broken and that the markup you needed inserted has been inserted.
  9. Manually add languages bar, etc as needed.

Known issues[edit]

  • Wikilinks:
    • Cannot keep wikilinks "nested" within paragraph translation tags - system will always recognize start of a link as end of previous wrapped element. As a result, given my choice between missing links entirely and wrapping them separately, wikilinks contained within paragraphs are handled as separate translation elements (e.g. such paragraphs will be marked up as <translate>Testing 123 testing</translate> [[destination|<translate>label</translate>]]<translate> more text la la la </translate>)
    • No tvars for link destinations right now; that half of a link is just ignored entirely and left outside of all translate tags
  • Editing environment:
    • Script will not work in Visual Editor
    • Script will not work in 2017 Wikitext editor (VE-style view of Wikitext), as of editor's beta release circa March 2017
    • Texteditor area must have focus (i.e. click the mouse in the texteditor area) for script to recognize it was the area to grab text from. Triggering script without giving editor focus will lead to nothing happening, instead of markup happening.
  • Script cannot handle marking up only selected text; it will always mark everything in the edit window
  • Numbers
    • Formatnum section of the script currently doesn't handle percent signs (%)
  • Categories: are not a thing. Sigh.

Changelog[edit]

  • Beta:
    • 28 Feb 2017: Removed link label markup, as it led to double-tagging at least some of the time
  • v1.0 (17 March 2017)(diff):
    • Major changes:
      • Wikilinks are now handled by having their labels wrapped and targets ignored
      • Fixed whitespace tagging in nodes that contain no text other than their children
      • Added automatic wrapping of numbers in template:formatnum tags, including numbers that contain punctuation and numbers wrapped in parentheses
    • Minor changes:
      • Slightly streamlined selectors

To-do[edit]

  • Handle section editing
  • Tvars

Disclaimer[edit]

Please note that I am not a professional programmer and this script is likely to have bugs! This is not in any way an "official" Wikimedia Foundation script, and neither I nor my employer make any guarantees about the functioning or output of the script. I wrote this script partially as a way of teaching myself jQuery, so I'm not kidding when I say you should expect it to be inelegant at best. Remember, you are ultimately responsible for your own edits, even those made with the assistance of this (or any) script.

If you encounter a bug where the script breaks the page or where it inserts incorrect markup, please report it to my talk page. Feel free to request new features or suggest improvements to my code there as well, though I cannot guarantee that I will be able to implement them.

Links[edit]