Module:Lang: Difference between revisions
EnWikiAdmin (talk | contribs) m 1 revision imported |
EnWikiAdmin (talk | contribs) m 1 revision imported |
||
(One intermediate revision by one other user not shown) | |||
Line 1,054: | Line 1,054: | ||
local function is_latin (text, script, transl) | local function is_latin (text, script, transl) | ||
if mw.ustring. | text = mw.text.decode (text); -- convert html entities to characters | ||
text = | script = (script and script:lower()) or nil; -- ensure lowercase for comparisons | ||
if transl then -- not nil for {{transliteration}}; assume | 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 | 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 |