User:Monkbot/task 15: normalize lang icon templates

This task converts language icon templates {{<xx> icon}} and their various redirects to {{in lang|<xx>}} as a response to the only consensus achieved at this TfD.

descriptionEdit

Task 15 maintains a mapping of the {{<xx> icon}} templates and their various redirects to ISO 639 languages codes or IETF language tags. When located in article text, the icon templates are replaced with a {{in lang}} template with the appropriate code as the parameter value.

It is relatively common to find multiple icon templates listed together. When this occurs, task 15 will replace the multiple icon templates with a single {{in lang}} template with multiple parameters:

{{es icon}} / {{fr icon}} / {{it icon}} / {{pt icon}}{{in lang|es|fr|it|pt}}

{{link language}} and its redirects is the working template for {{<xx> icon}} templates. When {{link language}} or a redirect is found in article space, the template or redirect is replaced with {{in lang}}.

Task 15 skips pages that include {{bots|deny=Monkbot15}}.

ancillary tasksEdit

There are no ancillary tasks.

This task does not do awb general fixes.

scriptEdit

// Monkbot task 15 normalize lang icon templates
// replace {{xx icon}} with {{in lang|xx}}
// replace {{xx icon}} sep {{yy icon}} sep {{zz icon}}, etc) with {{in lang|xx|yy|zz}}

// use What transcludes page: Template:link language (for all of the icon templates) or
// use What transcludes page: Template:xx icon (for a single icon template)


