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

มอดูล:ko-translit-Thai

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

ข้อผิดพลาด Lua ใน มอดูล:documentation/translit บรรทัดที่ 21: Base segment of title should end in -translit: ko-translit-Thai


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

function export.tr(word, lang, sc)
	-- remove hanja
	-- Hani regex is a reasonable subset of Hani from [[Module:scripts/data]],
	-- last checked on 20220221
	word = gsub(word, "%([一-鿿㐀-䶿𠀀-𮯯𰀀-𱍏]+%)", "")
	word = gsub(word, "%([一-鿿㐀-䶿𠀀-𮯯𰀀-𱍏]*'''[一-鿿㐀-䶿𠀀-𮯯𰀀-𱍏]+'''[一-鿿㐀-䶿𠀀-𮯯𰀀-𱍏]*%)", "")

	-- transform em-dash to plain hyphen-minus
	word = gsub(word, "—", "-")
	
	--อักษรเดี่ยว
	if match(word, "^[ㄱㄲㄳㄴㄵㄶㄷㄸㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅃㅄㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ%-]+$") then
		return (gsub(word,
			"[ㄱㄲㄳㄴㄵㄶㄷㄸㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅃㅄㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ]", {
				["ㄱ"] = "ค/ก", ["ㄲ"] = "ก", ["ㄳ"] = "กซ", ["ㄴ"] = "น", ["ㄵ"] = "นจ", ["ㄶ"] = "นฮ", ["ㄷ"] = "ท/ด", ["ㄸ"] = "ต", ["ㄹ"] = "ร/ล", ["ㄺ"] = "ลก",
				["ㄻ"] = "ลม", ["ㄼ"] = "ลบ", ["ㄽ"] = "ลซ", ["ㄾ"] = "ลต", ["ㄿ"] = "ลป", ["ㅀ"] = "ลฮ", ["ㅁ"] = "ม", ["ㅂ"] = "พ/บ", ["ㅃ"] = "ป", ["ㅄ"] = "ปซ",
				["ㅅ"] = "ซ", ["ㅆ"] = "ซ", ["ㅇ"] = "อ/ง", ["ㅈ"] = "ช/จ", ["ㅉ"] = "จ", ["ㅊ"] = "ช", ["ㅋ"] = "ค", ["ㅌ"] = "ท", ["ㅍ"] = "พ", ["ㅎ"] = "ฮ",
				["ㅏ"] = "อา", ["ㅐ"] = "แอ", ["ㅑ"] = "ยา", ["ㅒ"] = "แย", ["ㅓ"] = "ออ̂", ["ㅔ"] = "เอ", ["ㅕ"] = "ยอ̂",
				["ㅖ"] = "เย", ["ㅗ"] = "โอ", ["ㅘ"] = "วา", ["ㅙ"] = "แว", ["ㅚ"] = "เออ̂", ["ㅛ"] = "โย", ["ㅜ"] = "อู",
				["ㅝ"] = "วอ̂", ["ㅞ"] = "เว", ["ㅟ"] = "วี", ["ㅠ"] = "ยู", ["ㅡ"] = "อือ̂", ["ㅢ"] = "อึย", ["ㅣ"] = "อี" }
		))
	end
	
	if not match(word, "[가-힣]") then
		return nil
	end
	
	-- transform compat jamo into a form [[Module:ko-pron]] can handle
	-- for [[-ㅂ니까]] [[-ㅁ둥]] etc.
	-- could be moved to [[Module:ko-pron]]
	if match(word, "%-[ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅅㅆㅇㅈㅊㅋㅌㅍㅎ]") then
		word = gsub(word,
			"[ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅅㅆㅇㅈㅊㅋㅌㅍㅎ]", {
				["ㄱ"] = "ᆨ", ["ㄲ"] = "ᆩ", ["ㄳ"] = "ᆪ", ["ㄴ"] = "ᆫ", ["ㄵ"] = "ᆬ", ["ㄶ"] = "ᆭ", ["ㄷ"] = "ᆮ", ["ㄹ"] = "ᆯ", ["ㄺ"] = "ᆰ",
				["ㄻ"] = "ᆱ", ["ㄼ"] = "ᆲ", ["ㄽ"] = "ᆳ", ["ㄾ"] = "ᆴ", ["ㄿ"] = "ᆵ", ["ㅀ"] = "ᆶ", ["ㅁ"] = "ᆷ", ["ㅂ"] = "ᆸ", ["ㅄ"] = "ᆹ",
				["ㅅ"] = "ᆺ", ["ㅆ"] = "ᆻ", ["ㅇ"] = "ᆼ", ["ㅈ"] = "ᆽ", ["ㅊ"] = "ᆾ", ["ㅋ"] = "ᆿ", ["ㅌ"] = "ᇀ", ["ㅍ"] = "ᇁ", ["ㅎ"] = "ᇂ" }
		)
	end

	local m_pron = require("Module:ko-pron")
	local revised = m_pron.romanise(word, 7, {}, true)
	
	if not revised then
		return nil
	end
	
	if match(revised, "[%.%?%!]") then
		revised = mw.ustring.upper(mw.ustring.sub(revised, 1, 1)) .. mw.ustring.sub(revised, 2, -1)
		revised = gsub(revised, "([%.%?%!]) ([a-z%'])", "%1 ^%2")
		revised = gsub(revised, "^%'%'%'", "'''^")
	end
	revised = gsub(revised, "([a-z])%-%'([a-z])", "%1-%2")
	revised = gsub(revised, "%^%'%'%'", "'''^")
	revised = gsub(revised, "%^%l", mw.ustring.upper)
	revised = gsub(revised, '%^', '')
	revised = gsub(revised, "%-'''%-", "'''-")
	revised = gsub(revised, "%-%-", "-")
	
	return revised
