localexport={}localArray=require("Module:array")localm_lang=require("Module:languages")functionexport.categorize(title,langs,sortkey)langs=Array(langs):slice()localname=title.text:gsub("^R:","")locallang_in_title,rest=name:match("^(%l[%l-]*%l):(.+)$")iflang_in_titlethenifnotm_lang.getByCode(lang_in_title)thenlang_in_title=lang_in_title.."-pro"endifm_lang.getByCode(lang_in_title)andnotlangs:contains(lang_in_title)thenlangs:insert(1,lang_in_title)endname=restendsortkey=sortkeyornamereturnlangs:map(function(langCode)locallang=m_lang.getByCode(langCode,true)return"[[หมวดหมู่:แม่แบบการอ้างอิง"..lang:getCategoryName().."|"..sortkey.."]]"end):concat""endfunctionexport.main(frame)localcurrent_title=mw.title.getCurrentTitle()ifcurrent_title.nsText==""orcurrent_title.nsText=="การสืบสร้าง"thenerror("This template is meant to be used in the Template namespace.")endlocalargs=frame:getParent().argslocalsortkey=args.sortlocalargs=Array.shallow_copy(args)localtitle=current_titlelocalis_demo=current_title.nsText=="มอดูล"or(current_title.nsText=="แม่แบบ"andcurrent_title.baseText=="reference template cat")ifis_demoandargs.titlethentitle=mw.title.new(args.title)args.title=nilendargs.sort=nillocallangs=argsifnotlangs:is_array()thenerror("Sequential positional parameters expected")endlocalcategories=export.categorize(title,langs,sortkey)ifis_demothencategories=mw.text.nowiki(categories)endreturncategoriesendreturnexport