Module:mak-Latn-Bugi-translit

From Linguifex
Jump to navigation Jump to search

This module will transliterate Makasar language text. The module should preferably not be called directly from templates or other modules. To use it from a template, use {{xlit}}. Within a module, use Module:languages#Language:transliterate.

For testcases, see Module:mak-Latn-Bugi-translit/testcases.

Functions

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When the transliteration fails, returns nil.

local export = {}

local tt = {}

tt["Latn"] = {
	["ka"]="ᨀ", ["ki"]="ᨀᨗ", ["ku"]="ᨀᨘ", ["ke"]="ᨀᨙ", ["ko"]="ᨀᨚ",
	["ga"]="ᨁ", ["gi"]="ᨁᨗ", ["gu"]="ᨁᨘ", ["ge"]="ᨁᨙ", ["go"]="ᨁᨚ",
	["pa"]="ᨄ", ["pi"]="ᨄᨗ", ["pu"]="ᨄᨘ", ["pe"]="ᨄᨙ", ["po"]="ᨄᨚ",
	["ba"]="ᨅ", ["bi"]="ᨅᨗ", ["bu"]="ᨅᨘ", ["be"]="ᨅᨙ", ["bo"]="ᨅᨚ",
	["ma"]="ᨆ", ["mi"]="ᨆᨗ", ["mu"]="ᨆᨘ", ["me"]="ᨆᨙ", ["mo"]="ᨆᨚ",
	["ta"]="ᨈ", ["ti"]="ᨈᨗ", ["tu"]="ᨈᨘ", ["te"]="ᨈᨙ", ["to"]="ᨈᨚ",
	["da"]="ᨉ", ["di"]="ᨉᨗ", ["du"]="ᨉᨘ", ["de"]="ᨉᨙ", ["do"]="ᨉᨚ",
	["na"]="ᨊ", ["ni"]="ᨊᨗ", ["nu"]="ᨊᨘ", ["ne"]="ᨊᨙ", ["no"]="ᨊᨚ",
	["ca"]="ᨌ", ["ci"]="ᨌᨗ", ["cu"]="ᨌᨘ", ["ce"]="ᨌᨙ", ["co"]="ᨌᨚ",
	["ja"]="ᨍ", ["ji"]="ᨍᨗ", ["ju"]="ᨍᨘ", ["je"]="ᨍᨙ", ["jo"]="ᨍᨚ",
	["ya"]="ᨐ", ["yi"]="ᨐᨗ", ["yu"]="ᨐᨘ", ["ye"]="ᨐᨙ", ["yo"]="ᨐᨚ",
	["ra"]="ᨑ", ["ri"]="ᨑᨗ", ["ru"]="ᨑᨘ", ["re"]="ᨑᨙ", ["ro"]="ᨑᨚ",
	["la"]="ᨒ", ["li"]="ᨒᨗ", ["lu"]="ᨒᨘ", ["le"]="ᨒᨙ", ["lo"]="ᨒᨚ",
	["wa"]="ᨓ", ["wi"]="ᨓᨗ", ["wu"]="ᨓᨘ", ["we"]="ᨓᨙ", ["wo"]="ᨓᨚ",
	["sa"]="ᨔ", ["si"]="ᨔᨗ", ["su"]="ᨔᨘ", ["se"]="ᨔᨙ", ["so"]="ᨔᨚ",
	["ha"]="ᨖ", ["hi"]="ᨖᨗ", ["hu"]="ᨖᨘ", ["he"]="ᨖᨙ", ["ho"]="ᨖᨚ",
	["a"]="ᨕ", ["i"]="ᨕᨗ", ["u"]="ᨕᨘ", ["e"]="ᨕᨙ", ["o"]="ᨕᨚ",

	["nga"]="ᨂ", ["ngi"]="ᨂᨗ", ["ngu"]="ᨂᨘ", ["nge"]="ᨂᨙ", ["ngo"]="ᨂᨚ",
	["nya"]="ᨎ", ["nyi"]="ᨎᨗ", ["nyu"]="ᨎᨘ", ["nye"]="ᨎᨙ", ["nyo"]="ᨎᨚ",
	
	["kà"]="ᨀ", ["kì"]="ᨀᨗ", ["kù"]="ᨀᨘ", ["kè"]="ᨀᨙ", ["kò"]="ᨀᨚ",
	["gà"]="ᨁ", ["gì"]="ᨁᨗ", ["gù"]="ᨁᨘ", ["gè"]="ᨁᨙ", ["gò"]="ᨁᨚ",
	["pà"]="ᨄ", ["pì"]="ᨄᨗ", ["pù"]="ᨄᨘ", ["pè"]="ᨄᨙ", ["pò"]="ᨄᨚ",
	["bà"]="ᨅ", ["bì"]="ᨅᨗ", ["bù"]="ᨅᨘ", ["bè"]="ᨅᨙ", ["bò"]="ᨅᨚ",
	["mà"]="ᨆ", ["mì"]="ᨆᨗ", ["mù"]="ᨆᨘ", ["mè"]="ᨆᨙ", ["mò"]="ᨆᨚ",
	["tà"]="ᨈ", ["tì"]="ᨈᨗ", ["tù"]="ᨈᨘ", ["tè"]="ᨈᨙ", ["tò"]="ᨈᨚ",
	["dà"]="ᨉ", ["dì"]="ᨉᨗ", ["dù"]="ᨉᨘ", ["dè"]="ᨉᨙ", ["dò"]="ᨉᨚ",
	["nà"]="ᨊ", ["nì"]="ᨊᨗ", ["nù"]="ᨊᨘ", ["nè"]="ᨊᨙ", ["nò"]="ᨊᨚ",
	["cà"]="ᨌ", ["cì"]="ᨌᨗ", ["cù"]="ᨌᨘ", ["cè"]="ᨌᨙ", ["cò"]="ᨌᨚ",
	["jà"]="ᨍ", ["jì"]="ᨍᨗ", ["jù"]="ᨍᨘ", ["jè"]="ᨍᨙ", ["jò"]="ᨍᨚ",
	["yà"]="ᨐ", ["yì"]="ᨐᨗ", ["yù"]="ᨐᨘ", ["yè"]="ᨐᨙ", ["yò"]="ᨐᨚ",
	["rà"]="ᨑ", ["rì"]="ᨑᨗ", ["rù"]="ᨑᨘ", ["rè"]="ᨑᨙ", ["rò"]="ᨑᨚ",
	["là"]="ᨒ", ["lì"]="ᨒᨗ", ["lù"]="ᨒᨘ", ["lè"]="ᨒᨙ", ["lò"]="ᨒᨚ",
	["wà"]="ᨓ", ["wì"]="ᨓᨗ", ["wù"]="ᨓᨘ", ["wè"]="ᨓᨙ", ["wò"]="ᨓᨚ",
	["sà"]="ᨔ", ["sì"]="ᨔᨗ", ["sù"]="ᨔᨘ", ["sè"]="ᨔᨙ", ["sò"]="ᨔᨚ",
	["hà"]="ᨖ", ["hì"]="ᨖᨗ", ["hù"]="ᨖᨘ", ["hè"]="ᨖᨙ", ["hò"]="ᨖᨚ",
	["à"]="ᨕ", ["ì"]="ᨕᨗ", ["ù"]="ᨕᨘ", ["è"]="ᨕᨙ", ["ò"]="ᨕᨚ",

	["ngà"]="ᨂ", ["ngì"]="ᨂᨗ", ["ngù"]="ᨂᨘ", ["ngè"]="ᨂᨙ", ["ngò"]="ᨂᨚ",
	["nyà"]="ᨎ", ["nyì"]="ᨎᨗ", ["nyù"]="ᨎᨘ", ["nyè"]="ᨎᨙ", ["nyò"]="ᨎᨚ",
};

function export.tr(text, lang, sc)
    if (sc == "Latn") then
        -- Lowercase
        text = mw.ustring.lower(text)
        -- Remove glottal stop
        text = mw.ustring.gsub(text, "\'", "")
        text = mw.ustring.gsub(text, "ʼ", "")
        -- Replace character clusters
        text = mw.ustring.gsub(text, "ng[aeiouàèìòù]", tt[sc])
        text = mw.ustring.gsub(text, "ny[aeiouàèìòù]", tt[sc])
        -- Replace the rest of the characters
        text = mw.ustring.gsub(text, "[kgnpbmtdnrcjyclwsh][aeiouàèìòù]", tt[sc])
        -- Replace one-vowel syllables
        text = mw.ustring.gsub(text, "[aeiouàèìòù]", tt[sc])
        -- Remove left-overs
        text = mw.ustring.gsub(text, "[kgnpbmtdnrcjyclwsh-]", "")
    end
    return mw.ustring.toNFC(text)
end

return export