Bước tới nội dung

Mô đun:aio-phk-translit

Từ điển mở Wiktionary

Mô đun này có chức năng chuyển tự văn bản Tiếng Aiton. Nó cũng được sử dụng để phiên âm tiếng Aiton and tiếng Phake. Lưu ý, không nên gọi mô đun này trực tiếp trong các bản mẫu hoặc mô đun khác. Để sử dụng trong một bản mẫu, dùng {{xlit}}. Còn trong một mô đun, dùng Mô đun:languages#Language:transliterate.

Đối với trường hợp kiểm thử, xem Module:aio-phk-translit/testcases.

Chức năng

[sửa]
tr(text, lang, sc)
Chuyển tự một text (văn bản) được đưa ra và viết bằng chữ viết được xác định bởi mã sc, và ngôn ngữ được xác định bởi mã lang.
Nếu chuyển tự thất bại, nó sẽ gọi giá trị nil.
local export = {}
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local con_cls = "([ကၵငꩡꩬၺတထꩫဒပၸမဗယꩺလဝꩭဢ])"
local med_cls = "([ျြၞ]?)"

local tt1 = {
	-- consonants
	["က"] = "k", ["ၵ"] = "kh", ["င"] = "ṅ",
	["ꩡ"] = "c", ["ꩬ"] = "s", ["ၺ"] = "ñ",
	["တ"] = "t", ["ထ"] = "th", ["ꩫ"] = "n", ["ဒ"] = "d",
	["ပ"] = "p", ["ၸ"] = "ph", ["မ"] = "m", ["ဗ"] = "b",
	["ယ"] = "y", ["ꩺ"] = "r", ["လ"] = "l", ["ဝ"] = "w",
	["ꩭ"] = "h", ["ဢ"] = "ʼ",
	-- medials
	["ျ"] = "y", ["ြ"] = "r", ["ၞ"] = "w",
	-- dependent vowels and diacritics (excluding front type)
	["္"] = "", ["ႜ"] = "a", ["ႃ"] = "ā", ["ိ"] = "i", ["ီ"] = "ī",
	["ု"] = "u", ["ူ"] = "ū", ["ွ"] = "o", ["်"] = "", ["ႝ"] = "y",
	["ေ"] = "e", ["ံ"] = "ṃ",
	-- punctuation marks
	["၊"] = ",", ["။"] = ".", ["꩷"] = "!",
	-- numerals
	["꩸"] = "1", ["꩹"] = "2",
	["၀"] = "0", ["၁"] = "1", ["၂"] = "2", ["၃"] = "3", ["၄"] = "4",
	["၅"] = "5", ["၆"] = "6", ["၇"] = "7", ["၈"] = "8", ["၉"] = "9",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼",
}

function export.tr(text, lang, sc)

	if type(text) == "table" then -- called directly from a template
		text = text.args[1]
	end

	text = gsub(text, u(0xFE00), "") -- remove VS01

	text = gsub(text, "ေ".."ႃ", "ō")
	text = gsub(text, "ိ".."ု", "ü")
	text = gsub(text, "ွ".."်", "aw")
	text = gsub(text, "ၞ".."်", "aü")

	text = gsub(text, con_cls .. med_cls .. con_cls .. "်", "%1%2a%3")
	text = gsub(text, con_cls .. med_cls .. "([ႝံ])", "%1%2a%3")

	text = gsub(text, ".", tt1)

	return text
 
end
 
return export