Module:Wikt-lang: Difference between revisions

Content deleted Content added
ustring function only needed to handle entry-name replacements; elsewhere, bytewise string functions are fine
recognize single private-use subtag (for ine-x-proto, gem-x-proto)
Line 42:
end
end
end
 
local function fixScriptCode(firstLetter, threeLetters)
return string.upper(afirstLetter) .. string.lower(bthreeLetters)
end
 
Line 49 ⟶ 53:
if codes == nil or codes == "" then
errorText = 'no language or script code provided'
-- Private-use subtag: x followed by one or more sequences of 1-8 lowercase
-- letters separated by hyphens. This only allows for one sequence, as it is
-- needed for proto-languages such as ine-x-proto (Proto-Indo-European).
elseif codes:find("^%s*%a%a%a%?-x%-%a%a?%a?%a?%a?%a?%a?%a?") then
languageCode, scriptCode =
codes:match("^%s*(%a%a%a%-x%-%a%a?%a?%a?%a?%a?%a?%a?)%-?(.+)")
if not languageCode then
errorText = '<code>'..codes..'</code> is not a valid language or script code.'
elseif not scriptCode:find("%a%a%a%a") then
errorText = '<code>'..invalidCode..'</code> is not a valid script code.'
else
scriptCode = scriptCode:gsub(
"(%a)(%a%a%a?)",
fixScriptCode,
1
)
end,
elseif codes:find("^%s*%a%a%a?%s*$") or codes:find("^%s*%a%a%a?%-%a%a%a%a%s*$") then
-- A three- or two-letter lowercase sequence at beginning of first parameter
Line 55 ⟶ 78:
codes:match("^%s*(%l%l%l?)")
or codes:match("^%s*(%a%a%a?)")
:gsub("(%a%a%a?)", string.lower, 1)
"(%a%a%a?)",
string.lower,
1
)
)
-- One uppercase and three lowercase letters at the end of the first parameter
Line 68 ⟶ 87:
codes:match("(%a%a%a%a)%s*$"),
"(%a)(%a%a%a)",
function(afixScriptCode, b)
return string.upper(a) .. string.lower(b)
end,
1
)
Line 86 ⟶ 103:
scriptCode,
"(%a)(%a%a%a)",
fixScriptCode
function(a, b)
return string.upper(a) .. string.lower(b)
end
)
errorText = '<code>'..invalidCode..'</code> is not a valid language code.'