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

มอดูล:Kali-translit

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

This module will transliterate text in the อักษรกะยา. It is used to transliterate กะยาตะวันตก. 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:Kali-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 gsub = mw.ustring.gsub
local u = mw.ustring.char

local tt1 = {
	-- consonants
	['ꤊ'] = 'ก', ['ꤋ'] = 'ค', ['ꤌ'] = 'ฆ', ['ꤍ'] = 'ง',
	['ꤎ'] = 'ส', ['ꤏ'] = 'ศ', ['ꤐ'] = 'ซ', ['ꤑ'] = 'ญ',
	['ꤒ'] = 'ต', ['ꤓ'] = 'ท', ['ꤔ'] = 'น',
	['ꤕ'] = 'ป', ['ꤖ'] = 'พ', ['ꤗ'] = 'ม',
	['ꤘ'] = 'ด', ['ꤙ'] = 'บ',
	['ꤚ'] = 'ร', ['ꤛ'] = 'ย', ['ꤜ'] = 'ล', ['ꤝ'] = 'ว',
	['ꤞ'] = 'ษ', ['ꤟ'] = 'ฮ', ['ꤠ'] = 'ฝ', ['ꤡ'] = 'จ',
	-- vowels
	['ꤢ'] = '@า', ['ꤣ'] = '@เอ̂', ['ꤤ'] = '@ี', ['ꤥ'] = '@โ',
	-- tones
	['꤫'] = '⁵', ['꤬'] = '¹', ['꤭'] = '³',
	-- marks
	['꤮'] = '-', ['꤯'] = 'ฯ',
	-- numerals
	['꤀'] = '0', ['꤁'] = '1', ['꤂'] = '2', ['꤃'] = '3', ['꤄'] = '4',
	['꤅'] = '5', ['꤆'] = '6', ['꤇'] = '7', ['꤈'] = '8', ['꤉'] = '9',
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = '‼',
}

local tt2 = {
	-- vowels
	['ꤢꤦ'] = '@ือ̂', ['ꤢꤧ'] = '@แ', ['ꤢꤨ'] = '@ู',
	['ꤢꤩ'] = '@เ', ['ꤢꤪ'] = '@อ̂',
	['ꤣꤦ'] = '@เอ̂͜อือ̂', ['ꤣꤧ'] = '@ือ̂͜แอ', ['ꤣꤨ'] = '@เอ̂ว',
	['ꤣꤩ'] = '@เอ̂͜เอ', ['ꤣꤪ'] = '@เอ̂͜ออ̂',
}

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, 'ꤟꤌꤣ', '@เ̤ือ̂')
	text = gsub(text, 'ꤛꤣ', '@เือ̂')
	text = gsub(text, '[ꤢꤣ][ꤦ-ꤪ]', tt2)
	text = gsub(text, '.', tt1)

	text = gsub(text, '^@', 'อ')
	text = gsub(text, '([%s%p])@', '%1อ')

	text = gsub(text, '@', '')

	text = gsub(text, '([ก-ฮ]̤?)([เแโ])', '%2%1')

	return text
 
end
 
return export