ข้ามไปเนื้อหา

มอดูล:Ethi-translit

จาก วิกิพจนานุกรม พจนานุกรมเสรี

This module will transliterate text in the อักษรเอธิโอเปีย. It is used to transliterate อัมฮารา, Blin, Dahalik, กืออึซ, Harari, Chaha, ทือกรึญญา, and ทือเกร. 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:Ethi-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 tt = {
	["ሀ"]="เฮอ", ["ሁ"]="ฮู", ["ሂ"]="ฮี", ["ሃ"]="ฮา", ["ሄ"]="เฮ", ["ህ"]="ฮ์", ["ሆ"]="โฮ",
	["ለ"]="เลอ", ["ሉ"]="ลู", ["ሊ"]="ลี", ["ላ"]="ลา", ["ሌ"]="เล", ["ል"]="ล์", ["ሎ"]="โล", 
		["ሏ"]="ล๎วา", 
	["ሐ"]="เฮ̱อ", ["ሑ"]="ฮู̱", ["ሒ"]="ฮ̱ี", ["ሓ"]="ฮ̱า", ["ሔ"]="เฮ̱", ["ሕ"]="ฮ์̱", ["ሖ"]="โฮ̱", 
		["ሗ"]="ฮ๎̱วา", 
	["መ"]="เมอ", ["ሙ"]="มู", ["ሚ"]="มี", ["ማ"]="มา", ["ሜ"]="เม", ["ም"]="ม์", ["ሞ"]="โม", 
		["ሟ"]="ม๎วา", ["ፙ"]="เม๎ยอ", 
	["ሠ"]="เช̱อ", ["ሡ"]="ชู̱", ["ሢ"]="ช̱ี", ["ሣ"]="ช̱า", ["ሤ"]="เช̱", ["ሥ"]="ช์̱", ["ሦ"]="โช̱", 
		["ሧ"]="ช๎̱วา", 
	["ረ"]="เรอ", ["ሩ"]="รู", ["ሪ"]="รี", ["ራ"]="รา", ["ሬ"]="เร", ["ር"]="ร์", ["ሮ"]="โร",
		["ሯ"]="ร๎วา", ["ፘ"]="เร๎ยอ", 
	["ሰ"]="เซอ", ["ሱ"]="ซู", ["ሲ"]="ซี", ["ሳ"]="ซา", ["ሴ"]="เซ", ["ስ"]="ซ์", ["ሶ"]="โซ",
		["ሷ"]="ซ๎วา", 
	["ሸ"]="เศอ", ["ሹ"]="ศู", ["ሺ"]="ศี", ["ሻ"]="ศา", ["ሼ"]="เศ", ["ሽ"]="ศ์", ["ሾ"]="โศ",
		["ሿ"]="ศ๎วา", 
	["ቀ"]="เก͇อ", ["ቁ"]="กู̱", ["ቂ"]="ก͇ี", ["ቃ"]="ก͇า", ["ቄ"]="เก͇", ["ቅ"]="ก์͇", ["ቆ"]="โก͇",
		["ቈ"]="เก๎̱วอ", ["ቊ"]="ก๎̱วี", ["ቋ"]="ก๎̱วา", ["ቌ"]="เก๎̱ว", ["ቍ"]="ก๎̱ว์", 
	["ቐ"]="เคอ", ["ቑ"]="คู", ["ቒ"]="คี", ["ቓ"]="คา", ["ቔ"]="เค", ["ቕ"]="ค์", ["ቖ"]="โค",
		["ቘ"]="เค๎วอ", ["ቚ"]="ค๎วี", ["ቛ"]="ค๎วา", ["ቜ"]="เค๎ว", ["ቝ"]="ค๎ว์",
	["በ"]="เบอ", ["ቡ"]="บู", ["ቢ"]="บี", ["ባ"]="บา", ["ቤ"]="เบ", ["ብ"]="บ์", ["ቦ"]="โบ", 
		["ቧ"]="บ๎วา", 
	["ቨ"]="เฝอ", ["ቩ"]="ฝู", ["ቪ"]="ฝี", ["ቫ"]="ฝา", ["ቬ"]="เฝ", ["ቭ"]="ฝ์", ["ቮ"]="โฝ", 
		["ቯ"]="ฝ๎วา", 
	["ተ"]="เตอ", ["ቱ"]="ตู", ["ቲ"]="ตี", ["ታ"]="ตา", ["ቴ"]="เต", ["ት"]="ต์", ["ቶ"]="โต", 
		["ቷ"]="ต๎วา", 
	["ቸ"]="เจอ", ["ቹ"]="จู", ["ቺ"]="จี", ["ቻ"]="จา", ["ቼ"]="เจ", ["ች"]="จ์", ["ቾ"]="โจ", 
		["ቿ"]="จ๎วา", 
	["ኀ"]="เฆอ", ["ኁ"]="ฆู", ["ኂ"]="ฆี", ["ኃ"]="ฆา", ["ኄ"]="เฆ", ["ኅ"]="ฆ์", ["ኆ"]="โฆ", 
		["ኈ"]="เฆ๎วอ", ["ኊ"]="ฆ๎วี", ["ኋ"]="ฆ๎วา", ["ኌ"]="เฆ๎ว", ["ኍ"]="ฆ๎ว์", 
	["ነ"]="เนอ", ["ኑ"]="นู", ["ኒ"]="นี", ["ና"]="นา", ["ኔ"]="เน", ["ን"]="น์", ["ኖ"]="โน",
		["ኗ"]="น๎วา", 
	["ኘ"]="เญอ", ["ኙ"]="ญู", ["ኚ"]="ญี", ["ኛ"]="ญา", ["ኜ"]="เญ", ["ኝ"]="ญ์", ["ኞ"]="โญ", 
		["ኟ"]="ญ๎วา", 
	["አ"]="เออ", ["ኡ"]="อู", ["ኢ"]="อี", ["ኣ"]="อา", ["ኤ"]="เอ", ["እ"]="อ์", ["ኦ"]="โอ",
		["ኧ"]="อ๎วา", 
	["ከ"]="เกอ", ["ኩ"]="กู", ["ኪ"]="กี", ["ካ"]="กา", ["ኬ"]="เก", ["ክ"]="ก์", ["ኮ"]="โก", 
		["ኰ"]="เก๎วอ", ["ኲ"]="ก๎วี", ["ኳ"]="ก๎วา", ["ኴ"]="เก๎ว", ["ኵ"]="ก๎ว์", 
	["ኸ"]="เฅอ", ["ኹ"]="ฅู", ["ኺ"]="ฅี", ["ኻ"]="ฅา", ["ኼ"]="เฅ", ["ኽ"]="ฅ์", ["ኾ"]="โฅ", 
	["ወ"]="เวอ", ["ዉ"]="วู", ["ዊ"]="วี", ["ዋ"]="วา", ["ዌ"]="เว", ["ው"]="ว์", ["ዎ"]="โว", 
	["ዐ"]="เอ̱อ", ["ዑ"]="อู̱", ["ዒ"]="อ̱ี", ["ዓ"]="อ̱า", ["ዔ"]="เอ̱", ["ዕ"]="อ์̱", ["ዖ"]="โอ̱", 
	["ዘ"]="เซ̱อ", ["ዙ"]="ซู̱", ["ዚ"]="ซ̱ี", ["ዛ"]="ซ̱า", ["ዜ"]="เซ̱", ["ዝ"]="ซ์̱", ["ዞ"]="โซ̱",
		["ዟ"]="ซ๎̱วา", 
	["ዠ"]="เฌอ", ["ዡ"]="ฌู", ["ዢ"]="ฌี", ["ዣ"]="ฌา", ["ዤ"]="เฌ", ["ዥ"]="ฌ์", ["ዦ"]="โฌ", 
		["ዧ"]="ฌ๎วา", 
	["የ"]="เยอ", ["ዩ"]="ยู", ["ዪ"]="ยี", ["ያ"]="ยา", ["ዬ"]="เย", ["ይ"]="ย์", ["ዮ"]="โย", 
	["ደ"]="เดอ", ["ዱ"]="ดู", ["ዲ"]="ดี", ["ዳ"]="ดา", ["ዴ"]="เด", ["ድ"]="ด์", ["ዶ"]="โด",
		["ዷ"]="ด๎วา", 
	["ጀ"]="เจ̱อ", ["ጁ"]="จู̱", ["ጂ"]="จ̱ี", ["ጃ"]="จ̱า", ["ጄ"]="เจ̱", ["ጅ"]="จ์̱", ["ጆ"]="โจ̱", 
		["ጇ"]="จ̱๎วา", 
	["ገ"]="เก̱อ", ["ጉ"]="กู̱", ["ጊ"]="ก̱ี", ["ጋ"]="ก̱า", ["ጌ"]="เก̱", ["ግ"]="ก์̱", ["ጎ"]="โก̱",
		["ጐ"]="เก̱๎วอ", ["ጒ"]="ก̱๎วี", ["ጓ"]="ก̱๎วา", ["ጔ"]="เก̱๎ว", ["ጕ"]="ก̱๎ว์", 
	["ጘ"]="เงอ", ["ጙ"]="งู", ["ጚ"]="งี", ["ጛ"]="งา", ["ጜ"]="เง", ["ጝ"]="ง์", ["ጞ"]="โง",
		["ⶓ"]="เง๎วอ", ["ⶔ"]="ง๎วี", ["ጟ"]="ง๎วา", ["ⶕ"]="เง๎ว", ["ⶖ"]="ง๎ว์", 
	["ጠ"]="เทอ", ["ጡ"]="ทู", ["ጢ"]="ที", ["ጣ"]="ทา", ["ጤ"]="เท", ["ጥ"]="ท์", ["ጦ"]="โท", 
		["ጧ"]="ท๎วา", 
	["ጨ"]="เชอ", ["ጩ"]="ชู", ["ጪ"]="ชี", ["ጫ"]="ชา", ["ጬ"]="เช", ["ጭ"]="ช์", ["ጮ"]="โช",
		["ጯ"]="ช๎วา", 
	["ጰ"]="เพอ", ["ጱ"]="พู", ["ጲ"]="พี", ["ጳ"]="พา", ["ጴ"]="เพ", ["ጵ"]="พ์", ["ጶ"]="โพ",
		["ጷ"]="พ๎วา",
	["ጸ"]="เษอ", ["ጹ"]="ษู", ["ጺ"]="ษี", ["ጻ"]="ษา", ["ጼ"]="เษ", ["ጽ"]="ษ์", ["ጾ"]="โษ", 
		["ጿ"]="ษ๎วา", 
	["ፀ"]="เฑอ", ["ፁ"]="ฑู", ["ፂ"]="ฑี", ["ፃ"]="ฑา", ["ፄ"]="เฑ", ["ፅ"]="ฑ์", ["ፆ"]="โฑ", 
	["ፈ"]="เฟอ", ["ፉ"]="ฟู", ["ፊ"]="ฟี", ["ፋ"]="ฟา", ["ፌ"]="เฟ", ["ፍ"]="ฟ์", ["ፎ"]="โฟ",
		["ፏ"]="ฟ๎วา", ["ፚ"]="เฟ๎ยอ", 
	["ፐ"]="เปอ", ["ፑ"]="ปู", ["ፒ"]="ปี", ["ፓ"]="ปา", ["ፔ"]="เป", ["ፕ"]="ป์", ["ፖ"]="โป", 
		["ፗ"]="ป๎วา",
	--punctuation
	["፠"]="§", ["፡"]="-", ["።"]=".", ["፣"]=",", ["፤"]=";", ["፥"]=":", ["፦"]=":-", ["፧"]="?", ["፨"]="¶",
}

