Module:Wikt-lang: Difference between revisions

Content deleted Content added
trying to make checking for validity less taxing
repair codes with improper capitalization
Line 223:
 
function p.lang(frame)
local codes = frame.args[1]
-- A three- or two-letter lowercase sequence at beginning of first parameter
local languageCode, scriptCode
local languageCode = match(frame.args[1], "^%s*(%l%l%l)") or match(frame.args[1], "^%s*(%l%l)") or error("Place a valid language code in the first parameter of {{\[\[Template:Lang/sandbox|lang/sandbox\]\]}}")
if codes then
-- One uppercase and three lowercase letters at the end of the first parameter
-- A three- or two-letter lowercase sequence at beginning of first parameter
local scriptCode = match(frame.args[1], "(%u%l%l%l)%s*$") or nil
languageCode = find(codes, "%a%a%a?") and (match(codes, "^%s*(%l%l%l?)") or gsub(match(codes, "^%s*(%a%a%a?)"), "(%a%a%a?)", function(a) return lower(a) end, 1) ) or error("No language code was found in the first parameter")
-- One uppercase and three lowercase letters at the end of the first parameter
scriptCode = find(codes, "%a%a%a%a%s*$") and (match(codes, "(%u%l%l%l)%s*$") or gsub(match(codes, "(%a%a%a%a)%s*$"), "(%a)(%a%a%a)", function(a, b) return upper(a) .. lower(b) end, 1) ) or nil
else
error("No content in the first parameter")
end
local text = frame.args[2] or error("Provide text in the second parameter")
local italics = frame.args["italics"] or frame.args["i"] or "auto"
Line 251 ⟶ 257:
local codes = frame.args[1]
local languageCode, scriptCode
local validity = (find(codes, "^%s*%l%l%l?%s*$") or find(codes, "^%s*%l%l%l?-%u%l%l%l%s*$") ) and "correct capitalization" or (find(codes, "^%s*%a%a%a?%s*$") or find(codes, "^%s*%a%a%a?-%a%a%a%a%s*$") ) and "incorrect capitalization" or "invalid"
if validity == "invalid" then
error("Language or script code or codes in first parameter not recognized")
end
if codes then
-- A three- or two-letter lowercase sequence at beginning of first parameter
languageCode = matchfind(codes, "^%s*(a%la%l%l)a?") orand (match(codes, "^%s*(%l%l%l?)") --[[ or gsub(match(codes, "^%s*(%a%a%a?)"), "^%s*(%a%a%a?)", function(a) return lower(a) end, 1) )]] or error("No language code was found in the first parameter")
-- One uppercase and three lowercase letters at the end of the first parameter
scriptCode = find(codes, "%a%a%a%a%s*$") and (match(codes, "(%u%l%l%l)%s*$") --[[ or gsub(match(codes, "(%a%a%a%a)%s*$"), "(%a)(%a%a%a)%s*$", function(a, b) return upper(a) .. lower(b) end, 1) )]] or nil
else
error("No content in the first parameter")