Jump to content

Module:lep-translit

From Wiktionary, the free dictionary

This module will transliterate Lepcha 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:lep-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 conv = {
	[""] = "",
	["ᰀ"] = "k",	--U+1C00, \225\176\128
	["ᰁ"] = "kl",	--U+1C01, \225\176\129
	["ᰂ"] = "kh",	--U+1C02, \225\176\130
	["ᰃ"] = "g",	--U+1C03, \225\176\131
	["ᰄ"] = "gl",	--U+1C04, \225\176\132
	["ᰅ"] = "ng",	--U+1C05, \225\176\133
	["ᰆ"] = "c",	--U+1C06, \225\176\134
	["ᰇ"] = "ch",	--U+1C07, \225\176\135
	["ᰈ"] = "j",	--U+1C08, \225\176\136
	["ᰉ"] = "ny",	--U+1C09, \225\176\137
	["ᰊ"] = "t",	--U+1C0A, \225\176\138
	["ᰋ"] = "th",	--U+1C0B, \225\176\139
	["ᰌ"] = "d",	--U+1C0C, \225\176\140
	["ᰍ"] = "n",	--U+1C0D, \225\176\141
	["ᰎ"] = "p",	--U+1C0E, \225\176\142
	["ᰏ"] = "pl",	--U+1C0F, \225\176\143
	["ᰐ"] = "ph",	--U+1C10, \225\176\144
	["ᰑ"] = "f",	--U+1C11, \225\176\145
	["ᰒ"] = "fl",	--U+1C12, \225\176\146
	["ᰓ"] = "b",	--U+1C13, \225\176\147
	["ᰔ"] = "bl",	--U+1C14, \225\176\148
	["ᰕ"] = "m",	--U+1C15, \225\176\149
	["ᰖ"] = "ml",	--U+1C16, \225\176\150
	["ᰗ"] = "ts",	--U+1C17, \225\176\151
	["ᰘ"] = "tsh",	--U+1C18, \225\176\152
	["ᰙ"] = "dz",	--U+1C19, \225\176\153
	["ᰚ"] = "y",	--U+1C1A, \225\176\154
	["ᰛ"] = "r",	--U+1C1B, \225\176\155
	["ᰜ"] = "l",	--U+1C1C, \225\176\156
	["ᰝ"] = "h",	--U+1C1D, \225\176\157
	["ᰞ"] = "hl",	--U+1C1E, \225\176\158
	["ᰟ"] = "v",	--U+1C1F, \225\176\159
	["ᰠ"] = "s",	--U+1C20, \225\176\160
	["ᰡ"] = "sh",	--U+1C21, \225\176\161
	["ᰢ"] = "w",	--U+1C22, \225\176\162
	["ᰣ"] = "ʔ",	--U+1C23, \225\176\163
	["ᰤ"] = "y",	--U+1C24, \225\176\164
	["ᰥ"] = "r",	--U+1C25, \225\176\165
	["ᰥᰤ"] = "ry",
	["ᰀ᰷"] = "t",
	["ᰝ᰷"] = "th",
	["ᰃ᰷"] = "d",
	["ᰦ"] = "á",	--U+1C26, \225\176\166
	["ᰧ"] = "i",	--U+1C27, \225\176\167
	["ᰨ"] = "o",	--U+1C28, \225\176\168
	["ᰩ"] = "ó",	--U+1C29, \225\176\169
	["ᰪ"] = "u",	--U+1C2A, \225\176\170
	["ᰫ"] = "ú",	--U+1C2B, \225\176\171
	["ᰬ"] = "e",	--U+1C2C, \225\176\172
	["ᰭ"] = "k",	--U+1C2D, \225\176\173
	["ᰮ"] = "m",	--U+1C2E, \225\176\174
	["ᰯ"] = "l",	--U+1C2F, \225\176\175
	["ᰰ"] = "n",	--U+1C30, \225\176\176
	["ᰱ"] = "p",	--U+1C31, \225\176\177
	["ᰲ"] = "r",	--U+1C32, \225\176\178
	["ᰳ"] = "t",	--U+1C33, \225\176\179
	["ᰴ"] = "ng",	--U+1C34, \225\176\180
	["ᰵ"] = "ng",	--U+1C35, \225\176\181
	["ᰧᰶ"] = "í",	--U+1C27 U+1C36, \225\176\167 \225\176\182
	["ᰶ"] = "â",	--U+1C36, \225\176\182
	["᰷"] = "",		--U+1C37, \225\176\183
	["᰻"] = ".",	--U+1C3B, \225\176\187
	["᰼"] = ".",	--U+1C3C, \225\176\188
	["᰽"] = ".",	--U+1C3D, \225\176\189
	["᰾"] = ".",	--U+1C3E, \225\176\190
	["᰿"] = ".",	--U+1C3F, \225\176\191
	["᱀"] = "0",	--U+1C40, \225\177\128
	["᱁"] = "1",	--U+1C41, \225\177\129
	["᱂"] = "2",	--U+1C42, \225\177\130
	["᱃"] = "3",	--U+1C43, \225\177\131
	["᱄"] = "4",	--U+1C44, \225\177\132
	["᱅"] = "5",	--U+1C45, \225\177\133
	["᱆"] = "6",	--U+1C46, \225\177\134
	["᱇"] = "7",	--U+1C47, \225\177\135
	["᱈"] = "8",	--U+1C48, \225\177\136
	["᱉"] = "9",	--U+1C49, \225\177\137
	["ᱍ"] = "tt",	--U+1C4D, \225\177\141
	["ᱎ"] = "tth",	--U+1C4E, \225\177\142
	["ᱏ"] = "dd",	--U+1C4F, \225\177\143
}

local function add_inherent_vowel(c)
	return c == "" and "a" or c
end

local initials = "([ᰀ-ᰣᱍ-ᱏ])"
local nukta = "(᰷?)"
local medials = "([ᰤᰥ]?[ᰤ]?)"
local vowels = "([ᰦ-ᰬ]?)"
local finals = "([ᰭ-ᰵ]?)"
local ran = "(ᰶ?)" -- the ran diacritic goes after final

local syllable = initials .. nukta .. medials .. vowels .. finals .. ran

local function romanise_syllable(i, n, m, v, f, r)
	return conv[i .. n] .. conv[m] .. add_inherent_vowel(conv[v .. r]) .. conv[f]
end

-- Take Lepcha-script `text` and output a table of tables (for each word) of
-- romanised syllables.
function export.syllabify(text)
	local ret = {}
	
	for word in mw.text.gsplit(text, " ") do
		local syllables = {}
		
		for i, n, m, v, f, r in mw.ustring.gmatch(word, syllable) do
			table.insert(syllables, romanise_syllable(i, n, m, v, f, r))
		end
		
		table.insert(ret, syllables)
	end
	
	return ret
end

function export.tr(text, lang, sc)
	text = mw.ustring.gsub(text, "[᰻-᱉]", conv)
	text = mw.ustring.gsub(text, syllable, romanise_syllable)
	return text
end

return export