มอดูล:Laoo-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 มอดูล:Laoo-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 u = mw.ustring.char

local tt = {
	-- consonants
	['ກ'] = 'ก', ['ຂ'] = 'ข', ['ຄ'] = 'ค', ['ງ'] = 'ง', ['ຈ'] = 'จ',
	['ຊ'] = 'ซ', ['ຍ'] = 'ย̃', ['ດ'] = 'ด', ['ຕ'] = 'ต', ['ຖ'] = 'ถ',
	['ທ'] = 'ท', ['ນ'] = 'น', ['ບ'] = 'บ', ['ປ'] = 'ป', ['ຜ'] = 'ผ',
	['ຝ'] = 'ฝ', ['ພ'] = 'พ', ['ຟ'] = 'ฟ', ['ມ'] = 'ม', ['ຢ'] = 'ย',
	['ຣ'] = 'ร', ['ລ'] = 'ล', ['ວ'] = 'ว', ['ສ'] = 'ส', ['ຫ'] = 'ห',
	['ອ'] = 'อ', ['ຮ'] = 'ฮ', ['ຼ'] = 'ล', ['ຽ'] = 'ย͢',
	['ໜ'] = 'หน', ['ໝ'] = 'หม', ['ໞ'] = 'ก̷', ['ໟ'] = 'ย̷̃',
	-- Pali and Sanskrit
	['ຆ'] = 'ฆ', ['ຉ'] = 'ฉ', ['ຌ'] = 'ฌ', ['ຎ'] = 'ญ',
	['ຏ'] = 'ฏ', ['ຐ'] = 'ฐ', ['ຑ'] = 'ฑ', ['ຒ'] = 'ฒ', ['ຓ'] = 'ณ',
	['ຘ'] = 'ธ', ['ຠ'] = 'ภ', ['ຨ'] = 'ศ', ['ຩ'] = 'ษ', ['ຬ'] = 'ฬ', ['຺'] = 'ฺ',
	-- punctuations
	['ຯ'] = 'ฯ', ['ໆ'] = 'ๆ',
	-- vowels
	['ະ'] = 'ะ', ['ັ'] = 'ั', ['າ'] = 'า', ['ຳ'] = 'ำ',
	['ິ'] = 'ิ', ['ີ'] = 'ี', ['ຶ'] = 'ึ', ['ື'] = 'ื',
	['ຸ'] = 'ุ', ['ູ'] = 'ู', ['ົ'] = '็',
	['ເ'] = 'เ', ['ແ'] = 'แ', ['ໂ'] = 'โ', ['ໃ'] = 'ใ', ['ໄ'] = 'ไ',
	-- tones and diacritics
	['່'] = '่', ['້'] = '้', ['໊'] = '๊', ['໋'] = '๋', ['໌'] = '์', ['ໍ'] = 'ํ',
	-- numerals
	['໐'] = '๐', ['໑'] = '๑', ['໒'] = '๒', ['໓'] = '๓', ['໔'] = '๔',
	['໕'] = '๕', ['໖'] = '๖', ['໗'] = '๗', ['໘'] = '๘', ['໙'] = '๙',
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = '‼',
}

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, '.', tt)

	if lang == "pi" or lang == "sa" then
		text = gsub(text, "ซ", "ช")
	end

	-- ย้ายสัญลักษณ์ลงล่าง เมื่อมีสระบนและวรรณยุกต์
	text = gsub(text, u(0x0303)..'([ัำิ-ื็-๎])', u(0x0330)..'%1') -- tilde above > tilde below

	return text

end

return export