Module:ko-translit

From Linguifex
Revision as of 00:08, 2 December 2023 by Sware (talk | contribs) (Created page with "local export = {} local gsub = mw.ustring.gsub local match = mw.ustring.match function export.tr(text, lang, sc) if (not text) or text == "" then return text end local HaniChars = require("Module:scripts").getByCode("Hani"):getCharacters() text = gsub(text, "%<%/?r[pt]%>", "") text = gsub(text, "%<%/?ruby%>", "") -- remove hanja from (ex.) 사전(辭典) and 辭典(사전) text = gsub(text, "%([" .. HaniChars .. "]+%)", "") text = gsub(text, "%([" .. HaniChars...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:ko-translit/doc

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

function export.tr(text, lang, sc)
	if (not text) or text == "" then
		return text
	end
	local HaniChars = require("Module:scripts").getByCode("Hani"):getCharacters()
	text = gsub(text, "%<%/?r[pt]%>", "")
	text = gsub(text, "%<%/?ruby%>", "")
	-- remove hanja from (ex.) 사전(辭典) and 辭典(사전)
	text = gsub(text, "%([" .. HaniChars .. "]+%)", "")
	text = gsub(text, "%([" .. HaniChars .. "]*'''[" .. HaniChars .. "]+'''[" .. HaniChars .. "]*%)", "")
	text = gsub(text, "[" .. HaniChars .. "]+%((.-)%)", "%1")
	
	-- transform em-dash to plain hyphen-minus
	text = gsub(text, "—", "-")
	
	local HangChars = require("Module:scripts").getByCode("Hang"):getCharacters()
	local m_pron = require("Module:ko-pron")
	
	text = gsub(text, "[" .. HangChars .. "%s%p􀀀-􏿽]+", function(m1) return m_pron.romanise(m1, 2, {}, true) end)
	
	return text and text
		:gsub("([A-Za-z])%-%'([A-Za-z])", "%1-%2")
		:gsub("%-'''%-", "'''-")
		:gsub("%-%-", "-")
end

export.tr_revised = export.tr

return export