Module:User:Lunabunn/Babel

Hello, you have come here looking for the meaning of the word Module:User:Lunabunn/Babel. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:Lunabunn/Babel, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:Lunabunn/Babel in singular and plural. Everything you need to know about the word Module:User:Lunabunn/Babel you have here. The definition of the word Module:User:Lunabunn/Babel will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:Lunabunn/Babel, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local export = {}

local m_para = require("Module:parameters")
local m_lang = require("Module:languages")
local m_sc = require("Module:scripts")
local m_data = require("Module:Babel/data")
local m_table = require("Module:Babel/table")
local track = require("Module:debug/track")
local profs = m_data.proficiencies
local programming_profs = m_data.programming_proficiencies
local script_profs = m_data.script_proficiencies

local function soft_error(key, err, lang)
	track("Babel/" .. key) track("Babel/" .. key .. "/" .. lang)
	return '<span class="error">' .. err .. lang .. '</span><br>'
end

local function process(lang_n)
	-- takes a string of the format "languagecode-number" and outputs a table
	local result = {
		lang_n:gsub("-$", ""),
		lang_n:match("$")
	}
	if not result then result = "N" end
	return result
end

local function grab_lang_message(code)
	-- given a string of the format languagecode-proficiency, fetches the 
	-- translated message from the data subpages
	local subpage = mw.loadData(
		mw.title.new("Module:Babel/data/" .. code:sub(1, 1)).fullText
	)
	return subpage
end

local function is_valid_proglang(code)
	for i,_ in pairs(m_data.proglangs) do
		if code:lower() == i then return code end
	end
end

local function make_table(lang_n, nocat)
	if not lang_n then return "align=center style=\"font-style:italic;\" | "
		.. "You haven't set up any languages. "
		.. "Please see ] for help." 
	elseif lang_n:find("UNIQ") then
		track("Babel/direct user lang call")
		return ""
	elseif lang_n == "!" then
		return "\n|\n"
	elseif lang_n == "-" then
		return "<div style=\"float: left; margin: 2px;\">\n"
			.. "{| cellspacing=\"0\" style=\"width: 238px;\"\n"
			.. "| style=\"width: 45px; height: 45px;\" | &nbsp;\n"
			.. "|style=\"font-size: 8pt; padding: 4pt; line-height: 1.25em;\" | &nbsp;\n|}</div>"
	elseif lang_n == "----" then
		return "<div style=\"clear: both; padding: 0.25em 0;\"><hr/></div>"
	end
	local processed = process(lang_n)
	local lang, prof = processed, processed
	local lang_name, script -- script is actually only for when a script code is affixed to the langcode; script codes are treated as langs otherwise
	local is_programming_lang, is_script
	local lang_proper -- store lang code without script code for use in {{lang}}
	if lang:find("-%u%l+") then
		-- automatically truncate script code from code to allow eg zh-Hant if there's no data entry
		local truncated = lang:gsub("-%u%l+", "")
		local lang_object = m_lang.getByCode(truncated)
		if not lang_object and m_data.region_codes then
			lang_name = m_data.region_codes
		elseif lang_object then
			lang_name = lang_object:getCanonicalName()
			local script_code = lang:match("%u%l+")
			script = m_sc.getByCode(script_code)
			if not script then return soft_error("invalid script code", "Invalid script code: ", script_code) end
			script = script
			-- store and check script code for categorisation later
		else return soft_error("invalid language code", "Invalid language code: ", lang)
		end
		lang_proper = truncated:gsub("-%u+", "")
	elseif m_data.region_codes then
		-- allow predefined region code affixes
		lang_name = m_data.region_codes
		lang_proper = lang:gsub("-%u+", "")
	elseif is_valid_proglang(lang) then
		lang_name = lang
		is_programming_lang = 1 -- flag for different messages later
	elseif m_lang.getByCode(lang) then
		lang_name = m_lang.getByCode(lang):getCanonicalName()
	elseif m_sc.getByCode(lang) then
		lang_name = m_sc.getByCode(lang):getCanonicalName()
		is_script = 1 -- flag for different messages later
	elseif m_data.script_messages then
		is_script = 1
	else
		return soft_error("invalid language code", "Invalid language code: ", lang)
	end
	lang_proper = lang_proper or lang
	local table_data = {
		code = lang_proper,
		proficiency = prof,
		display_code = lang,
		is_programming_lang = is_programming_lang,
		lang_n = lang_n,
	}
	table_data.text = m_data.script_messages
	if is_script == 1 then
		table_data.text = table_data.text or script_profs
	elseif is_programming_lang == 1 then
		table_data.text = table_data.text or programming_profs
	else
		table_data.text = grab_lang_message(lang .. "-" .. prof) or profs
	end
	table_data.text = table_data.text:gsub("{-}", 
		function(arg)
			local forms = {
				arg:match("{+"):gsub("{", ""), -- masculine
				arg:match("%++%+"):gsub("%+", ""), -- feminine
				nil -- neutral (default to nil)
			}
			if arg:match("+}") then forms = arg:match("+}"):gsub("}", "") end
			return mw.getContentLanguage():gender(mw.title.getCurrentTitle().rootText, forms)
		end)
	if table_data.text:find("hiero") then
		table_data.text = mw.getCurrentFrame():preprocess(table_data.text) -- preprocess uses of <hiero></hiero>
	end
	local cats = { = "Category:User " .. lang}
	if is_programming_lang then
		if m_data.proglangs.cat then
			cats = "Category:User " .. m_data.proglangs.cat .. " coder-" .. prof
			cats = cats:gsub(lang, m_data.proglangs.cat) .. " coder"
		else
			cats = "Category:User " .. lang .. " coder-" .. prof
			cats = cats .. " coder"
		end
	else
		cats = "Category:User " .. lang .. "-" .. prof
	end
	if script then
		table.insert(cats, "Category:User " .. script .. "-" .. prof)
		table.insert(cats, "Category:User " .. script)
	end
	table_data.text = table_data.text:gsub("$1", ":" .. cats)
		:gsub("$2", ":" .. cats)
		:gsub("$3", lang_name or "")
	local result = m_table.generate_table(table_data)
	local title = mw.title.getCurrentTitle()
	local is_userpage = title:inNamespace("User") and title.text == title.rootText
	if not nocat and is_userpage and prof ~= "0" then
		for _,i in ipairs(cats) do
			result = result .. "]"
		end
	end
	return result