local number = {
	['፩']=1, ['፪']=2, ['፫']=3, ['፬']=4, ['፭']=5, ['፮']=6, ['፯']=7, ['፰']=8, ['፱']=9,
	['፲']=10, ['፳']=20, ['፴']=30, ['፵']=40, ['፶']=50, ['፷']=60, ['፸']=70, ['፹']=80, ['፺']=90
}

function export.number(geez)

	local val = 0
	if mw.ustring.find(geez, '^[፻፼]') then
		geez = '፩' .. geez -- prepend 1
	end
	local func = mw.text.gsplit(geez, '')
	
	while true do
		local digit = func()
		if (not digit) then break end
		if mw.ustring.find(digit, '[፩-፺]') then
			val = val + number[digit]
		elseif digit == '፻' then
			val = val * 100
		elseif digit == '፼' then
			val = val * 10000
		end
	end
	
	return val

end

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

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

	text = mw.ustring.gsub(text, ".", tt)
	text = mw.ustring.gsub(text, "([์๎])([̱͇])", "%2%1") -- correct Mediawiki's interfering

	text = mw.ustring.gsub(text, "^(.[̱͇]?)์", "%1ือ")
	text = mw.ustring.gsub(text, "([%s%p%d])(.[̱͇]?)์", "%1%2ือ")

	text = mw.ustring.gsub(text, "(.[̱͇]?)า(.[̱͇]?)์", "%1ั%2์")
	text = mw.ustring.gsub(text, "(.[̱͇]?)ี(.[̱͇]?)์", "%1ิ%2์")
	text = mw.ustring.gsub(text, "(.[̱͇]?)ู(.[̱͇]?)์", "%1ุ%2์")
	text = mw.ustring.gsub(text, "เ(.[̱͇]?)(.[̱͇]?)์", "เ%1็%2์")
	text = mw.ustring.gsub(text, "โ(.[̱͇]?)(.[̱͇]?)์", "โ%1็%2์")
	text = mw.ustring.gsub(text, "(.[̱͇]?)ือ(.[̱͇]?)์", "%1ึ%2์")
	text = mw.ustring.gsub(text, "เ(.[̱͇]?)อ(.[̱͇]?)์", "เ%1ิ%2์")

	text = mw.ustring.gsub(text, "(.[̱͇]?)ัว์", "เ%1า")

	text = mw.ustring.gsub(text, "[፩-፼]+", export.number)

	return text

end

return export