มอดูล:Talu-translit

จาก วิกิพจนานุกรม พจนานุกรมเสรี
ไปยังการนำทาง ไปยังการค้นหา

มอดูลนี้ใช้ถอดอักษรข้อความในอักษรไทลื้อใหม่.

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 มอดูล:Talu-translit/testcases.

ฟังก์ชัน[แก้ไข]

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

local export = {}
local gsub = mw.ustring.gsub

local tt = {
	-- consonants
	["ᦀ"] = "อ", ["ᦁ"] = "อ̱",
	["ᦂ"] = "ก", ["ᦃ"] = "ฃ", ["ᦄ"] = "หฺง", ["ᦅ"] = "ค", ["ᦆ"] = "ฅ", ["ᦇ"] = "ง",
	["ᦈ"] = "จ", ["ᦉ"] = "ส", ["ᦊ"] = "หฺย", ["ᦋ"] = "ช", ["ᦌ"] = "ซ", ["ᦍ"] = "ย",
	["ᦎ"] = "ต", ["ᦏ"] = "ถ", ["ᦐ"] = "หฺน", ["ᦑ"] = "ท", ["ᦒ"] = "ธ", ["ᦓ"] = "น",
	["ᦔ"] = "ป", ["ᦕ"] = "ผ", ["ᦖ"] = "หฺม", ["ᦗ"] = "พ", ["ᦘ"] = "ภ", ["ᦙ"] = "ม",
	["ᦚ"] = "ฝ", ["ᦛ"] = "หฺว", ["ᦜ"] = "หฺล", ["ᦝ"] = "ฟ", ["ᦞ"] = "ว", ["ᦟ"] = "ล",
	["ᦠ"] = "ห", ["ᦡ"] = "ด", ["ᦢ"] = "บ", ["ᦣ"] = "ฮ", ["ᦤ"] = "ด̱", ["ᦥ"] = "บ̱",
	["ᦦ"] = "กฺว", ["ᦧ"] = "ฃฺว", ["ᦨ"] = "คฺว", ["ᦩ"] = "ฅฺว", ["ᦪ"] = "สฺว", ["ᦫ"] = "ซฺว",
	-- vowels and finals (visual ordering by Unicode 8)
	["ᦰ"] = "ะ", ["ᦱ"] = "า", ["ᦲ"] = "ี", ["ᦳ"] = "ุ", ["ᦴ"] = "ู",
	["ᦵ"] = "เ", ["ᦶ"] = "แ", ["ᦷ"] = "โ", ["ᦸ"] = "อ̂", ["ᦹ"] = "ื", ["ᦺ"] = "ไ",
	["ᦻ"] = "าย์", ["ᦼ"] = "ูย์", ["ᦽ"] = "↶โย์", ["ᦾ"] = "อ̂ย์", ["ᦿ"] = "ืย์", ["ᧀ"] = "ีย์", -- killer will be removed later
	["ᧁ"] = "ว์", ["ᧂ"] = "ง์", ["ᧃ"] = "น์", ["ᧄ"] = "ม์", ["ᧅ"] = "ก์", ["ᧆ"] = "ด์", ["ᧇ"] = "บ์", -- killer will be removed later
	-- tones
	["ᧈ"] = "¹", ["ᧉ"] = "²",
	-- numerals
	["᧐"] = "0", ["᧑"] = "1", ["᧒"] = "2", ["᧓"] = "3", ["᧔"] = "4",
	["᧕"] = "5", ["᧖"] = "6", ["᧗"] = "7", ["᧘"] = "8", ["᧙"] = "9",
	["᧚"] = "1",
	-- ligatures ᧞ ᧟ ถูกจัดลำดับอยู่หลัง ᦶᦜ
	["᧞"] = "แหฺล", ["᧟"] = "แหฺลว์", -- killer will be removed later
}

function export.tr(text, lang, sc, debug_mode)

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

	text = gsub(text, "([ᦀ-ᦫ])([ᧁ-ᧇ])", "%1ั%2")
	text = gsub(text, "([ᦵᦶᦷᦺ])(.)ั", "%1%2")

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

	text = gsub(text, "(.)ัว์", "เ%1า")
	text = gsub(text, "หฺ(.)↶โ", "โหฺ%1")
	text = gsub(text, "(.)↶โ", "โ%1")

	text = gsub(text, "([กงดนบมยว])์([¹²])", "%2%1") -- also remove killer
	text = gsub(text, "([กงดนบมยว])์", "%1") -- remove killer
	text = gsub(text, "([ะา])¹", "่%1") -- ek
	text = gsub(text, "([ะา])²", "้%1") -- tho
	text = gsub(text, "(อ̂)¹", "่%1") -- ek
	text = gsub(text, "(อ̂)²", "้%1") -- tho
	text = gsub(text, "¹", "่") -- ek
	text = gsub(text, "²", "้") -- tho

	return text

end

return export