Module:languages: Difference between revisions
No edit summary |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 965: | Line 965: | ||
first_sc = get_script(first_sc) | first_sc = get_script(first_sc) | ||
local charset = first_sc.characters | local charset = first_sc.characters | ||
return charset and umatch(text, "[" .. charset .. "]") and first_sc or get_script("None") | |||
return charset and umatch(text, "[" .. ugsub(charset, "%]", "%%]") .. "]") and first_sc or get_script("None") | |||
end | end | ||
| Line 1,020: | Line 1,021: | ||
-- Count characters by removing everything in the script's charset and comparing to the original length. | -- Count characters by removing everything in the script's charset and comparing to the original length. | ||
local charset = sc.characters | local charset = sc.characters | ||
local count = charset and length - ulen((ugsub(text, "[" .. charset .. "]+", ""))) or 0 | local count = charset and length - ulen((ugsub(text, "[" .. charset:gsub("%]", "%%]") .. "]+", ""))) or 0 | ||
if count >= length then | if count >= length then | ||
| Line 1,917: | Line 1,918: | ||
-- Incomplete transliterations return nil. | -- Incomplete transliterations return nil. | ||
local charset = sc.characters | local charset = sc.characters | ||
if charset and umatch(text, "[" .. charset .. "]") then | if charset and umatch(text, "[" .. charset:gsub("%]", "%%]") .. "]") then | ||
-- Remove any characters in Latin, which includes Latin characters also included in other scripts (as these are | -- Remove any characters in Latin, which includes Latin characters also included in other scripts (as these are | ||
-- false positives), as well as any PUA substitutions. Anything remaining should only be script code "None" | -- false positives), as well as any PUA substitutions. Anything remaining should only be script code "None" | ||