Module:Wikt-lang: Difference between revisions

Content deleted Content added
determine code validity
trying to make checking for validity less taxing
Line 6:
local find = mw.ustring.find
local match = mw.ustring.match
local lower = mw.ustring.lower
local upper = mw.ustring.upper
local U = mw.ustring.char
 
Line 181 ⟶ 183:
end
 
local function stripmakeEntryName(word, languageCode)
local data = languages[languageCode]
word = tostring(word)
if word == nil then
error("The function stripmakeEntryName requires a string argument")
elseif word == "" then
return ""
Line 222 ⟶ 224:
function p.lang(frame)
-- A three- or two-letter lowercase sequence at beginning of first parameter
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\]\]}}")
-- One uppercase and three lowercase letters at the end of the first parameter
local scriptCode = match(frame.args[1], "(%u%l%l%l)%s*$") or nil
Line 248 ⟶ 250:
function p.wikt(frame)
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
local languageCode = match(codes, "^%s*(%l%l%l)") or match(codes, "^%s*(%l%l)")
languageCode = match(codes, "^%s*(%l%l%l)") or match(codes, "^%s*(%l%l)") --[[ or gsub(match(codes, "^%s*(%a%a%a?)"), "^%s*(%a%a%a?)", function(a) return lower(a) end)]] or error("No language code was found in the first parameter")
-- One uppercase and three lowercase letters at the end of the first parameter
local scriptCode = match(codes, "(%u%l%l%l)%s*$") or nil
scriptCode = 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)]] or nil
else
error("No content in the first parameter")
end
local word1 = frame.args[2]
local word2 = frame.args[3]
Line 263 ⟶ 270:
if languageCode then
if checkForString(word2) and checkForString(word1) then
entry = stripmakeEntryName(word1, languageCode)
linkText = word2
elseif checkForString(word1) then
entry = stripmakeEntryName(word1, languageCode)
linkText = word1
else