This module will transliterate text in the Canadian syllabic script.
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:Cans-translit/testcases.
tr(text, lang, sc)
text
written in the script specified by the code sc
, and language specified by the code lang
.nil
.{
= {
= {
= "ᑊ",
= "p",
},
= {
= "ᐟ",
= "t",
},
= {
= "ᐠ",
= "k",
},
= {
= "ᐨ",
= "c",
},
= {
= "ᒼ",
= "m",
},
= {
= "ᐣ",
= "n",
},
= {
= "ᐢ",
= "s",
},
= {
= "ᐧ",
= "y",
},
= {
= "ᐤ",
= "w",
},
= {
= "ᐦ",
= "h",
},
= {
= "ᕁ",
= "hk",
},
= {
= "ᕽ",
= "hk",
},
= {
= "ᓫ",
= "l",
},
= {
= "ᕑ",
= "r",
},
= {
= "ᑉ",
= "p",
},
= {
= "ᑦ",
= "t",
},
= {
= "ᒡ",
= "c",
},
= {
= "ᒃ",
= "k",
},
= {
= "ᒻ",
= "m",
},
= {
= "ᓐ",
= "n",
},
= {
= "ᔅ",
= "s",
},
= {
= "ᔥ",
= "š",
},
= {
= "ᔾ",
= "y",
},
= {
= "ᓪ",
= "l",
},
= {
= "ᕐ",
= "r",
},
= {
= "ᕪ",
= "ð",
},
= {
= "‡",
= "ð",
},
= {
= "ᒄ",
= "kw",
},
= {
= "ᔉ",
= "sk",
},
= {
= "ᖅ",
= "q",
},
= {
= "ᖕ",
= "ng",
},
= {
= "ᖖ",
= "nng",
},
= {
= "ᕝ",
= "v",
},
= {
= "ᖦ",
= "l",
},
= {
= "ᕀ",
= "y",
},
= {
= "ᕻ",
= "h",
},
= {
= "ᕼ",
= "h",
},
},
}
local export = {}
-- to be discussed: not to create this module, but create individual modules instead?
local UTF8_char = "*"
local function iter_char(str)
return string.gmatch(str, UTF8_char)
end
local function len(str)
local _, length = string.gsub(str, UTF8_char, "")
return length
end
local function fetch(str, index)
local i = 0
for char in iter_char(str) do
i = i + 1
if i == index then
return char
end
end
return ""
end
function export.tr(text, lang, sc)
local data = {
{ --short-vowel
"ᐁᐃᐅᐊᐯᐱᐳᐸᑌᑎᑐᑕᑫᑭᑯᑲᒉᒋᒍᒐᒣᒥᒧᒪᓀᓂᓄᓇᓭᓯᓱᓴᔦᔨᔪᔭᖊᖋᖌᖍᕃᕆᕈᕍᕂᕄᕊᕋᔐᔑᔓᔕᕓᕕᕗᕙᕞᕠᕤᕦᘚᘛᘕᘔᓓᓕᓗᓚᙯᕿᖁᖃᙰᖏᖑᖓ ᙱᙳᙵᕴᕵᕷᕹ",
"1ptkcmnsyrrršfðzlq23h",
{"","ng","nng"},
"eioa",
function(a,b)
return a..b
end
},
{ --w
"ᐌᐍᐎᐏᐒᐓᐗᐘᐺᐻᐼᐽᑀᑁᑄᑅᑗᑘᑙᑚᑝᑞᑡᑢᑴᑵᑶᑷᑺᑻᑾᑿᒒᒓᒔᒕᒘᒙᒜᒝᒬᒭᒮᒯᒲᒳᒶᒷ"
.. "ᓉᓊ ᓋᓌ ᓶᓷᓸᓹᓼᓽᔀᔁᔯᔰᔱᔲᔵᔶᔹᔺᔗᔘᔙᔚᔝᔞᔡᔢᓜᓝᓞᓟᓢᓣᓦᓧ",
"1ptkcmnsyrz",
{""},
"eeiiooaa",
function(a,b)
return a..'w'..b
end
},
{ --long-vowel
"ᐄᐆᐋᐲᐴᐹᑏᑑᑖᑮᑰᑳᒌᒎᒑᒦᒨᒫᓃᓅᓈᓰᓲᓵᔩᔫᔮᕇᕉᕌᔒᔔᔖᕖᕘᕚᕢᕥᕧᓖᓘᓛᐐᐔᐙᖀᖂᖄᕶᕸᕺ",
"1ptkcmnsyršfðlwqh",
{""},
"īōā",
function(a,b)
return a..b
end
},
{ --w-long
"ᐐᐑᐔᐕᐖᐙᐚᐛᐾᐿᑂᑃ ᑆᑇᑈᑛᑜᑟᑠ ᑣᑤᑥᑸᑹᑼᑽ ᒀᒁᒂᒖᒗᒚᒛ ᒞᒟᒠᒰᒱᒴᒵ ᒸᒹᒺ ᓍᓎᓏ"
.. "ᓠᓡᓤᓥ ᓨᓩ ᓺᓻᓾᓿ ᔂᔃᔄᔛᔜᔟᔠ ᔣᔤ ᔳᔴᔷᔸ ᔻᔼᔽ ᕎᕏ ᕛᕜ ᕨᕩ ",
"1ptkcmnlsšyrfð",
{""},
"īīōōōāāā",
function(a,b)
return a..'w'..b
end
},
{ --individual
"ᑊᐟᐠᐨᒼᐣᐢᐧᐤᐦᕁᕽᓫᕑᑉᑦᒡᒃᒻᓐᔅᔥᔾᓪᕐᕪ‡ᒄᔉᖅᖕᖖᕝᖦᕀᕻᕼ",
"ptkcmnsywh11lrptckmnsšylrðð23q45vlyhh",
{"hk","kw","sk","ng","nng"},
},
}
for i, item in pairs(data) do
if item then
local length = len(item)
local c = 0
for s in iter_char(item) do
c = c + 1
local index = math.ceil(c / length)
local a = fetch(item, index)
if tonumber(a) then
a = item
end
index = (c - 1) % length + 1
local b = fetch(item, index)
if s ~= " " then
text = string.gsub(text, s, item(a,b))
end
end
else
local iter1, iter2 = iter_char(item), iter_char(item)
while true do
local s, a = iter1(), iter2()
if not (s and a) then
break
end
if tonumber(a) then
a = item
end
text = string.gsub(text, s, a)
end
end
end
return text
end
return export