end

function export.show(frame)
	local args = m_para.process(frame:getParent().args,{ 
		 = { list = true },
		 = { boolean = true },
		 = { set = {"left", "right", "none"}, default = "right" },
		 = { alias_of = "float" },
		 = { default = "248px" },
		 = { default = "#99B3FF" },
		 = { default = "]" },
		 = { default = "inherit" },
		 = { default = "Search [[:Category:User languages|"
			.. "user languages]] or ]" },
		 = { alias_of = "border_color" },
		 = { alias_of = "border_color" },
		 = {},
		 = { alias_of = "gender" },
	})
	local result = {}
	if not args then
		table.insert(result, make_table(nil, args))
	else
		for _,i in ipairs(args) do
			table.insert(result, make_table(i, args))
		end
	end
	if args and require("Module:pages").is_preview() then
		args = args .. "\n<span class=\"error\""
			.. "style =\"font-size:75%;\">"
			.. "Gender is automatically grabbed from your preferences.\n"
			.. "You can remove the gender parameter.</span>"
	end
	return "{| name=\"userboxes\" id=\"userboxes\""
		.. "style=\"float: " .. args .. "; margin-left: 1em;"
		.. "margin-bottom: 0.5em; width: " .. args .. "; border: "
		.. args .. " solid 1px;"
		.. "clear: " .. args .. ";\"\n"
		.. "! style=\"background-color: " .. args .. "; text-align:"
		.. "center\" colspan=\"10\" | " .. args .. "\n"
		.. "|- style=vertical-align:top\n"
		.. "|" .. table.concat(result, "") .. "\n"
		.. "|-\n| style=\"background-color: " .. args .. ";"
		.. "text-align: center;\" colspan=\"10\" | " .. args
		.. "\n|}"
end

return export