Module:Languages

local l = {}

local function escRx(text, spaces) 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, ':', '\\:') if spaces then text = mw.ustring.gsub(text, ' ', '_') end 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&redlink=1&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,    	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('') existing = select(3, mw.ustring.find(existing, '^%s*%|([%|a-z-]*)%|%s*$')) if existing then existing = mw.text.split(existing, '|') 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(' ') root = mw.ustring.gsub(':' .. title.nsText .. ':' .. root, '^::', '') 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