Pergi ke kandungan

Modul:yi-translit

Daripada Wikikamus

Modul ini akan mentransliterasi Bahasa Yiddish teks. 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:yi-translit/testcases.

Functions

[sunting]
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 = {
	["א"] = "q",
	["אָ"] = "o",
	["אַ"] = "a",
	["בּ"] = "b",
	["ב"] = "b",
	["בֿ"] = "v",
	["גּ"] = "g",
	["ג"] = "g",
	["גֿ"] = "g",
	["דּ"] = "d",
	["ד"] = "d",
	["דֿ"] = "d",
	["ה"] = "h",
	["ו"] = "w",
	["וּ"] = "u",
	["וו"] = "v",
	["װ"] = "v",
	["וי"] = "oy",
	["ױ"] = "oy",
	["ז"] = "z",
	["ח"] = "kh",
	["ט"] = "t",
	["י"] = "y",
	["יִ"] = "i",
	["יִ"] = "i",
	["יי"] = "ey",
	["ײ"] = "ey",
	["ייַ"] = "ay",
	["ײַ"] = "ay",
	["ײַ"] = "ay",
	["כּ"] = "k",
	["כ"] = "kh",
	["כֿ"] = "kh",
	["ךּ"] = "k",
	["ך"] = "kh",
	["ךֿ"] = "kh",
	["ל"] = "l",
	["מ"] = "m",
	["ם"] = "m",
	["נ"] = "n",
	["ן"] = "n",
	["ס"] = "s",
	["ע"] = "e",
	["פּ"] = "p",
	["פ"] = "f",
	["פֿ"] = "f",
	["ףּ"] = "p",
	["ף"] = "f",
	["ףֿ"] = "f",
	["צ"] = "ts",
	["ץ"] = "ts",
	["ק"] = "k",
	["ר"] = "r",
	["שׁ"] = "sh",
	["ש"] = "sh",
	["שׂ"] = "s",
	["תּ"] = "t",
	["ת"] = "s",
	["תֿ"] = "s",
	["־"] = "-",
	["׳"] = "'",
	["״"] = "\"",
}

-- in precedence order
local tokens = {
	"ייַ",
	"אָ",
	"אַ",
	"בּ",
	"בֿ",
	"גּ",
	"גֿ",
	"דּ",
	"דֿ",
	"וּ",
	"וו",
	"וי",
	"יִ",
	"יִ",
	"יי",
	"ײַ",
	"כּ",
	"כֿ",
	"ךּ",
	"ךֿ",
	"פּ",
	"פֿ",
	"ףּ",
	"ףֿ",
	"שׁ",
	"שׂ",
	"תּ",
	"תֿ",
	"א",
	"ב",
	"ג",
	"ד",
	"ה",
	"ו",
	"ױ",
	"װ",
	"ז",
	"ח",
	"ט",
	"י",
	"ײ",
	"ײַ",
	"כ",
	"ך",
	"ל",
	"מ",
	"ם",
	"נ",
	"ן",
	"ס",
	"ע",
	"פ",
	"ף",
	"צ",
	"ץ",
	"ק",
	"ר",
	"ש",
	"ת",
	"־",
	"׳",
	"״",
}

function export.tr(text, lang, sc)
	for _, token in ipairs(tokens) do
		text = string.gsub(text, token, tt[token])
	end
	
	text = string.gsub(text, "([bcdfghjklmnpqrstvwxz])y$", "%1i")
	text = string.gsub(text, "([bcdfghjklmnpqrstvwxz])y([^aeiouwy])", "%1i%2")
	text = string.gsub(text, "([bcdfghjklmnpqrstvwxz])y([^aeiouwy])", "%1i%2") -- repeated to handle overlapping cases
	text = string.gsub(text, "([bcdfghjklmnpqrstvxyz])w$", "%1u")
	text = string.gsub(text, "([bcdfghjklmnpqrstvxyz])w([^aeiouwy])", "%1u%2")
	text = string.gsub(text, "([bcdfghjklmnpqrstvxyz])w([^aeiouwy])", "%1u%2") -- repeated to handle overlapping cases
	text = string.gsub(text, "w", "v")
	text = string.gsub(text, "zsh", "zh")
	text = string.gsub(text, "q", "")
	
    return text
end

return export