end

export.tr_revised = export.tr

return export

--[[
	revised = table.concat(revised,"")
	--ปรับแต่งอักษรไทย
	revised = mw.ustring.gsub(revised, '…', 'อ')
	revised = mw.ustring.gsub(revised, '^([าีืู↶])', 'อ%1')
	revised = mw.ustring.gsub(revised, '([%s0-9—])([าีืู↶])', '%1อ%2')
	revised = mw.ustring.gsub(revised, '^(อ̂)', 'อ%1')
	revised = mw.ustring.gsub(revised, '([%s0-9—])(อ̂)', '%1อ%2')
	revised = mw.ustring.gsub(revised, '^ฺ', '')
	revised = mw.ustring.gsub(revised, '([%s0-9—])ฺ', '%1')

	revised = mw.ustring.gsub(revised, '([ก-ฮ])↶([เแโ])', '%2%1')

	revised = mw.ustring.gsub(revised, '([ก-ฮ])า([ก-ฮ])([ก-ฮ])(อ̂)', '%1ั%2%3%4')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])า([ก-ฮ])([ก-ฮ])([ัาิีึืฺุู็])', '%1ั%2%3%4')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])า([ก-ฮ])([เแโ])', '%1ั%2%3')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])า([ก-ฮ]) ', '%1ั%2 ')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])า([ก-ฮ])$', '%1ั%2')

	revised = mw.ustring.gsub(revised, '([ก-ฮ])ี([ก-ฮ])([ก-ฮ])(อ̂)', '%1ิ%2%3%4')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])ี([ก-ฮ])([ก-ฮ])([ัาิีึืฺุู็])', '%1ิ%2%3%4')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])ี([ก-ฮ])([เแโ])', '%1ิ%2%3')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])ี([ก-ฮ]) ', '%1ิ%2 ')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])ี([ก-ฮ])$', '%1ิ%2')

	revised = mw.ustring.gsub(revised, '([ก-ฮ])ื([ก-ฮ])([ก-ฮ])(อ̂)', '%1ึ%2%3%4')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])ื([ก-ฮ])([ก-ฮ])([ัาิีึืฺุู็])', '%1ึ%2%3%4')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])ื([ก-ฮ])([เแโ])', '%1ึ%2%3')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])ื([ก-ฮ]) ', '%1ึ%2 ')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])ื([ก-ฮ])$', '%1ึ%2')

	revised = mw.ustring.gsub(revised, '([ก-ฮ])ู([ก-ฮ])([ก-ฮ])(อ̂)', '%1ุ%2%3%4')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])ู([ก-ฮ])([ก-ฮ])([ัาิีึืฺุู็])', '%1ุ%2%3%4')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])ู([ก-ฮ])([เแโ])', '%1ุ%2%3')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])ู([ก-ฮ]) ', '%1ุ%2 ')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])ู([ก-ฮ])$', '%1ุ%2')

	revised = mw.ustring.gsub(revised, '([ก-ฮ])อ̂([ก-ฮ])([ก-ฮ])(อ̂)', '%1็อ̂%2%3%4')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])อ̂([ก-ฮ])([ก-ฮ])([ัาิีึืฺุู็])', '%1็อ̂%2%3%4')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])อ̂([ก-ฮ])([เแโ])', '%1็อ̂%2%3')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])อ̂([ก-ฮ]) ', '%1็อ̂%2 ')
	revised = mw.ustring.gsub(revised, '([ก-ฮ])อ̂([ก-ฮ])$', '%1็อ̂%2')

	revised = mw.ustring.gsub(revised, '([เแโ])([ก-ฮ])([ก-ฮ])([ก-ฮ])(อ̂)', '%1%2็%3%4%5')
	revised = mw.ustring.gsub(revised, '([เแโ])([ก-ฮ])([ก-ฮ])([ก-ฮ])([ัาิีึืฺุู็])', '%1%2็%3%4%5')
	revised = mw.ustring.gsub(revised, '([เแโ])([ก-ฮ])([ก-ฮ])([เแโ])', '%1%2็%3%4')
	revised = mw.ustring.gsub(revised, '([เแโ])([ก-ฮ])([ก-ฮ]) ', '%1%2็%3 ')
	revised = mw.ustring.gsub(revised, '([เแโ])([ก-ฮ])([ก-ฮ])$', '%1%2็%3')

	revised = mw.ustring.gsub(revised, 'อฺ', '')
	revised = mw.ustring.gsub(revised, '—', '-')
--]]