Module:Lang: Difference between revisions

m 1 revision imported
No edit summary
Line 1,054: Line 1,054:


local function is_latin (text, script, transl)
local function is_latin (text, script, transl)
if mw.ustring.find (text, 'θ', 1, true) then -- does <text> contain 'θ'?
text = mw.text.decode (text); -- convert html entities to characters
text = text:gsub ('θ', ''); -- remove theta from <text>
script = (script and script:lower()) or nil; -- ensure lowercase for comparisons
if 0 == text:len() then -- will be zero if theta was the only character in <text>
if transl then -- not nil for {{transliteration}}; assume Latin theta because this is 'transliteration' template
local whitelist = '[ʻʼʽʾʿΔαβγδθλσφχϑъьӾӿᾱῑ῾上入去平阳阴]'
 
if not transl then -- testing {{lang}} or {{langx}} <text>
if '' == mw.ustring.gsub (text, whitelist, '') then -- when <text> uses only whitelisted characters
return ('latn' == script); -- true when latn script; false when other script or no script
end
end
 
if mw.ustring.find (text, whitelist) then -- does <text> contain characters from the whitelist?
text = mw.ustring.gsub (text, whitelist, 'x'); -- replace whitelisted characters from <text> with known Latn-script char 'x'
-- if 0 == text:len() then -- will be zero if theta was the only character in <text>
if '' == text then -- will be empty string if the only character(s) in <text> are in <whitelist>
if transl then -- not nil for {{transliteration}}; assume Latn because this is 'transliteration' template
return true;
return true;
end
end
return (script and ('latn' == script:lower())) or false; -- {{lang}}, {{langx}}, and {{lang-??}}; true when script is Latn; false else
return (script and ('latn' == script)) or false; -- {{lang}}, {{langx}}, and {{lang-??}}; true when script is Latn; false else
end
end
return unicode.is_Latin (text); -- return true when all characters in modified <text> are Latn script; false else
return unicode.is_Latin (text); -- return true when all characters in modified <text> are Latn script; false else