Module:Languages

local l = {}

local function escRx(text) text = mw.ustring.gsub(text, '%\\', '\\\\') text = mw.ustring.gsub(text, '%(', '\\(') text = mw.ustring.gsub(text, '%)', '\\)') text = mw.ustring.gsub(text, '%.', '\\.') text = mw.ustring.gsub(text, '%+', '\\+') text = mw.ustring.gsub(text, '%*', '\\*') text = mw.ustring.gsub(text, '%?', '\\?') text = mw.ustring.gsub(text, '%^', '\\^') text = mw.ustring.gsub(text, '%$', '\\$') text = mw.ustring.gsub(text, '%-', '\\-') text = mw.ustring.gsub(text, '/', '\\/') text = mw.ustring.gsub(text, '=', '\\=') text = mw.ustring.gsub(text, '!', '\\!') text = mw.ustring.gsub(text, ':', '\\:') return text end local function makeLink(root, lang, text, exists) local page = root if lang then page = page .. '/' .. lang end if exists then return ..text.. else root = mw.ustring.gsub(root, '^:', '') return ' ['..tostring(mw.uri.fullUrl( page, 'action=edit&preload='..root ))..' '..text..'] ' end end function l.langs(frame) local title, root = mw.title.getCurrentTitle if mw.ustring.find(title.subpageText, '[a-z-]+') and mw.language.fetchLanguageName(title.subpageText) ~= '' then root = title.baseText else root = title.text end local args = require('Dev:Arguments').getArgs(frame, {   	trim = true,    	removeBlanks = true,    	frameOnly = true,    	wrappers = {    		'Template:Languages'    	},    	readOnly = true    }) local rootLang = mw.ustring.lower(args['root'] or 'en') local langs = {} for i,v in ipairs(args or {}) do       v = mw.ustring.lower(mw.text.trim(v or '')) if v ~= '' then langs[v] = false end end local existing = frame:preprocess('') root = mw.ustring.gsub(':' .. title.nsText .. ':' .. root, '^::', '') if mw.ustring.find(existing, '^%|.*%|$') then existing = mw.text.split(mw.ustring.sub(existing, 2, -2), '|') for i,v in ipairs(existing or {}) do           v = mw.ustring.lower(mw.text.trim(v or '')) if v ~= '' then langs[v] = true end end end local ordered = {} for k,v in pairs(langs) do       if k ~= rootLang then ordered[#ordered+1] = k       end end table.sort(ordered) local separator = frame:preprocess('') local div = mw.html.create('div'):addClass(args['class']) div:tag('strong'):wikitext(frame:preprocess('')):done:wikitext(' ') div:wikitext(makeLink(root, nil, mw.language.fetchLanguageName(rootLang), true)) for _,lang in ipairs(ordered) do       local name = mw.language.fetchLanguageName(lang) div:wikitext(separator):wikitext(makeLink(root, lang, name, langs[lang])) end return div end

return l