/*
* Converts Latin-script translations with no parameters besides language, term, and gender to {{t-simple}}.
* Add a link just above the edit box, if you're in the main namespace,
* and if a Translations header exists on the page.
*/
/* jshint eqeqeq: true, esversion: 6, undef: true, unused: true, varstmt: true */
/* globals $, CleanupButtons, mw */
// <nowiki>
if ( mw.config.get("wgNamespaceNumber") === 0 && document.querySelector(".translations") !== null ) {
const summary = "{{]}} for Latin-script terms with just lang, term, and gender, to reduce Lua memory usage, using ]";
// Uses Latin-script pattern from ]: A-Za-zÀ-ÖØ-öø-ɏḀ-ỿ
const translationRegex = /\n\* (+)\: *(.*)\{\{t(\+?)\|(+?)\|(+)(?:\|(+))?\}\}/g;
const convertToSimple = (content) => {
let count = 0;
const addSimple = (wholeMatch, langName, intervening, interwiki, langCode, term, gender) => {
++count;
return "\n* " + langName + ": " + intervening + "{{t-simple|"
+ langCode + "|" + term
+ (gender ? "|" + gender : "")
+ "|langname=" + langName
+ (interwiki === "+" ? "|interwiki=1" : "")
+ "}}";
};
while ( translationRegex.test(content) )
content = content.replace(translationRegex, addSimple);
mw.notify(count > 0
? `${count} replacement${count > 1 ? "s" : ""} made.`
: "No replacements of translation templates were made.");
$("#wpSummary").val((index, value) => {
const match = value.match(/^\/\*+\*\/\s+(.+)/);
let addition;
const afterSectionName = match ? match : "";
if ( count > 0 && !afterSectionName.includes(summary) ) {
addition = (afterSectionName.length > 1 ? "; " : "")
+ summary;
}
return value + (addition || "");
});
return content;
};
$.getScript("//en.wiktionary.orghttps://en.wiktionary.org/w/index.php?title=User:Erutuon/scripts/CleanupButtons.js&action=raw&ctype=text/javascript")
.done(() => {
const buttons = new CleanupButtons();
buttons.addButton({
button: {
text: "switch Latin-script translations to {{t-simple}}"
},
func: convertToSimple,
});
});
}
// </nowiki>