Content deleted Content added
No edit summary |
No edit summary |
||
Line 1,055:
local function is_latin (text, script, transl)
text = mw.text.decode (text); -- convert html entities to characters
script = (script and script:lower()) or nil; -- ensure lowercase for comparisons
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 transl then -- not nil for {{transliteration}}; assume Latn because this is 'transliteration' template
return true;
end
return (script and ('latn' == script
end
return unicode.is_Latin (text); -- return true when all characters in modified <text> are Latn script; false else
|