Module:Lang/documentor tool/sandbox
Appearance
![]() | This is the module sandbox page for Module:Lang/documentor tool (diff). See also the companion subpage for test cases (run). |
![]() | This Lua module is used on approximately 3,700 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
Module:Lang/documentor tool implements the following templates:
The module is also used to produce the following testcases:
{{#invoke:Lang|name_from_tag}}
– ISO 639-1, ISO 639-3-1, ISO 639-3-2, and ISO 639-3-3, and ISO 639 deprecated and override.{{#invoke:ISO 639 name|name_from_code}}
– ISO 639-1, ISO 639-2, ISO 639-3-1, ISO 639-3-2, ISO 639-3-3, ISO 639-5, and ISO 639 deprecated.{{#invoke:ISO 639 name|code_from_name}}
– ISO 639-1, ISO 639-2, ISO 639-3-1, ISO 639-3-2, ISO 639-3-3, ISO 639-5, and ISO 639 deprecated.
require('strict')localp={}--[[ -------------------------< P R I V A T E _ T A G S >------------------------------------------------------{{#invoke:Lang/documentor tool|private_tags}}Reads the override{} table in Module:Lang/data and renders a wiki table of private tags and their associated languages]]localfunctionprivate_tags(frame)localoverride_t=mw.loadData('Module:Lang/data').override-- get the override tablelocalprivate_t={}fortag,langinpairs(override_t)doiftag:find('%-x%-')thentable.insert(private_t,table.concat({'\n|-\n|',lang,'||',tag}))endendtable.sort(private_t)table.insert(private_t,1,'{| class="wikitable sortable"')table.insert(private_t,2,'\n|+ Supported private-use IETF language tags')table.insert(private_t,3,'\n! Language !! Private-use tag')returntable.concat(private_t)..'\n|}'-- return '<pre>' .. table.concat (private_t) .. '\n|}' .. '</pre>'--error (mw.dumpObject (private_t))end--[[ -------------------------< L A N G - X X _ S E T T I N G S >----------------------------------------------{{#invoke:Lang/documentor tool|lang_xx_settings|template={{ROOTPAGENAME}}}}Reads the content of the template and extracts the parameters from {{#invoke:Lang|...}} for display on the template'sdocumentation page.]]localfunctionlang_xx_settings(frame)localpage=mw.title.makeTitle('Template',frame.args['template']orframe.args[1])-- get a page object for this page in 'Template:' namespaceifnotpagethenreturn''-- TODO: error message?endlocalcontent=page:getContent()-- get unparsed contentifnotpagethenreturn''-- TODO: error message?endlocalout={}localparamslocalstyleifcontent:match('{{%s*#invoke:%s*[Ll]ang%s*|[^|]+|[^}]+}}')orcontent:match('{{%s*#invoke:%s*[Ll]ang/sandbox%s*|[^|]+|[^}]+}}')then-- if this template uses [[Module:Lang]]params=content:match('{{%s*#invoke:%s*[Ll]ang%s*|[^|]+(|[^}]+)}}')orcontent:match('{{%s*#invoke:%s*[Ll]ang/sandbox%s*|[^|]+(|[^}]+)}}')-- extract the #invoke:'s parametersifnotparamsthenreturn''-- there should be at least one or the template/module won't work TODO: error message?endtable.insert(out,'{| class="wikitable" style="text-align: right; float: right;"\n|+settings')-- start a wikitablefork,vinparams:gmatch('%s*|%s*([^%s=]+)%s*=%s*([^%s|]+)')do-- get the parameter names (k) and values (v)if'label'==kthen-- special case for labels because spaces and pipesv=params:match('label%s*=%s*(%[%[[^%]]+%]%])')orparams:match('label%s*=%s*([^|\n]+)')or'missing label'endtable.insert(out,table.concat({k,'\n|',v}))-- make rudimentary wikitable entriesendstyle=content:match('lang_xx_([^|]+)')ifnotstyleor('italic'~=mw.text.trim(style)and'inherit'~=mw.text.trim(style))thenreturn'<span style="color:#d33">Error: template #invoke calls unknown function</span>'endreturntable.concat({table.concat(out,'\n|-\n! scope="row" | '),'\n|-\n|colspan="2"|style: ',style,'\n|-\n|}'})-- add inter-row markup and close the wikitable and doneelsereturn''-- does not use [[Module:Lang]] so abandon quietlyendend--[[ -------------------------- < U S E S _ M O D U L E > --------------------------{{#invoke:Lang/documentor tool|uses_module|template={{ROOTPAGENAME}}}}Reads the content of the template to determine if this {{lang-xx}} template uses Module:Lang.Returns the index of the substring '{{#invoke|lang|' in the template page content if true; empty string if false.Used in template documentation {{#if:}} parser functions.]]localfunctionuses_module(frame)localpage=mw.title.makeTitle('Template',frame.args['template']orframe.args[1])-- get a page object for this page in 'Template:' namespaceifnotpagethenreturn''-- TODO: error message?endlocalcontent=page:getContent()-- get unparsed contentifnotpagethenreturn''-- TODO: error message?endreturncontent:find('{{%s*#invoke:[Ll]ang%s*|')or''-- return index or empty stringend--[[ -------------------------- < S H A R E D _ C O D E > --------------------------- Tables:-- LANGUAGE_CATEGORIES-- error_messages-- strings- Functions:-- make_error(message, layout, parent_category, nocat)-- get_language_link(language_name, language_code)-- get_see_also_section(page_title, language_name, language_code)-- get_hidden_category_template(frame)-- get_top_section(frame)-- get_bottom_section(frame, language_name, see_also_section, parent_category)]]localLANGUAGE_CATEGORIES={["LANGUAGES_SOURCES"]="Articles with %s-language sources (%s)",["LANGUAGES_COLLECTIVE_SOURCES"]="Articles with %s-collective sources (%s)",["CS1"]="CS1 %s-language sources (%s)",["CS1_SCRIPT"]="CS1 uses %s-language script (%s)",["LANGUAGE_TEXT"]="Articles containing %s-language text",["LANGUAGES_COLLECTIVE_TEXT"]="Articles with text in %s",["ENGLISH"]="Articles containing explicitly cited %s-language text",["IPA"]="Pages with %s IPA"}localerror_assistance=" Please see [[Template talk:Lang]] for assistance."localerror_messages={["ASSISTANCE"]="Please see [[Template talk:Lang]] for assistance.",["INCORRECT_CATEGORY_TITLE"]="[[:%s]] is not the category being populated by the {{tlx|%s}} template. The correct category is located at: [[:%s]].",["NO_CATEGORY_TITLE_FOUND"]="No language category found for '''%s.'''"..error_assistance,["NOT_VALID_CATEGORY_FORMAT"]="'''%s''' is not a a valid category title."..error_assistance,["NOT_VALID_LANGUAGE_CODE"]="[[%s]] is not a valid ISO 639 or IETF language name."..error_assistance,}localstrings={["ERROR_CATEGORY"]="[[Category:Lang and lang-xx template errors]]",["ERROR_SPAN"]='<span style="font-size: 100%%; font-style: normal;" class="error">Error: %s </span>',["PURGE_DIV"]='<div style="font-size: x-small;">%s</div>',["SEE_ALSO"]="\n==See also==",["SEE_ALSO_ITEM"]="* [[:%s]]",}--[[ -------------------------- < M A K E _ E R R O R > --------------------------Create an error message.Does not place page in error category if args.nocat is used.Does not categorize in parent cateogory if used in category namespace (usually for /testcases).]]localfunctionmake_error(message,layout,parent_category,nocat)table.insert(layout,string.format(strings["ERROR_SPAN"],message))ifnotnocatthentable.insert(layout,strings["ERROR_CATEGORY"])endifmw.title.getCurrentTitle().nsText=="Category"thentable.insert(layout,parent_category)endreturntable.concat(layout)end--[[ -------------------------- < G E T _ L A N G U A G E _ L I N K > --------------------------Generates a language link for the correct style.Collective languages use the name_from_tag value,while other languages use a display name of "x-language".]]localfunctionget_language_link(language_name,language_code)locallang_module=require('Module:Lang')-- Is a language collective?iflanguage_name:find('languages')thenreturnlang_module.name_from_tag({language_code,link="yes"})elsereturnlang_module.name_from_tag({language_code,link="yes",label=lang_module.name_from_tag({language_code}).."-language"})endend--[[ -------------------------- < G E T _ P R I M A R Y _ L A N G U A G E _ C O D E > --------------------------Returns the primary language for sub-langage variants.]]localfunctionget_primary_language_code(language_code)-- If no hyphen exists, return nil (for cases like "el")ifnotlanguage_code:find("-")thenreturnnilend-- Match everything before the first hyphen, but only if a hyphen existsiflanguage_code:match("^-")thenreturnnil-- If the code starts with a hyphen, return nilend-- Look for the first part before any hyphenlocalprimary_code=language_code:match("^[^-]+")returnprimary_codeend--[[ -------------------------- < G E T _ S E E _ A L S O _ S E C T I O N > --------------------------Generates a consistent style See also section for{{Category articles containing non-English-language text}} and {{Non-English-language source category}}.If {{CS1 language sources}} is converted, it should also use it.]]localfunctionget_see_also_section(page_title,language_name,language_code)localsee_also_section={}for_,category_nameinpairs(LANGUAGE_CATEGORIES)dolocalcategory=mw.title.new(string.format(category_name,language_name,language_code),14)ifcategoryandpage_title~=category.textandcategory.existsthentable.insert(see_also_section,string.format(strings["SEE_ALSO_ITEM"],category.prefixedText))endendtable.sort(see_also_section)table.insert(see_also_section,1,strings["SEE_ALSO"])iftable.getn(see_also_section)==1thenreturn""elsereturntable.concat(see_also_section,"\n")endend--[[ -------------------------- < G E T _ H I D D E N _ C A T E G O R Y _ T E M P L A T E > --------------------------Generates the Template:Hidden category template.This function is separate from the get_top_section() functionas this should be used in both error categories and valid categories.]]localfunctionget_hidden_category_template(frame)returnframe:expandTemplate{title='Hidden category'}end--[[ -------------------------- < G E T _ T O P _ S E C T I O N > --------------------------Generates a consistent top maintenance template section which consists of:-- Template:Possibly empty category-- Template:Purge]]localfunctionget_top_section(frame)localtop_section={}ifmw.site.stats.pagesInCategory(mw.title.getCurrentTitle().text,"all")==0thentable.insert(top_section,frame:expandTemplate{title='Possibly empty category'})elsetable.insert(top_section,frame:expandTemplate{title='Possibly empty category',args={hidden=true}})endlocalpurge_module=require('Module:Purge')table.insert(top_section,string.format(strings["PURGE_DIV"],purge_module._main({"Purge page cache"})))returntable.concat(top_section,"\n\n")end--[[ -------------------------- < G E T _ B O T T O M _ S E C T I O N > --------------------------Generates a consistent non-text section which consists of:-- Template:Automatic category TOC-- A see also section-- {{DEFAULTSORT}}-- Categorization in parent category]]localfunctionget_bottom_section(frame,language_name,see_also_section,parent_category,parent_language_category)localbottom_section={}table.insert(bottom_section,frame:expandTemplate{title='Automatic category TOC'})table.insert(bottom_section,see_also_section)ifmw.title.getCurrentTitle().nsText=="Category"thentable.insert(bottom_section,frame:preprocess{text="{{DEFAULTSORT:"..language_name.."}}"})ifparent_language_categorythentable.insert(bottom_section,"[["..parent_language_category.."]]")endtable.insert(bottom_section,parent_category)endreturntable.concat(bottom_section,"\n\n\n")end--[[ -------------------------- < N O N _ E N G L I S H _ L A N G U A G E _ T E X T _ C A T E G O R Y > --------------------------{{#invoke:Lang/documentor tool|non_english_language_text_category}}This function implements {{Non-English-language text category}}.]]localnon_english_language_text_strings={["LINE1"]="This category contains articles with %s%s text. The primary purpose of these categories is to facilitate manual or automated checking of text in other languages.",["LINE2"]="This category should only be added with the %s family of templates, never explicitly.",["LINE3"]='For example %s, which wraps the text with %s. Also available is %s which displays as %s.',["LINE3_SYNTAXHIGHLIGHT"]="<span lang=\"%s\">",["IN_SCRIPT"]=" (in %s)",["EXAMPLE_DEFAULT_TEXT"]="text in %s language here",["PARENT_CATEGORY"]="[[Category:Articles containing non-English-language text]]",["TEMPLATE"]="Lang",["TEMPLATE2"]="Langx",}localfunctionnon_english_language_text_category(frame)localpage=mw.title.getCurrentTitle()localargs=require('Module:Arguments').getArgs(frame)-- args.test is used for /testcasesifargs.testthenpage=mw.title.new(args.test)end-- Naming style: Articles with text from the Berber languages collectivelocalpage_title_modified=page.textlocalsplit_title="([^,]+)%%s([^,]*)"localpart1=""localpart2=""ifpage_title_modified:find('Articles with text in')then-- Naming style: Category:Articles with text from Afro-Asiatic languages (as currently implemented in Module:lang)part1,part2=LANGUAGE_CATEGORIES["LANGUAGES_COLLECTIVE_TEXT"]:match(split_title)elseifpage_title_modified:find('explicitly cited')thenpart1,part2=LANGUAGE_CATEGORIES["ENGLISH"]:match(split_title)else-- Naming style: Category:Articles containing French-language textpart1,part2=LANGUAGE_CATEGORIES["LANGUAGE_TEXT"]:match(split_title)endpage_title_modified=page_title_modified:gsub(part1,"")page_title_modified=page_title_modified:gsub(part2,"")locallanguage_name=page_title_modifiedlocallayout={}table.insert(layout,get_hidden_category_template(frame))localparent_category=non_english_language_text_strings["PARENT_CATEGORY"]iflanguage_name==page.textthen-- Error: Category title format not supported.returnmake_error(string.format(error_messages["NOT_VALID_CATEGORY_FORMAT"],page.text),layout,parent_category,args.nocat)endlocallang_module=require('Module:Lang')locallanguage_code=lang_module._tag_from_name({language_name})iflanguage_code:find('[Ee]rror')then-- Error: Language code not found in database.returnmake_error(string.format(error_messages["NOT_VALID_LANGUAGE_CODE"],language_name),layout,parent_category,args.nocat)endlocalcorrect_language_category_title=lang_module._category_from_tag({language_code})ifcorrect_language_category_title:find('[Ee]rror')then-- Error: No category title found for language code.returnmake_error(string.format(error_messages["NO_CATEGORY_TITLE_FOUND"],language_code),layout,parent_category,args.nocat)endlocalcurrent_category_title=page.prefixedTextifcurrent_category_title~=correct_language_category_titlethen-- Error: The current title used is not in the supported format. TODO: can this still be reached?returnmake_error(string.format(error_messages["INCORRECT_CATEGORY_TITLE"],current_category_title,non_english_language_text_strings["TEMPLATE"],correct_language_category_title),layout,parent_category,args.nocat)endtable.insert(layout,get_top_section(frame))localscript_text=""ifargs.scriptthenscript_text=string.format(non_english_language_text_strings["IN_SCRIPT"],args.script)endlocallanguage_link=get_language_link(language_name,language_code)table.insert(layout,string.format(non_english_language_text_strings["LINE1"],language_link,script_text))locallang_template=frame:expandTemplate{title='Tl',args={non_english_language_text_strings["TEMPLATE"]}}table.insert(layout,string.format(non_english_language_text_strings["LINE2"],lang_template))locallanguage_code_link=lang_module._name_from_tag({language_code,link="yes",label=language_code})localexample_default_text=string.format(non_english_language_text_strings["EXAMPLE_DEFAULT_TEXT"],language_name)localexample_text=args.exampleorexample_default_textlocallang_template_example=frame:expandTemplate{title="Tlx",args={non_english_language_text_strings["TEMPLATE"],language_code_link,example_text}}locallangx_args={non_english_language_text_strings["TEMPLATE2"],language_code_link,example_text}locallangx_template_example=frame:expandTemplate{title="Tlx",args={non_english_language_text_strings["TEMPLATE2"],language_code,example_text}}locallangx_template_code=frame:expandTemplate{title=non_english_language_text_strings["TEMPLATE2"],args={language_code,example_text}}-- Strip private use subtag from code tag because this is what [[Module:Lang]] does.locallanguage_code_without_private_use=language_code:gsub("%-x%-.*","")-- Wrap in syntaxhighlight.localsyntaxhighlight=frame:extensionTag("syntaxhighlight",string.format(non_english_language_text_strings["LINE3_SYNTAXHIGHLIGHT"],language_code_without_private_use),{lang="html",inline=true})table.insert(layout,string.format(non_english_language_text_strings["LINE3"],lang_template_example,syntaxhighlight,langx_template_example,langx_template_code))localsee_also_section=get_see_also_section(page.text,language_name,language_code)localparent_language_code=get_primary_language_code(language_code)localparent_language_categoryifparent_language_codethenparent_language_category=lang_module._category_from_tag({parent_language_code})endlocalbottom=get_bottom_section(frame,language_name,see_also_section,non_english_language_text_strings["PARENT_CATEGORY"],parent_language_category)returntable.concat(layout,"\n\n")..bottomend--[[ -------------------------- < N O N _ E N G L I S H _ L A N G U A G E _ S O U R C E S _ C A T E G O R Y > --------------------------{{#invoke:Lang/documentor tool|non_english_language_sources_category}}This function implements {{Non-English-language sources category}}.]]localnon_english_language_sources_strings={["LINE1"]="This is a tracking category for articles that use %s to identify %s sources.",["PARENT_CATEGORY"]="[[Category:Articles with non-English-language sources]]",["TEMPLATE"]="In lang",}localfunctionnon_english_language_sources_category(frame)localpage=mw.title.getCurrentTitle()localargs=require('Module:Arguments').getArgs(frame)-- args.test is used for /testcasesifargs.testthenpage=mw.title.new(args.test)endlocalpage_title=page.textlocallanguage_code=page_title:match('%(([%a%-]+)%)')locallanguage_name=require('Module:Lang')._name_from_tag({language_code})locallayout={}table.insert(layout,get_hidden_category_template(frame))localparent_category=non_english_language_sources_strings["PARENT_CATEGORY"]localin_lang_module=require('Module:In lang')localcorrect_language_category_title=in_lang_module._in_lang({language_code,["list-cats"]="yes"})ifcorrect_language_category_title==""then-- Error: No category title found for language code.returnmake_error(string.format(error_messages["NO_CATEGORY_TITLE_FOUND"],language_code),layout,parent_category,args.nocat)endlocalcurrent_category_title=page.prefixedTextifcorrect_language_category_title~=current_category_titlethen-- Error: The current title used is not in the supported format.returnmake_error(string.format(error_messages["INCORRECT_CATEGORY_TITLE"],current_category_title,non_english_language_sources_strings["TEMPLATE"],correct_language_category_title),layout,parent_category,args.nocat)endlocallanguage_link=get_language_link(language_name,language_code)localtext=string.format(non_english_language_sources_strings["LINE1"],frame:expandTemplate{title='Tlx',args={non_english_language_sources_strings["TEMPLATE"],language_code}},language_link)table.insert(layout,get_top_section(frame))table.insert(layout,text)localsee_also_section=get_see_also_section(page_title,language_name,language_code)localparent_language_code=get_primary_language_code(language_code)localparent_language_categoryifparent_language_codethenparent_language_category=in_lang_module._in_lang({parent_language_code,["list-cats"]="yes"})endlocalbottom=get_bottom_section(frame,language_name,see_also_section,parent_category,parent_language_category)returntable.concat(layout,"\n\n")..bottomend--[[ -------------------------- < N O N _ E N G L I S H _ L A N G U A G E _ C S 1 _ S O U R C E S _ C A T E G O R Y > --------------------------{{#invoke:Lang/documentor tool|non_english_language_cs1_sources_category}}This function implements {{Non-English-language CS1 sources category}}.]]localnon_english_language_cs1_text_strings={["LINE1"]="This is a tracking category for [[WP:CS1|CS1 citations]] that use the parameter %s to identify a source in [[%s language|%s]]. Pages in this category should only be added by CS1 templates and [[Module:Citation/CS1]].",["PARENT_CATEGORY"]="[[Category:CS1 foreign language sources]]",-- #TODO change to "Articles with non-english CS1 language sources" or "CS1 non-English language sources"}--"This is a tracking category for [[WP:CS1|CS1 citations]] that use the parameter %s to hold a citation title that uses %s characters and contains the language prefix <code>%s:</code>. Pages in this category should only be added by CS1 templates and [[Module:Citation/CS1]].",--"[[Category:CS1 uses foreign language script]]",-- "This is a tracking category for [[WP:CS1|CS1 citations]] that use the parameter %s. Pages in this category should only be added by CS1 templates and [[Module:Citation/CS1]].",-- "to identify a source in [[%s language|%s]].",-- "to hold a citation title that uses %s characters and contains the language prefix <code>%s:</code>.",localfunctionnon_english_language_cs1_sources_category(frame)localpage_title_object=mw.title.getCurrentTitle()localpage_title=page_title_object.textlocallanguage_code=page_title:match('%(([%a%-]+)%)')locallanguage_name=require('Module:Lang')._name_from_tag({language_code})locallayout={}table.insert(layout,get_hidden_category_template(frame))localsee_also_section=""localparameter_doc=frame:expandTemplate{title='para',args={"language",language_code}}table.insert(layout,get_top_section(frame))table.insert(layout,string.format(non_english_language_cs1_text_strings["LINE1"],parameter_doc,language_name,language_name))localsee_also_section=get_see_also_section(page_title,language_name,language_code)localbottom=get_bottom_section(frame,language_name,see_also_section,non_english_language_cs1_text_strings["PARENT_CATEGORY"])returntable.concat(layout,"\n\n")..bottomend--[[ -------------------------- < T E S T _ C A S E S _ S H A R E D _ C O D E > -------------------------- ]]localfunctioncompare_by_keys2(a,b)-- local function used by table.sort()returna[2]<b[2]-- ascending sort by codeendlocalfunctioncompare_by_keys(a,b)-- local function used by table.sort()returna[1]<b[1]-- ascending sort by codeend-- Used by testcases_iso_code_to_name()localfunctionget_language_code_table_from_code(args)localentry={}--if args.override_table[args.language_code] then-- table.insert(entry, args.override_table[args.language_code][1]) -- :gsub(' %b()$', '') fails here--elsetable.insert(entry,args.language_code)-- endreturnentryend-- Used by testcases_name_from_tag()localfunctionget_language_code_and_name_table_from_code(args)localentry={}ifargs.override_tableandargs.override_table[args.language_code]thentable.insert(entry,args.language_code)locallanguage_code,_=args.override_table[args.language_code][1]:gsub(' %b()$','')table.insert(entry,language_code)elsetable.insert(entry,args.language_code)table.insert(entry,args.language_table[args.language_code])endreturnentryend-- Used by testcases_category_from_tag()localfunctionget_language_code_and_category_table_from_code(args)localentry={}table.insert(entry,args.language_code)table.insert(entry,args.test_function({args.language_code}))returnentryend-- Used by testcases_iso_name_to_code() and testcases_tag_from_name()localfunctionget_language_name_and_code_table_from_code(args)localentry={}ifargs.override_table[args.language_code]thentable.insert(entry,args.override_table[args.language_code][1])-- only the first name when there are multiplestable.insert(entry,args.language_code)elsetable.insert(entry,args.language_names[1])-- only the first name when there are multiplestable.insert(entry,args.language_code)endreturnentryendlocalfunctionget_table(table_function,language_table,length,range,iso_number,test_function)localtable_of_language_name_and_code_tables={}localoverride_table_name="override"ifiso_numberthenoverride_table_name="override_"..iso_numberendlocaloverride_table=require("Module:ISO 639 name/ISO_639_override/sandbox")[override_table_name]-- For most ISO 639s.ifrangethenforlanguage_code,language_namesinpairs(language_table)doiflanguage_code:find(range)thentable.insert(table_of_language_name_and_code_tables,table_function({override_table=override_table,language_code=language_code,language_names=language_names,test_function=test_function,language_table=language_table}))endend-- For ISO 639-1.elseiflengththenforlanguage_code,language_namesinpairs(language_table)doiflanguage_code:len()==2thentable.insert(table_of_language_name_and_code_tables,table_function({override_table=override_table,language_code=language_code,language_names=language_names,test_function=test_function,language_table=language_table}))endend-- For general /testcases.elseforlanguage_code,language_namesinpairs(language_table)dotable.insert(table_of_language_name_and_code_tables,table_function({override_table=override_table,language_code=language_code,language_names=language_names,test_function=test_function,language_table=language_table}))endendreturntable_of_language_name_and_code_tablesendlocalfunctionget_undabbed_table(language_list,length,range)localundabbed_language_table={}-- for this test, ISO 639-3 language name disambiguators must be removed; un-dabbed names go hereforlanguage_code,language_namesinpairs(language_list)do-- For most ISO 639s.ifrangetheniflanguage_code:find(range)thenundabbed_language_table[language_code]=language_names[1]:gsub(' %b()$','')-- undab and save only the first name; ignore all other names assigned to a codeend-- For ISO 639-1.elseiflengththeniflanguage_code:len()==2thenundabbed_language_table[language_code]=language_names[1]:gsub(' %b()$','')-- undab and save only the first name; ignore all other names assigned to a codeend-- For general /testcases.elseundabbed_language_table[language_code]=language_names[1]:gsub(' %b()$','')endendreturnundabbed_language_tableend--[[ -------------------------- < T E S T C A S E S _ C A T E G O R Y _ F R O M _ T A G > --------------------------Entry point for the various category_from_tag testcases.Build a table of test patterns where each entry in the table is a table with two members: {"<language_code>", "<category name according to Module:Lang>"}- "Expected" column value is the category name according to Module:Lang.- "Actual" column value is the result of {{#invoke:Lang/sandbox|category_from_tag|<language_code>}}.TODO: Currently not working.]]localfunctiontestcases_category_from_tag(self,args)localcat_from_tag_function=require('Module:Lang')._category_from_taglocallanguage_tables=get_table(get_language_code_and_category_table_from_code,args.language_list,args.length,args.range,args.iso_number,cat_from_tag_function)table.sort(language_tables,compare_by_keys)self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|category_from_tag|','}}','','',language_tables,{nowiki=false})end--[[ -------------------------- < T E S T C A S E S _ N A M E _ F R O M _ T A G > --------------------------Entry point for the various name_from_tag testcases.Build a table of test patterns where each entry in the table is a table with two members: {"<language_code>", "<language_name>"}- "Expected" column value is the <language_name>.- "Actual" column value is the result of sandbox version {{#invoke:Lang/sandbox|name_from_tag|<language_code>}}.]]localfunctiontestcases_name_from_tag(self,args)localundabbed_language_table=get_undabbed_table(args.language_list,args.length,args.range,nil)locallanguage_tables=get_table(get_language_code_and_name_table_from_code,undabbed_language_table,args.length,args.range)table.sort(language_tables,compare_by_keys)self:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|name_from_tag|','}}','','',language_tables,{nowiki=false})end--[[ -------------------------- < T E S T C A S E S _ T A G _ F R O M _ N A M E > --------------------------Entry point for the various tag_from_name testcases.Build a table of test patterns where each entry in the table is a table with two members: {"<language_name>", "<language_code>"}- "Expected" column value is the <language_code>.- "Actual" column value is the result of sandbox version {{#invoke:Lang/sandbox|tag_from_name|<language_name>}}.TODO: Currently not working.]]localfunctiontestcases_tag_from_name(self,args)locallanguage_tables=get_table(get_language_name_and_code_table_from_code,args.language_list,args.length,args.range,args.iso_number,nil)table.sort(language_tables,compare_by_keys2)localordered_table={}table.sort(unordered_table)for_,keyinipairs(unordered_table)dotable.insert(ordered_table,{key,reverse_table[key]})endself:preprocess_equals_preprocess_many('{{#invoke:Lang/sandbox|tag_from_name|','}}','','',language_tables,{nowiki=false})end--[[ -------------------------- < T E S T C A S E S _ I S O _ C O D E _ T O _ N A M E > --------------------------Entry point for the various iso_code_to_name testcases.Build a table of test patterns where each entry in the table is a table with one member: {"<language_code>"}- "Expected" column value is the result of the live version of {{#invoke:ISO 639 name|iso_639_name_to_code|<language_code>}}.- "Actual" column value is the result of sandbox version {{#invoke:ISO 639 name/sandbox|iso_639_name_to_code|<language_code>}}.]]localfunctiontestcases_iso_code_to_name(self,args)locallanguage_tables=get_table(get_language_code_table_from_code,args.language_list,args.length,args.range,args.iso_number,nil)table.sort(language_tables,compare_by_keys)self:preprocess_equals_preprocess_many('{{#invoke:ISO 639 name/sandbox|iso_639_code_to_name|link=yes|','}}','{{#invoke:ISO 639 name|iso_639_code_to_name|link=yes|','}}',language_tables,{nowiki=false})end--[[ -------------------------- < T E S T C A S E S _ I S O _ N A M E _ T O _ C O D E > --------------------------Entry point for the various iso_name_to_code testcases.Build a table of test patterns where each entry in the table is a table with two members: {"<language_name>", "<language_code>"}- "Expected" column value is the <language_code>.- "Actual" column is value the result of {{#invoke:ISO 639 name/sandbox|iso_639_name_to_code|<language_name>}}.]]localfunctiontestcases_iso_name_to_code(self,args)locallanguage_tables=get_table(get_language_name_and_code_table_from_code,args.language_list,args.length,args.range,args.iso_number,nil)table.sort(language_tables,compare_by_keys2)self:preprocess_equals_preprocess_many('{{#invoke:ISO 639 name/sandbox|iso_639_name_to_code|2='..args.iso_number.."|",'}}','','',language_tables,{nowiki=false})end--[[--------------------------< S E E _ A L S O >--------------------------------------------------------------adds items to the list of items in §See also section of Template:Lang-x/doc; Evaluates single positional parameterwhich is a comma-separated list of items including list markup. {{#invoke:Lang/documentor tool|see_also|*{{tl|Lang-tt-Cyrl}}, *{{tl|Lang-tt-Latn}}, *{{tl|Lang-tt-Arab}}}}]]localfunctionsee_also(frame)ifnil==frame.args[1]or''==frame.args[1]then-- if empty, ...return-- ... return nothingendreturnframe:preprocess(frame.args[1]:gsub('%s*,%s','\n'))-- preprocess so any templates are rendered before saving and doneend--[[ -------------------------< E X P O R T E D _ F U N C T I O N S > -----------------------------------------]]return{lang_xx_settings=lang_xx_settings,uses_module=uses_module,see_also=see_also,non_english_language_text_category=non_english_language_text_category,non_english_language_sources_category=non_english_language_sources_category,non_english_language_cs1_sources_category=non_english_language_cs1_sources_category,private_tags=private_tags,-- Module:Lang testcasestestcases_category_from_tag=testcases_category_from_tag,testcases_name_from_tag=testcases_name_from_tag,testcases_tag_from_name=testcases_tag_from_name,-- Module:ISO 639 name testcasestestcases_iso_code_to_name=testcases_iso_code_to_name,testcases_iso_name_to_code=testcases_iso_name_to_code,}