public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
	{
	Skip = true;								// for development, never skip; for the bot set this true then when fixes are made, set it false

	string	pattern;
	const string	__DELETE__ = @"";

	int		match_count = 0;
	int		empty_skip_count = 0;
	int		no_match_skip_count = 0;

	bool	gSkip = Skip;


//---------------------------< D I C T I O N A R Y >----------------------------------------------------------
//
// this dictionary maps {{xx icon}} and redirects to appropriate language codes.  First letter of 'key' is always
// lowercase in this dictionary because template names may have both upper or lowercase first letters; all other
// casing must be maintained as the template or redirect is named.
//
// TODO:
//		confirm that codes are correct
//		where both ISO 639-1 and 639-2/3 are available, use 639-1 code ([[Module:Lang/ISO 639 synonyms]])
//

	Dictionary<string, string> language_map = new Dictionary<string, string>();

//-----< A >-----
		language_map.Add ("aa icon", "aa");
		language_map.Add ("ab icon", "ab");

		language_map.Add ("ace icon", "ace");
		language_map.Add ("ace", "ace");

		language_map.Add ("acw icon", "acw");
		language_map.Add ("acw", "acw");

		language_map.Add ("ady icon", "ady");
		language_map.Add ("ady", "ady");

		language_map.Add ("ae icon", "ae");
		language_map.Add ("ae", "ae");

		language_map.Add ("aeb icon", "aeb");
		language_map.Add ("aeb", "aeb");

		language_map.Add ("af icon", "af");
		language_map.Add ("af li", "af");

		language_map.Add ("ajt icon", "ajt");
		language_map.Add ("ajt", "ajt");

		language_map.Add ("ak icon", "ak");
		language_map.Add ("ak", "ak");

		language_map.Add ("als icon", "als");
		language_map.Add ("als", "als");

		language_map.Add ("am icon", "am");
		language_map.Add ("an icon", "an");

		language_map.Add ("ang icon", "ang");
		language_map.Add ("ang", "ang");
		language_map.Add ("ang-icon", "ang");

		language_map.Add ("ar icon", "ar");
		language_map.Add ("aR", "ar");

		language_map.Add ("arc icon", "arc");
		language_map.Add ("arc", "arc");

		language_map.Add ("arn icon", "arn");

		language_map.Add ("arz icon", "arz");
		language_map.Add ("arz", "arz");

		language_map.Add ("as icon", "as");
		language_map.Add ("as", "as");

		language_map.Add ("ast icon", "ast");
		language_map.Add ("ast", "ast");

		language_map.Add ("av icon", "av");
		language_map.Add ("av", "av");

		language_map.Add ("ay icon", "ay");
		language_map.Add ("ay", "ay");

		language_map.Add ("az icon", "az");
		language_map.Add ("az", "az");
		language_map.Add ("ref-az", "az");

		language_map.Add ("azb icon", "azb");


//-----< B >-----
		language_map.Add ("ba icon", "ba");
		language_map.Add ("ba", "ba");
		language_map.Add ("ba li", "ba");

		language_map.Add ("bal icon", "bal");

		language_map.Add ("be icon", "be");
		language_map.Add ("be li", "be");
		language_map.Add ("ref-be", "be");
		language_map.Add ("ref-by", "be");

		language_map.Add ("ber icon", "ber");
		language_map.Add ("ber", "ber");

		language_map.Add ("bg icon", "bg");
		language_map.Add ("bg li", "bg");

		language_map.Add ("bi icon", "bi");
		language_map.Add ("bla icon", "bla");

		language_map.Add ("bm icon", "bm");
		language_map.Add ("bm", "bm");

		language_map.Add ("bn icon", "bn");
		language_map.Add ("bn", "bn");

		language_map.Add ("bo icon", "bo");

		language_map.Add ("bpy icon", "bpy");
		language_map.Add ("bpy", "bpy");

		language_map.Add ("br icon", "br");
		language_map.Add ("br li", "br");

		language_map.Add ("bs icon", "bs");

		language_map.Add ("bxr icon", "bxr");
		language_map.Add ("bxr", "bxr");
		language_map.Add ("bxr language", "bxr");


//-----< C >-----
		language_map.Add ("ca icon", "ca");
		language_map.Add ("ca", "ca");
		language_map.Add ("ca li", "ca");

		language_map.Add ("cbv icon", "cbv");
		language_map.Add ("cbv", "cbv");

		language_map.Add ("cdo icon", "cdo");
		language_map.Add ("cdo", "cdo");

		language_map.Add ("ce icon", "ce");

		language_map.Add ("ceb icon", "ceb");
		language_map.Add ("ceb", "ceb");

		language_map.Add ("ch icon", "ch");
		language_map.Add ("ch", "ch");

		language_map.Add ("chm icon", "chm");
		language_map.Add ("chm", "chm");

		language_map.Add ("ckb icon", "ckb");
		language_map.Add ("ckb", "ckb");

		language_map.Add ("clw icon", "clw");
		language_map.Add ("clw", "clw");

		language_map.Add ("cmn icon", "cmn");

		language_map.Add ("cnr icon", "cnr");
		language_map.Add ("cnr", "cnr");

		language_map.Add ("co icon", "co");
		language_map.Add ("co", "co");

		language_map.Add ("cop icon", "cop");
		language_map.Add ("cr icon", "cr");

		language_map.Add ("crh icon", "crh");
		language_map.Add ("crh", "crh");

		language_map.Add ("cs icon", "cs");
		language_map.Add ("cs li", "cs");
		language_map.Add ("cz", "cs");
		language_map.Add ("cz icon", "cs");

		language_map.Add ("cu icon", "cu");

		language_map.Add ("cv icon", "cv");

		language_map.Add ("cy icon", "cy");
		language_map.Add ("cy", "cy");
		language_map.Add ("cy-icon", "cy");
		language_map.Add ("wel icon", "cy");


//-----< D >-----
		language_map.Add ("da icon", "da");
		language_map.Add ("da", "da");
		language_map.Add ("da li", "da");
		language_map.Add ("da-icon", "da");
		language_map.Add ("dk icon", "da");

		language_map.Add ("de icon", "de");
		language_map.Add ("de li", "de");
		language_map.Add ("de-icon", "de");
		language_map.Add ("ger", "de");
		language_map.Add ("icon de", "de");
		language_map.Add ("ref-de", "de");

		language_map.Add ("din icon", "din");
		language_map.Add ("din", "din");

		language_map.Add ("diq icon", "zza");									// diq is iana/iso 639 Dimli (individual language); second level domain name for zazzaki wikipedia
		language_map.Add ("diq", "zza");
		language_map.Add ("diq-icon", "zza");

		language_map.Add ("dsb icon", "dsb");
		language_map.Add ("dsb", "dsb");

		language_map.Add ("dv icon", "dv");

		language_map.Add ("dz icon", "dz");
		language_map.Add ("dz", "dz");


//-----< E >-----
		language_map.Add ("ee icon", "ee");
		language_map.Add ("ee", "ee");

		language_map.Add ("el icon", "el");
		language_map.Add ("el", "el");
		language_map.Add ("gr icon", "el");
		language_map.Add ("gre icon", "el");

		language_map.Add ("en icon", "en");									// this is the english wikipedia; delete en icon templates?
		language_map.Add ("en li", "en");
		language_map.Add ("en-icon", "en");
		language_map.Add ("ref-en", "en");

		language_map.Add ("enm icon", "enm");
		language_map.Add ("enm", "enm");
		language_map.Add ("enm-icon", "enm");

		language_map.Add ("eo icon", "eo");
		language_map.Add ("eo", "eo");

		language_map.Add ("es icon", "es");
		language_map.Add ("eS", "es");
		language_map.Add ("es", "es");
		language_map.Add ("es li", "es");
		language_map.Add ("es-icon", "es");
		language_map.Add ("sp icon", "es");

		language_map.Add ("esu icon", "esu");
		language_map.Add ("esu", "esu");

		language_map.Add ("et icon", "et");
		language_map.Add ("estonian icon", "et");
		language_map.Add ("et", "et");
		language_map.Add ("et li", "et");

		language_map.Add ("eu icon", "eu");
		language_map.Add ("eu", "eu");
		language_map.Add ("eu li", "eu");

		language_map.Add ("ext icon", "ext");


//-----< F >-----
		language_map.Add ("fa icon", "fa");
		language_map.Add ("fa", "fa");
		language_map.Add ("pr icon", "fa");

		language_map.Add ("ff icon", "ff");
		language_map.Add ("ff", "ff");

		language_map.Add ("fi icon", "fi");
		language_map.Add ("fi", "fi");
		language_map.Add ("fi li", "fi");

		language_map.Add ("fj icon", "fj");
		language_map.Add ("fj", "fj");

		language_map.Add ("fo icon", "fo");
		language_map.Add ("fo", "fo");

		language_map.Add ("fon icon", "fon");
		language_map.Add ("fon", "fon");

		language_map.Add ("fr icon", "fr");
		language_map.Add ("fr", "fr");
		language_map.Add ("fr li", "fr");
		language_map.Add ("fR-icon", "fr");
		language_map.Add ("fr-icon", "fr");
		language_map.Add ("french icon", "fr");
		language_map.Add ("ref-fr", "fr");

		language_map.Add ("fro icon", "fro");

		language_map.Add ("frp icon", "frp");
		language_map.Add ("frp", "frp");

		language_map.Add ("frr icon", "frr");
		language_map.Add ("frr", "frr");

		language_map.Add ("fry icon", "fy");
		language_map.Add ("fry", "fy");
		language_map.Add ("fy", "fy");
		language_map.Add ("fy icon", "fy");

		language_map.Add ("fur icon", "fur");


//-----< G >-----
		language_map.Add ("ga icon", "ga");
		language_map.Add ("ga li", "ga");

		language_map.Add ("gd icon", "gd");
		language_map.Add ("gd li", "gd");
		language_map.Add ("gla", "gd");
		language_map.Add ("gla icon", "gd");

		language_map.Add ("gl icon", "gl");
		language_map.Add ("gl", "gl");

		language_map.Add ("gn icon", "gn");
		language_map.Add ("gn li", "gn");

		language_map.Add ("grc icon", "grc");
		language_map.Add ("gRC icon", "grc");
		
		language_map.Add ("gsw icon", "gsw");
		language_map.Add ("gsw", "gsw");
		
		language_map.Add ("gu icon", "gu");
		language_map.Add ("gu", "gu");
		
		language_map.Add ("gv icon", "gv");
		language_map.Add ("gv", "gv");


//-----< H >-----
		language_map.Add ("ha icon", "ha");

		language_map.Add ("hak icon", "hak");
		language_map.Add ("hak", "hak");

		language_map.Add ("haw icon", "haw");
		language_map.Add ("haw", "haw");

		language_map.Add ("hbs icon", "sh");
		language_map.Add ("hbs", "sh");
		language_map.Add ("sh icon", "sh");

		language_map.Add ("he icon", "he");

		language_map.Add ("hi icon", "hi");
		language_map.Add ("in icon", "hi");

		language_map.Add ("hif icon", "hif");

		language_map.Add ("hin icon", "hi");
		language_map.Add ("hin", "hi");

		language_map.Add ("ho icon", "ho");
		language_map.Add ("ho", "ho");

		language_map.Add ("hr icon", "hr");
		language_map.Add ("hr li", "hr");

		language_map.Add ("hsb icon", "hsb");
		language_map.Add ("ht icon", "ht");

		language_map.Add ("hu icon", "hu");
		language_map.Add ("hu", "hu");
		language_map.Add ("hu li", "hu");
		language_map.Add ("ref-hu", "hu");

		language_map.Add ("hy icon", "hy");
		language_map.Add ("hy", "hy");
		language_map.Add ("ref-hy", "hy");

		language_map.Add ("hz icon", "hz");
		language_map.Add ("hz", "hz");


//-----< I >-----
		language_map.Add ("ia icon", "ia");
		language_map.Add ("ia", "ia");

		language_map.Add ("id icon", "id");
		language_map.Add ("id", "id");
		language_map.Add ("id li", "id");
		language_map.Add ("indonesian", "id");
		language_map.Add ("indonesian icon", "id");

		language_map.Add ("ie icon", "ie");
		language_map.Add ("ig icon", "ig");
		language_map.Add ("ii icon", "ii");

		language_map.Add ("ik icon", "ik");
		language_map.Add ("ik", "ik");

		language_map.Add ("ilo icon", "ilo");
		language_map.Add ("ilo", "ilo");

		language_map.Add ("io icon", "io");

		language_map.Add ("is icon", "is");
		language_map.Add ("is li", "is");

		language_map.Add ("it icon", "it");
		language_map.Add ("it", "it");
		language_map.Add ("it li", "it");

		language_map.Add ("iu icon", "iu");


//-----< J >-----
		language_map.Add ("ja icon", "ja");
		language_map.Add ("ja", "ja");
		language_map.Add ("ja li", "ja");
		language_map.Add ("ja-icon", "ja");
		language_map.Add ("jp icon", "ja");
		language_map.Add ("jp language", "ja");
		language_map.Add ("jp-icon", "ja");

		language_map.Add ("jac icon", "jac");
		language_map.Add ("jac", "jac");

		language_map.Add ("jbo icon", "jbo");
		language_map.Add ("jbo", "jbo");

		language_map.Add ("jv icon", "jv");
		language_map.Add ("jv", "jv");
		language_map.Add ("javanese", "jv");
		language_map.Add ("javanese icon", "jv");


//-----< K >-----
		language_map.Add ("ka icon", "ka");
		language_map.Add ("ge icon", "ka");
		language_map.Add ("ka li", "ka");
		language_map.Add ("ka-icon", "ka");
		language_map.Add ("ref-ka", "ka");

		language_map.Add ("kab icon", "kab");
		language_map.Add ("kab", "kab");

		language_map.Add ("kar icon", "kar");
		language_map.Add ("kar", "kar");

		language_map.Add ("kbd icon", "kbd");

		language_map.Add ("kbp icon", "kbp");
		language_map.Add ("kbp", "kbp");

		language_map.Add ("kdd icon", "kdd");
		language_map.Add ("kdd", "kdd");

		language_map.Add ("kg icon", "kg");
		language_map.Add ("kg", "kg");

		language_map.Add ("ki icon", "ki");
		language_map.Add ("ki", "ki");

		language_map.Add ("kj icon", "kj");
		language_map.Add ("kj", "kj");

		language_map.Add ("kjp icon", "kjp");
		language_map.Add ("kjp", "kjp");

		language_map.Add ("kk icon", "kk");
		language_map.Add ("kk", "kk");
		language_map.Add ("kz icon", "kk");

		language_map.Add ("kl icon", "kl");

		language_map.Add ("km icon", "km");
		language_map.Add ("km", "km");

		language_map.Add ("kmr icon", "kmr");
		language_map.Add ("kmr", "kmr");

		language_map.Add ("kn icon", "kn");
		language_map.Add ("kn", "kn");

		language_map.Add ("knn icon", "knn");

		language_map.Add ("ko icon", "ko");
		language_map.Add ("ko", "ko");

		language_map.Add ("kr icon", "kr");
		language_map.Add ("kr", "kr");

		language_map.Add ("ks icon", "ks");
		language_map.Add ("ks", "ks");

		language_map.Add ("ksh icon", "ksh");
		language_map.Add ("ksh", "ksh");

		language_map.Add ("ksw icon", "ksw");

		language_map.Add ("ku icon", "ku");
		language_map.Add ("ku", "ku");

		language_map.Add ("kv icon", "kv");
		language_map.Add ("kv", "kv");

		language_map.Add ("kw icon", "kw");

		language_map.Add ("ky icon", "ky");
		language_map.Add ("ky", "ky");


//-----< L >-----
		language_map.Add ("la icon", "la");
		language_map.Add ("la-icon", "la");
		language_map.Add ("latin", "la");

		language_map.Add ("lad icon", "lad");
		language_map.Add ("lad", "lad");

		language_map.Add ("lb icon", "lb");
		language_map.Add ("lg icon", "lg");
		language_map.Add ("li icon", "li");

		language_map.Add ("lij icon", "lij");
		language_map.Add ("lij", "lij");

		language_map.Add ("liv icon", "liv");
		language_map.Add ("liv", "liv");
		language_map.Add ("liv li", "liv");

		language_map.Add ("ln icon", "ln");
		language_map.Add ("ln li", "ln");

		language_map.Add ("lo icon", "lo");

		language_map.Add ("lou icon", "lou");
		language_map.Add ("lou", "lou");

		language_map.Add ("lrc icon", "lrc");

		language_map.Add ("lt icon", "lt");
		language_map.Add ("lt li", "lt");
		language_map.Add ("lticon", "lt");

		language_map.Add ("lu icon", "lu");

		language_map.Add ("lv icon", "lv");
		language_map.Add ("lv", "lv");


//-----< M >-----
		language_map.Add ("mam icon", "mam");
		language_map.Add ("mam", "mam");

		language_map.Add ("may icon", __DELETE__);							// not used in article space; invalid code;

		language_map.Add ("mg icon", "mg");
		language_map.Add ("mg li", "mg");

		language_map.Add ("mh icon", "mh");
		language_map.Add ("mi icon", "mi");
		language_map.Add ("min icon", "min");

		language_map.Add ("mis icon", "mis");
		language_map.Add ("mis", "mis");
		language_map.Add ("mis-Cyrl icon", "mis-Cyrl");						// renders as Uncoded languages; script tags validated not otherwise supported
		language_map.Add ("mis-Latn icon", "mis-Latn");

		language_map.Add ("mk icon", "mk");
		language_map.Add ("mk", "mk");

		language_map.Add ("ml icon", "ml");
		language_map.Add ("mn icon", "mn");

		language_map.Add ("mnc icon", "mnc");
		language_map.Add ("mnc", "mnc");

		language_map.Add ("mni icon", "mni");
		language_map.Add ("mni", "mni");

//		language_map.Add ("mo icon", "ro"); 								// not a valid language code for moldovan; use ro. create ro-x-moldova?
//		language_map.Add ("mo", "ro");										// used in article space and currently emits error messages; leave in place so that these can be fixed manually

		language_map.Add ("mr icon", "mr");

		language_map.Add ("ms icon", "ms");
		language_map.Add ("ms", "ms");
		language_map.Add ("ms li", "ms");

		language_map.Add ("mt icon", "mt");
		language_map.Add ("mtq icon", "mtq");
		language_map.Add ("mwl icon", "mwl");
		language_map.Add ("my icon", "my");

		language_map.Add ("myn icon", "myn");
		language_map.Add ("myn", "myn");


//-----< N >-----
		language_map.Add ("na icon", "na");

		language_map.Add ("nah icon", "nah");
		language_map.Add ("nah", "nah");

		language_map.Add ("nan icon", "nan");
		language_map.Add ("nan", "nan");
		language_map.Add ("zh-min-nan icon", "nan");						// zh-min-nan redundant ietf tag; use nan

		language_map.Add ("nap icon", "nap");
		language_map.Add ("nap", "nap");

		language_map.Add ("nb icon", "nb");
		language_map.Add ("nd icon", "nd");
		language_map.Add ("nds icon", "nds");
		language_map.Add ("nds", "nds");

		language_map.Add ("ne icon", "ne");
		language_map.Add ("new icon", "new");
		language_map.Add ("ng icon", "ng");

		language_map.Add ("nl icon", "nl");
		language_map.Add ("du icon", "nl");
		language_map.Add ("nl", "nl");
		language_map.Add ("nl li", "nl");
		language_map.Add ("nl-icon", "nl");

		language_map.Add ("nn icon", "nn");

		language_map.Add ("no icon", "no");
		language_map.Add ("no-icon", "no");

		language_map.Add ("non icon", "non");
		language_map.Add ("nr icon", "nr");

		language_map.Add ("nrf icon", "nrf");
		language_map.Add ("nrf", "nrf");

		language_map.Add ("nrn icon", "nrn");
		language_map.Add ("nrn", "nrn");

		language_map.Add ("nso icon", "nso");
		language_map.Add ("nso", "nso");

		language_map.Add ("nv icon", "nv");
		language_map.Add ("nv", "nv");

		language_map.Add ("ny icon", "ny");
		language_map.Add ("ny", "ny");


//-----< O >-----
		language_map.Add ("oc icon", "oc");
		language_map.Add ("oc", "oc");

		language_map.Add ("oj icon", "oj");
		language_map.Add ("oj", "oj");

		language_map.Add ("om icon", "om");
		language_map.Add ("om", "om");

		language_map.Add ("or icon", "or");

		language_map.Add ("os icon", "os");
		language_map.Add ("os", "os");

		language_map.Add ("osp icon", "osp");
		language_map.Add ("osp", "osp");

		language_map.Add ("ota icon", "ota");
		language_map.Add ("ota", "ota");

		language_map.Add ("oto icon", "oto");
		language_map.Add ("oto", "oto");

		language_map.Add ("owl icon", "owl");
		language_map.Add ("owl-icon", "owl");


//-----< P >-----
		language_map.Add ("pa icon", "pa");
		language_map.Add ("pa", "pa");
		language_map.Add ("pa-icon", "pa");
		language_map.Add ("pan icon", "pa");
		language_map.Add ("pan-icon", "pa");

		language_map.Add ("pap icon", "pap");
		language_map.Add ("pap", "pap");

		language_map.Add ("pi icon", "pi");
		language_map.Add ("pl icon", "pl");
		language_map.Add ("pl", "pl");
		language_map.Add ("pl li", "pl");
		language_map.Add ("pl-icon", "pl");
		language_map.Add ("ref-pl", "pl");

		language_map.Add ("pms icon", "pms");

		language_map.Add ("pnb icon", "pnb");
		language_map.Add ("pnb", "pnb");
		language_map.Add ("pnb-icon", "pnb");

		language_map.Add ("prs icon", "prs");
		language_map.Add ("ps icon", "ps");

		language_map.Add ("pt icon", "pt");
		language_map.Add ("pt", "pt");
		language_map.Add ("pt li", "pt");


//-----< Q >-----
		language_map.Add ("qu icon", "qu");
		language_map.Add ("qu li", "qu");
		language_map.Add ("que icon", "qu");

		language_map.Add ("quc icon", "quc");
		language_map.Add ("quc", "quc");


//-----< R >-----
		language_map.Add ("rm icon", "rm");

		language_map.Add ("rmy icon", "rmy");
		language_map.Add ("rmy", "rmy");

		language_map.Add ("rn icon", "rn");

		language_map.Add ("ro icon", "ro");
		language_map.Add ("ro", "ro");
		language_map.Add ("ro li", "ro");
		language_map.Add ("ro-icon", "ro");
		language_map.Add ("ref-ro", "ro");

		language_map.Add ("roa icon", "roa");
		language_map.Add ("roa", "roa");

		language_map.Add ("ru icon", "ru");
		language_map.Add ("icon ru", "ru");
		language_map.Add ("ref-ru", "ru");
		language_map.Add ("ru Icon", "ru");
		language_map.Add ("ru language", "ru");
		language_map.Add ("ru li", "ru");
		language_map.Add ("ru-icon", "ru");

		language_map.Add ("rue icon", "rue");
		language_map.Add ("rue", "rue");

		language_map.Add ("rup icon", "rup");
		language_map.Add ("roa-rup", "rup");
		language_map.Add ("roa-rup icon", "rup");
		language_map.Add ("rup", "rup");

		language_map.Add ("rut icon", "rut");

		language_map.Add ("rw icon", "rw");
		language_map.Add ("rw", "rw");


//-----< S >-----
		language_map.Add ("sa icon", "sa");

		language_map.Add ("sah icon", "sah");
		language_map.Add ("sah", "sah");

		language_map.Add ("sc icon", "sc");

		language_map.Add ("scl icon", "scl");
		language_map.Add ("scl", "scl");

		language_map.Add ("scn icon", "scn");
		language_map.Add ("scn", "scn");

		language_map.Add ("sco icon", "sco");
		language_map.Add ("sco", "sco");

		language_map.Add ("sd icon", "sd");
		language_map.Add ("sd", "sd");

		language_map.Add ("sdc icon", "sdc");
		language_map.Add ("sdc", "sdc");

		language_map.Add ("sdn icon", "sdn");
		language_map.Add ("sdn", "sdn");

		language_map.Add ("se icon", "se");
		language_map.Add ("se", "se");

		language_map.Add ("seto icon", __DELETE__);							// no language code; no use in article space
		
		language_map.Add ("sg icon", "sg");
		language_map.Add ("sgn icon", "sgn");

		language_map.Add ("sgs icon", "sgs");
		language_map.Add ("sgs", "sgs");

		language_map.Add ("shn icon", "shn");
		language_map.Add ("si icon", "si");

		language_map.Add ("sk icon", "sk");
		language_map.Add ("sk", "sk");

		language_map.Add ("skr icon", "skr");
		language_map.Add ("skr", "skr");

		language_map.Add ("sl icon", "sl");
		language_map.Add ("sl li", "sl");
		language_map.Add ("slovene", "sl");

		language_map.Add ("sm icon", "sm");
		language_map.Add ("sn icon", "sn");
		language_map.Add ("so icon", "so");

		language_map.Add ("sq icon", "sq");
		language_map.Add ("al icon", "sq");
		language_map.Add ("albanian", "sq");

		language_map.Add ("sr icon", "sr");
		language_map.Add ("sR icon", "sr");
		language_map.Add ("sr li", "sr");

		language_map.Add ("ss icon", "ss");

		language_map.Add ("ssf icon", "ssf");
		language_map.Add ("ssf", "ssf");

		language_map.Add ("st icon", "st");
		language_map.Add ("su icon", "su");

		language_map.Add ("sv icon", "sv");
		language_map.Add ("sv", "sv");
		language_map.Add ("svenska", "sv");
		language_map.Add ("svicon", "sv");
		language_map.Add ("swe icon", "sv");

		language_map.Add ("sw icon", "sw");
		language_map.Add ("sw li", "sw");

		language_map.Add ("syc icon", "syc");
		language_map.Add ("syc", "syc");
		language_map.Add ("sy icon", "syc");

		language_map.Add ("syr icon", "syr");
		language_map.Add ("syr", "syr");

		language_map.Add ("szl icon", "szl");
		language_map.Add ("szl", "szl");


//-----< T >-----
		language_map.Add ("ta icon", "ta");
		language_map.Add ("te icon", "te");

		language_map.Add ("tet icon", "tet");
		language_map.Add ("tet", "tet");

		language_map.Add ("tg icon", "tg");
		language_map.Add ("tg", "tg");
		language_map.Add ("ref-tg icon", "tg");

		language_map.Add ("th icon", "th");
		language_map.Add ("ti icon", "ti");

		language_map.Add ("tk icon", "tk");
		language_map.Add ("tk", "tk");

		language_map.Add ("tl icon", "tl");
		language_map.Add ("ph icon", "tl");
		language_map.Add ("tagalog", "tl");
		language_map.Add ("tgl", "tl");
		language_map.Add ("tl li", "tl");

		language_map.Add ("tn icon", "tn");
		language_map.Add ("to icon", "to");

		language_map.Add ("tr icon", "tr");
		language_map.Add ("tr", "tr");
		language_map.Add ("tR", "tr");
		language_map.Add ("tr li", "tr");
		language_map.Add ("tr-icon", "tr");

		language_map.Add ("ts icon", "ts");
		language_map.Add ("tt icon", "tt");

		language_map.Add ("tun icon", "tun");
		language_map.Add ("tun", "tun");

		language_map.Add ("tw icon", "tw");
		language_map.Add ("ty icon", "ty");

		language_map.Add ("tzl icon", "tzl");
		language_map.Add ("tzl", "tzl");

		language_map.Add ("tzm icon", "tzm");
		language_map.Add ("tzm", "tzm");


//-----< U >-----
		language_map.Add ("udm icon", "udm");
		language_map.Add ("udm", "udm");

		language_map.Add ("ug icon", "ug");

		language_map.Add ("uk icon", "uk");
		language_map.Add ("icon uk", "uk");
		language_map.Add ("ref-uk", "uk");
		language_map.Add ("ua icon", "uk");
		language_map.Add ("uk li", "uk");
		language_map.Add ("uk-icon", "uk");

		language_map.Add ("ur icon", "ur");
		language_map.Add ("ur", "ur");

		language_map.Add ("uun icon", "uun");
		language_map.Add ("uun", "uun");

		language_map.Add ("uz icon", "uz");
		language_map.Add ("uz", "uz");
		language_map.Add ("uzb icon", "uz");
		language_map.Add ("ref-uz", "uz");


//-----< V >-----
		language_map.Add ("ve icon", "ve");
		language_map.Add ("ve", "ve");

		language_map.Add ("vi icon", "vi");
		language_map.Add ("vi", "vi");
		language_map.Add ("vi li", "vi");

//		language_map.Add ("vl icon", "vl");									// invalid code; supposed to be valencian?  use: ca-valencia?
//		language_map.Add ("vl", "vl");										// used in article space and currently producing error messages; leave in place to fix manually

		language_map.Add ("vo icon", "vo");

		language_map.Add ("vot icon", "vot");
		language_map.Add ("vot", "vot");

		language_map.Add ("vro icon", "vro");								// these all lump together to Võro but is that the correct thing to do?
		language_map.Add ("vro", "vro");									// Võro
		language_map.Add ("fiu icon", "fiu");								// not used in article space; should render 'Finno-Ugrian languages' because ISO 639-2 fiu is Finno-Ugrian languages?
		language_map.Add ("fiu-vro icon", "vro");							// Võro is a Finno-Ugrian language, so vro 'Võro'


//-----< W >-----
		language_map.Add ("wa icon", "wa");

		language_map.Add ("wo icon", "wo");
		language_map.Add ("wo", "wo");

		language_map.Add ("wuu icon", "wuu");
		language_map.Add ("wuu", "wuu");
		language_map.Add ("zh-wuu icon", "wuu");							// zh-wuu redundant ietf tag; use wuu


//-----< X >-----
		language_map.Add ("xh icon", "xh");
		language_map.Add ("xh", "xh");

		language_map.Add ("xmf icon", "xmf");
		language_map.Add ("xmf", "xmf");


//-----< Y >-----
		language_map.Add ("yi icon", "yi");
		language_map.Add ("yi", "yi");

		language_map.Add ("yo icon", "yo");

		language_map.Add ("yua icon", "yua");
		language_map.Add ("yua", "yua");

		language_map.Add ("yue icon", "yue");
		language_map.Add ("yue", "yue");
		language_map.Add ("zh-yue icon", "yue");							// zh-yue redundant ietf tag; use yue


//-----< Z >-----
		language_map.Add ("za icon", "za");
		language_map.Add ("za", "za");

		language_map.Add ("zh icon", "zh");
		language_map.Add ("zh-icon", "zh");
		language_map.Add ("cn icon", "zh");
//		language_map.Add ("zh-classical icon", "zh-classical");				// not used in article space; uses |cat-lang=Chinese; literary chinese? use lzh?
//		language_map.Add ("zh-classical", "zh-classical");					// not used in article space

		language_map.Add ("zh-hant icon", "zh-hant");						// renders as Chinese; script tags validated not otherwise supported
		language_map.Add ("zh-hant", "zh-hant");

		language_map.Add ("zh-hans", "zh-hans");
		language_map.Add ("zh-hans icon", "zh-hans");

		language_map.Add ("zh-cn", "zh-cn");								// renders as Chinese; region tags validated not otherwise currently supported
		language_map.Add ("zh-cn icon", "zh-cn");

		language_map.Add ("zh-hk icon", "zh-hk");
		language_map.Add ("zh-hk", "zh-hk");

		language_map.Add ("zh-tw icon", "zh-tw");
		language_map.Add ("zh-tw", "zh-tw");

		language_map.Add ("zu icon", "zu");
		language_map.Add ("zu", "zu");


//---------------------------< R E N A M E   X X   I C O N   T E M P L A T E S >------------------------------
//
// renames {{xx icon}} and redirects to {{in lang|xx}}
//

	pattern = @"\{\{([A-Za-z\-_ ]+)\}\}";									// just letters, spaces, underscores, and hyphens
	if (Regex.Match (ArticleText, pattern).Success)
		{
		ArticleText = Regex.Replace(ArticleText, pattern,
			delegate(Match match)
				{
				string	code;												// language code from dictionary
				string	raw_template = match.Groups[0].Value;				// the whole {{xx icon}} template; if we can't fix the template then return raw_template
				string	template_content = match.Groups[1].Value.Trim();	// everything between {{ and }} except leading and trailing spaces

				if (@"" == template_content)								// if an empty string
					{
					empty_skip_count++;
					return raw_template;									// nothing to do
					}

				template_content = Regex.Replace (template_content, @"_", " ");		// replace underscores with space characters

				template_content = char.ToLower(template_content[0]).ToString() + template_content.Substring(1);	// force first character lowercase

				if (language_map.ContainsKey (template_content))			// if template is an exact match
					{
					match_count++;											// found it, bump the counter
					code = language_map[template_content];					// and get the appropriate code
					if (__DELETE__ == code)									// rare case of delete-instead-of-replace
						return @"";											// delete the template by returning empty string
					}
				else
					{
					no_match_skip_count++;									// this more or less useless; because these are any template that doesn't have a pipe and isn't an icon template (there are lots)
					return raw_template;
					}

				gSkip = false;
				return @"{{in lang|" + code + @"}}";						// create new template and done
				});
		}


//---------------------------< R E N A M E   L I N K   L A N G U A G E   T E M P L A T E S >------------------
//
// renames {{link language}} and its redirects to {{in lang}}
//
// pattern does not allow for |cat-lang= parameters; those should be fixed manually
//

	pattern = @"\{\{(?:[Ll]ang[\- _]*icon|[Ll]anguage[ _]*icon|[Ll]anguage[ _]+link|[Ll]ink[ _]+language|[Ll]ink[ _]+lang|LL|[Ll]l|[Oo]ther[ _]+language[ _]+link|[Ww]ikipedia:[Ss]ymbole) *\|([A-Za-z\-]+)\}\}";
	if (Regex.Match (ArticleText, pattern).Success)
		{
		ArticleText = Regex.Replace(ArticleText, pattern,
			delegate(Match match)
				{
				string	code = match.Groups[1].Value.Trim();				// the language code

				match_count++;												// bump the counter
				gSkip = false;												// fix made so don't skip
				return @"{{in lang|" + code + @"}}";						// create new template and done
				});
		}


//---------------------------< M U L T I P L E S >------------------------------------------------------------
//
// convert a series of {{xx icon}} templates with a variety of separators to a single {{in lang}} template with multiple
// code parameters
//

	string sep = @"(?: and |[ /&,]*)";
	string in_lang1 = @"(\{\{in lang\|[a-z\|]+)\}\}";
	string in_lang2 = @"\{\{in lang\|([a-z\|]+)\}\}";

	pattern = in_lang1 + sep + in_lang2;
	while (Regex.Match (ArticleText, pattern).Success)
		ArticleText = Regex.Replace(ArticleText, pattern, "$1|$2}}");


//---------------------------< F I N I S H >------------------------------------------------------------------

	if (true == gSkip)
		Summary = @"";														// if skipping, no public edit-summary lead
	else
//		Summary = "(developmental testing):";
//		Summary = "[[User:Monkbot/task 15: normalize lang icon templates|Task 15]] (developmental testing):";
		Summary = "[[User:Monkbot/task 15: normalize lang icon templates|Task 15]]:";

	Summary = Summary + @"  language icon template(s) replaced (" + match_count + @"×);";

	if (0 != empty_skip_count)
		Summary = Summary + @" empty skip (" + empty_skip_count + @"×);";

	Skip = gSkip;
	return ArticleText;
	}