Module:Linb-utilities
Jump to navigation
Jump to search
- This module lacks a documentation subpage. Please create it.
- Useful links: subpage list โข links โข transclusions โข testcases โข sandbox
local export = {}
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local dig_chars = {
[""] = 0,
["๐"] = 1,
["๐"] = 2,
["๐"] = 3,
["๐"] = 4,
["๐"] = 5,
["๐"] = 6,
["๐"] = 7,
["๐"] = 8,
["๐"] = 9,
["๐"] = 10,
["๐"] = 20,
["๐"] = 30,
["๐"] = 40,
["๐"] = 50,
["๐"] = 60,
["๐"] = 70,
["๐"] = 80,
["๐"] = 90,
["๐"] = 100,
["๐"] = 200,
["๐"] = 300,
["๐"] = 400,
["๐"] = 500,
["๐"] = 600,
["๐"] = 700,
["๐ "] = 800,
["๐ก"] = 900,
["๐ข"] = 1000,
["๐ฃ"] = 2000,
["๐ค"] = 3000,
["๐ฅ"] = 4000,
["๐ฆ"] = 5000,
["๐ง"] = 6000,
["๐จ"] = 7000,
["๐ฉ"] = 8000,
["๐ช"] = 9000,
["๐ซ"] = 10000,
["๐ฌ"] = 20000,
["๐ญ"] = 30000,
["๐ฎ"] = 40000,
["๐ฏ"] = 50000,
["๐ฐ"] = 60000,
["๐ฑ"] = 70000,
["๐ฒ"] = 80000,
["๐ณ"] = 90000,
}
local chars = {
-- SYLLABOGRAMS --
["๐
"] = { id = "1", tl = "da" },
["๐ซ"] = { id = "2", tl = "ro" },
["๐"] = { id = "3", tl = "pa" },
["๐ณ"] = { id = "4", tl = "te" },
["๐ต"] = { id = "5", tl = "to" },
["๐"] = { id = "6", tl = "na" },
["๐"] = { id = "7", tl = "di" },
["๐"] = { id = "8", tl = "a" },
["๐ฎ"] = { id = "9", tl = "se" },
["๐"] = { id = "10", tl = "u" },
["๐ก"] = { id = "11", tl = "po" },
["๐ฐ"] = { id = "12", tl = "so" },
["๐"] = { id = "13", tl = "me" },
["๐"] = { id = "14", tl = "do" },
["๐"] = { id = "15", tl = "mo" },
["๐ฃ"] = { id = "16", tl = "qa" },
["๐ผ"] = { id = "17", tl = "za" },
["๐"] = { id = "18" },
["๐"] = { id = "19" },
["๐ฟ"] = { id = "20", tl = "zo" },
["๐ฅ"] = { id = "21", tl = "qi" },
["๐"] = { id = "22" },
["๐"] = { id = "23", tl = "mu" },
["๐"] = { id = "24", tl = "ne" },
["๐"] = { id = "25", tl = "a2" },
["๐ฌ"] = { id = "26", tl = "ru" },
["๐ฉ"] = { id = "27", tl = "re" },
["๐"] = { id = "28", tl = "i" },
["๐"] = { id = "29", tl = "pu2" },
["๐"] = { id = "30", tl = "ni" },
["๐ญ"] = { id = "31", tl = "sa" },
["๐ฆ"] = { id = "32", tl = "qo" },
["๐"] = { id = "33", tl = "ra3" },
["๐"] = { id = "34" },
-- *35 is a flipped variant of *34
["๐"] = { id = "36", tl = "jo" },
["๐ด"] = { id = "37", tl = "ti" },
["๐"] = { id = "38", tl = "e" },
["๐ "] = { id = "39", tl = "pi" },
["๐น"] = { id = "40", tl = "wi" },
["๐ฏ"] = { id = "41", tl = "si" },
["๐บ"] = { id = "42", tl = "wo" },
["๐"] = { id = "43", tl = "a3" },
["๐"] = { id = "44", tl = "ke" },
["๐"] = { id = "45", tl = "de" },
["๐"] = { id = "46", tl = "je" },
["๐"] = { id = "47" },
["๐
"] = { id = "48", tl = "nwa" },
["๐"] = { id = "49" },
["๐ข"] = { id = "50", tl = "pu" },
["๐"] = { id = "51", tl = "du" },
["๐"] = { id = "52", tl = "no" },
["๐ช"] = { id = "53", tl = "ri" },
["๐ท"] = { id = "54", tl = "wa" },
["๐"] = { id = "55", tl = "nu" },
["๐"] = { id = "56" },
["๐"] = { id = "57", tl = "ja" },
["๐ฑ"] = { id = "58", tl = "su" },
["๐ฒ"] = { id = "59", tl = "ta" },
["๐จ"] = { id = "60", tl = "ra" },
["๐"] = { id = "61", tl = "o" },
["๐"] = { id = "62", tl = "pte" },
["๐"] = { id = "63" },
["๐"] = { id = "64" },
["๐"] = { id = "65", tl = "ju" },
["๐"] = { id = "66", tl = "ta2" },
["๐"] = { id = "67", tl = "ki" },
["๐"] = { id = "68", tl = "ro2" },
["๐ถ"] = { id = "69", tl = "tu" },
["๐"] = { id = "70", tl = "ko" },
["๐"] = { id = "71", tl = "dwe" },
["๐"] = { id = "72", tl = "pe" },
["๐"] = { id = "73", tl = "mi" },
["๐ฝ"] = { id = "74", tl = "ze" },
["๐ธ"] = { id = "75", tl = "we" },
["๐"] = { id = "76", tl = "ra2" },
["๐"] = { id = "77", tl = "ka" },
["๐ค"] = { id = "78", tl = "qe" },
["๐"] = { id = "79" },
["๐"] = { id = "80", tl = "ma" },
["๐"] = { id = "81", tl = "ku" },
["๐"] = { id = "82" },
["๐"] = { id = "83" },
-- *84
["๐"] = { id = "85", tl = "au" },
["๐"] = { id = "86" },
["๐"] = { id = "87", tl = "twe" },
-- *88
["๐"] = { id = "89" },
["๐"] = { id = "90", tl = "dwo" },
["๐"] = { id = "91", tl = "two" },
-- IDEOGRAMS --
["๐"] = { id = "100", tl = "VIR" },
-- *101 is a variant of *100
["๐"] = { id = "102", tl = "MUL" },
-- *103 is a variant of *102
["๐"] = { id = "104", tl = "CERV" },
["๐"] = { id = "105", tl = "EQU" },
["๐"] = { id = "105f", tl = "EQU<sup>f</sup>" },
["๐
"] = { id = "105m", tl = "EQU<sup>m</sup>" },
["$๐ฅ"] = { id = "106", tl = "OVIS" }, -- same as *21
["๐"] = { id = "106f", tl = "OVIS<sup>f</sup>" },
["๐"] = { id = "106m", tl = "OVIS<sup>m</sup>" },
["$๐"] = { id = "107", tl = "CAP" }, -- same as *22
["๐"] = { id = "107f", tl = "CAP<sup>f</sup>" },
["๐"] = { id = "107m", tl = "CAP<sup>m</sup>" },
["$๐"] = { id = "108", tl = "SUS" }, -- same as *85
["๐"] = { id = "108f", tl = "SUS<sup>f</sup>" },
["๐"] = { id = "108m", tl = "SUS<sup>m</sup>" },
["$๐"] = { id = "109", tl = "BOS" }, -- same as *23
["๐"] = { id = "109f", tl = "BOS<sup>f</sup>" },
["๐"] = { id = "109m", tl = "BOS<sup>m</sup>" },
["๐ฟ"] = { id = "110", tl = "Z" },
["๐พ"] = { id = "111", tl = "V" },
["๐ผ"] = { id = "112", tl = "T" },
["๐ฝ"] = { id = "113", tl = "S" },
["๐ป"] = { id = "114", tl = "Q" },
["๐บ"] = { id = "115", tl = "P" },
["๐น"] = { id = "116", tl = "N" },
["๐ธ"] = { id = "117", tl = "M" },
["๐ท"] = { id = "118", tl = "L" },
["๐"] = { id = "120", tl = "GRA" },
["๐"] = { id = "121", tl = "HORD" },
["๐"] = { id = "122", tl = "OLIV" },
["๐"] = { id = "123", tl = "AROM" },
-- *124 is a flipped variant of *125, traditionally transliterated as PYC
["๐"] = { id = "125", tl = "CYP" },
-- *126
["๐"] = { id = "127", tl = "kapo" },
["๐"] = { id = "128", tl = "kanako" },
["$๐"] = { id = "129", tl = "FAR" }, -- same as *65
["๐"] = { id = "130", tl = "OLE" },
["๐"] = { id = "131", tl = "WINE" },
["๐"] = { id = "132" },
["๐"] = { id = "133", tl = "arepa" },
-- *134
["๐"] = { id = "135", tl = "meri", },
["๐"] = { id = "140", tl = "AES" },
["๐"] = { id = "141", tl = "AUR" },
["๐"] = { id = "142" },
-- *143
["๐"] = { id = "144", tl = "CROC" },
["๐"] = { id = "145", tl = "LANA" },
["๐"] = { id = "146" },
-- *147, *148, *149
["๐"] = { id = "150" },
["๐ "] = { id = "151", tl = "CORN" },
["๐ก"] = { id = "152" },
["๐ข"] = { id = "153" },
["๐ฃ"] = { id = "154" },
["๐"] = { id = "155", vas = true },
["๐ค"] = { id = "156", tl = "turo2" },
["๐ฅ"] = { id = "157" },
["๐ฆ"] = { id = "158" },
["๐ง"] = { id = "159", tl = "TELA" },
["๐จ"] = { id = "160" },
["๐ฉ"] = { id = "161" },
["๐ช"] = { id = "162", tl = "TUN" },
["๐ซ"] = { id = "163", tl = "ARM" },
["๐ฌ"] = { id = "164" },
["๐ญ"] = { id = "165" },
["๐ฎ"] = { id = "166" },
["๐ฏ"] = { id = "167" },
["๐ฐ"] = { id = "168" },
["๐ฑ"] = { id = "169" },
["๐ฒ"] = { id = "170" },
["๐ณ"] = { id = "171" },
["๐ด"] = { id = "172" },
["๐ต"] = { id = "173", tl = "LUNA" },
["๐ถ"] = { id = "174" },
-- *175
["๐ท"] = { id = "176", tl = "ARB" },
["๐ธ"] = { id = "177" },
["๐น"] = { id = "178" },
["๐บ"] = { id = "179" },
["๐ป"] = { id = "180" },
["๐ผ"] = { id = "181" },
["๐ฝ"] = { id = "182" },
["๐พ"] = { id = "183" },
["๐ฟ"] = { id = "184" },
["๐"] = { id = "185" },
-- *186, *187, *188
["๐"] = { id = "189" },
["๐"] = { id = "190" },
["๐"] = { id = "191", tl = "GAL" },
["๐"] = { id = "200", vas = true },
["๐ "] = { id = "201", vas = true },
["๐ก"] = { id = "202", vas = true },
["๐ข"] = { id = "203", vas = true },
["๐ฃ"] = { id = "204", vas = true },
["๐ค"] = { id = "205", vas = true },
["๐ฅ"] = { id = "206", vas = true },
["๐ฆ"] = { id = "207", vas = true },
["๐ง"] = { id = "208", vas = true },
["๐จ"] = { id = "209", tl = "AMPH", vas = true },
["๐ฉ"] = { id = "210", vas = true },
["๐ช"] = { id = "211", vas = true },
["๐ซ"] = { id = "212", vas = true },
["๐ฌ"] = { id = "213", vas = true },
["๐ญ"] = { id = "214", vas = true },
["๐ฎ"] = { id = "215", vas = true },
["๐ฏ"] = { id = "216", vas = true },
["๐ฐ"] = { id = "217", vas = true },
["๐ฑ"] = { id = "218", vas = true },
["๐ฒ"] = { id = "219", vas = true },
["๐"] = { id = "220" },
["๐ณ"] = { id = "221", vas = true },
["๐ด"] = { id = "222", vas = true },
["๐
"] = { id = "225", tl = "ALV" },
["๐ต"] = { id = "226", vas = true },
["๐ถ"] = { id = "227", vas = true },
["๐ท"] = { id = "228", vas = true },
["๐ธ"] = { id = "229", vas = true },
["๐"] = { id = "230", tl = "HAS" },
["๐"] = { id = "231", tl = "SAG" },
["๐"] = { id = "232" },
["๐"] = { id = "233", tl = "PUG" },
["๐"] = { id = "234" },
-- *235
["๐"] = { id = "236", tl = "GUP" },
-- *237, *238, *239
["๐"] = { id = "240", tl = "BIG" },
["๐"] = { id = "241", tl = "CUR" },
["๐"] = { id = "242", tl = "CAPS" },
["๐"] = { id = "243", tl = "ROTA" },
-- *244, variant of *243 ?
["๐"] = { id = "245" },
["๐"] = { id = "246" },
["๐"] = { id = "247", tl = "dipte" },
["๐"] = { id = "248" },
["๐"] = { id = "249" },
["๐น"] = { id = "250", vas = true },
["๐"] = { id = "251" },
["๐"] = { id = "252" },
["๐"] = { id = "253" },
["๐"] = { id = "254", tl = "JAC" },
["๐"] = { id = "255" },
["๐"] = { id = "256" },
["๐"] = { id = "257" },
["๐"] = { id = "258" },
["๐"] = { id = "259" },
["๐บ"] = { id = "305", vas = true },
}
function export.tr(text, lang, sc)
-- See below at <export.makeDisplayText> for explanations.
text = gsub(gsub(text, u(0x200D), "+"), u(0x200C), "$")
-- Space between ideograms, syllabograms, and digits, or throw an error if there is apparently a missing space.
-- TODO: Have a thorough check whether certain spaceless combination are really impossible, and adjust the error throwing if not.
local space_between = { "[๐-๐บ๐ท-๐ฟ]", "%$[๐ฅ๐๐๐๐]", "[๐-๐]", "[๐-๐ณ]" }
for i_a, v_a in ipairs(space_between) do
for i_b, v_b in ipairs(space_between) do
if i_a ~= i_b or i_a < 3 or i_b < 3 then -- prevents spaces between syllabograms and digits
text = gsub(text, "("..v_a..")("..v_b..")", function(a, b)
if i_b < 4 then -- if the second char is not a digit, there's a missing space.
error("There seems to be a missing space.")
end
return a.." "..b
end)
end
end
end
-- Put a hyphen between syllabograms.
for i = 1, 2 do
text = gsub(text, "([๐-๐])([๐-๐])", "%1-%2")
end
-- Numerals.
text = gsub(text, "[๐-๐ณ]+", function(str)
local ret, count = gsub(str, "^([๐ซ-๐ณ]?)([๐ข-๐ช]?)([๐-๐ก]?)([๐-๐]?)([๐-๐]?)$", function (u5, u4, u3, u2, u1)
return dig_chars[u5] + dig_chars[u4] + dig_chars[u3] + dig_chars[u2] + dig_chars[u1]
end)
if count ~= 1 then
error("The number " .. str .. " is weird. Are you sure?")
end
return ret
end)
-- Syllabograms and ideograms.
text = gsub(text, "%$?[๐-๐บ๐ท-๐ฟ]", function(x_text)
x = chars[x_text]
if x == nil then error("The symbol " .. x_text .. " is not recognised.") end
return x.tl or ("*"..x.id..(x.vas and "<sup>VAS</sup>" or ""))
end)
-- The end.
return text
end
function export.makeDisplayText(text, lang, sc)
-- This is a rather awful bodge, made because there currently seems to be no way of hiding certain characters from the text while keeping them in the transliteration.
-- TODO: One should probably update MOD:languages to allow post-translit display-text replacements.
return (gsub(gsub(text, "%+", u(0x200D)), "%$", u(0x200C)))
end
function export.makeEntryName(text, lang, sc)
return (gsub(text, "[+$]", ""))
end
return export