User:Erutuon/scripts/simpleTranslations.js

Hello, you have come here looking for the meaning of the word User:Erutuon/scripts/simpleTranslations.js. In DICTIOUS you will not only get to know all the dictionary meanings for the word User:Erutuon/scripts/simpleTranslations.js, but we will also tell you about its etymology, its characteristics and you will know how to say User:Erutuon/scripts/simpleTranslations.js in singular and plural. Everything you need to know about the word User:Erutuon/scripts/simpleTranslations.js you have here. The definition of the word User:Erutuon/scripts/simpleTranslations.js will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofUser:Erutuon/scripts/simpleTranslations.js, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.
/*
 * 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>