Learning patterns/Resolve broken references left by the Content Translation tool
What problem does this solve?
editWhen using the Content Translation tool for translating articles from English (potentially other source languages as well), due to a known issue when *reusing* a reference in multiple paragraphs a "references duplicate key" error is displayed, like so:
Invalid <ref>
tag; name "$1" defined multiple times with different content
What happens from a technical point of view is that the tool duplicates the entire reference contents AND adds a bunch of code into subsequent reference calls, instead of just leaving the reference name on those subsequent calls. This triggers a references duplicate key error, which could be tedious to resolve manually (either in Visual Editor or in the classic edit box).
See such an error in an example on the Romanian Wikipedia: here, and then observe the source code behind it: here. Do you notice how the reference named "announcement" appears two times in the source, but with a different content the second time?
What is the solution?
editWhile it is possible to fix these references manually, this endeavor requires the user to either have a near-perfect understanding of the wiki code – in the classic source-code edit box – or to understand the concept of named references and be able to isolate the "true" one (as to delete and re-generate the rest) – in Visual Editor. There is a method which does not require any such expertise, and only takes a few clicks to execute.
- Steps to execute
- Navigate to the published article, and click "Edit source" in order to open up the source-code edit box (as opposed to the Visual Editor).
- In the bar just above the edit box, click "Advanced" and observe how another bar is expanded below it.
- Locate the magnifying glass icon on the far right of this bar, which upon mouse hovering says "Search and replace", and click it.
- In the "Search for" field, insert the following text:
<ref name\=([^>/]+)>((?!(?:</ref>|</cite>)).)*</cite>(?:\r?\n?((?!(?:</ref>|</cite>)).)*)*</ref>
- In the "Replace with" field, insert the following text:
<ref name=$1/>
- Enable "Treat search string as a regular expression"; leave the other checkboxes unchecked.
- Click "Replace all"
- Click "Close" to exit the Search&Replace box.
- Publish your edit.
Example of this approach being applied on an article on Romanian Wikipedia: here.
Feel free to use these search and replace strings to feed your robot some tasks, e.g. through AutoWikiBrowser.
Things to consider
edit- This approach works best if applied immediately after page is published using the Content Translation tool. If references are altered in the meantime, the search&replace procedure can cause "reference no text" errors instead.
- There are other reference issues (and indeed, code issues in general) that can be introduced by the Content Translation tool. Equally popular (and nasty) examples are references missing key and references no text. Refer to the linked help pages for advice.
- From a technical standpoint: the described solution relies on the existence of a <cite></cite> tag in the malformed references – usually added by the Content Translation tool upon reusing in different paragraphs.
When to use
editThis fix is intended to use on articles published within the Content Translation tool. Best to do it just after the translation is published.
- You can use it to mass-solve the CT-induced errors in pages under Category:Pages with reference errors on your wiki of choice.
- If you conduct a editathon or workshop based on translations and your participants/students use the Content Translation tool, you can either instruct them to perform the find-and-replace exercise, or do it yourself after or during the event.