Module:th

Hello, you have come here looking for the meaning of the word Module:th. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:th, but we will also tell you about its etymology, its characteristics and you will know how to say Module:th in singular and plural. Everything you need to know about the word Module:th you have here. The definition of the word Module:th will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:th, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module does things related to Thai. See {{th-new}}, {{th-l}} and {{th-usex}}.


local export = {}

local lang = require("Module:languages").getByCode("th")
local sc = require("Module:scripts").getByCode("Thai")

local m_str_utils = require("Module:string utilities")
local m_translit = require("Module:th-translit")
local m_links = require("Module:links")
local m_columns = require("Module:columns")

local gmatch = m_str_utils.gmatch
local gsub = m_str_utils.gsub
local len = m_str_utils.len
local match = m_str_utils.match
local sub = m_str_utils.sub
local u = m_str_utils.char
local upper = m_str_utils.upper


local function track(page)
	require("Module:debug/track")("th/" .. page)
	return true
end

function export.new(frame)
	local title = mw.title.getCurrentTitle().text
	local parent_args = frame:getParent().args
	
	local params = {
		 = { default = title },
		 = { default = "" }, -- pos 1
		 = { default = "{{rfdef|th}}" }, -- def 1
		 = true, -- pos 2
		 = { default = "{{rfdef|th}}" }, -- def 2
		 = true, -- pos 3
		 = { default = "{{rfdef|th}}" }, -- def 3
		 = true,
		 = { alias_of = "etym" },
		 = true,
		 = true,
		 = true,
		 = true,
		 = true,
		 = true,
	}
	
	args = require("Module:parameters").process(parent_args, params)
	local result = ""
	
	local function genTitle(text)
		local pos_title = {
			 = "Noun",  = "Noun",  = "Proper noun",  = "Proper noun",  = "Pronoun",
			 = "Verb",  = "Adjective",  = "Adjective",  = "Adverb",
			 = "Preposition",  = "Postposition",  = "Conjunction",
			 = "Particle",  = "Suffix",
			 = "Proverb",  = "Idiom",  = "Phrase",  = "Interjection",  = "Interjection",
			 = "Classifier",  = "Classifier",  = "Numeral",  = "Abbreviation",  = "Determiner"
		};
		return pos_title or upper(sub(text, 1, 1)) .. sub(text, 2, -1)
	end
	
	local function genHead(text)
		local pos_head = {
			 = "noun",  = "noun",  = "proper noun",  = "proper noun",  = "verb",  = "adj",
			 = "post",  = "con",  = "particle",  = "pronoun",
			 = "proverb",  = "idiom",  = "phrase",  = "interj",
			 = "abbr",  = "cls",  = "det"
		};
		return pos_head or text
	end
	
	local function other(class, title, args)
		local code = ""
		if args then
			code = code .. "\n\n===" .. title .. "===\n{{col3|th|" .. 
				table.concat(mw.text.split(args, ","), "|")
			i = 2
			while args do
				code = code .. "|" .. args
				i = i + 1
			end
			code = code .. "}}"
		end
		return code
	end
	
	if args then
		args = "From {{com|th|" .. args .. "|" .. args .. (args and "|" .. args or "") .. "}}."
		args = " .. "]] .. "]]"
	end
	
	result = result .. "==Thai=="
	if args then result = result .. "\n{{wikipedia|lang=th" .. (args ~= "y" and "|" .. args or "") .. "}}" end
	if args then result = result .. "\n .. "|thumb|" .. (args or "{{lang|th|" .. title .. "}}") .. "]]" end
	result = result .. other("alt", "Alternative forms", args)
	
	if args then result = result .. "\n\n===Etymology===\n" .. args end
	
	result = result .. "\n\n===Pronunciation===\n{{th-pron" .. ((args ~= title and args ~= "") and ("|" .. gsub(args, ",", "|")) or "") .. "}}"
	result = result .. "\n\n===" .. genTitle(args) .. "===\n{{th-" .. genHead(args) ..
	((args and genHead(args) == "noun") and "|" .. args or "") .. 
	(args and ("|head=" .. args) or "") .. 
	((args and genHead(args) == "verb") and "|~" or "") .. "}}\n\n# " .. args
	
	result = result .. other("syn", "=Synonyms=", args)
	result = result .. other("ant", "=Antonyms=", args)
	result = result .. other("der", "=Derived terms=", args)
	result = result .. other("rel", "=Related terms=", args)
	result = result .. other("also", "=See also=", args)
	
	if args then
		result = result .. "\n\n===" .. genTitle(args) .. "===\n{{th-" .. genHead(args) .. 
		((args and genHead(args) == "noun") and "|" .. args or "") .. 
		(args and ("|head=" .. args) or "") .. 
		((args and genHead(args) == "verb") and "|~" or "") .. 
		"}}\n\n# " .. args
	end
	
	if args then
		result = result .. "\n\n===" .. genTitle(args) .. "===\n{{th-" .. genHead(args) .. 
		((args and genHead(args) == "noun") and "|" .. args or "") .. 
		(args and ("|head=" .. args) or "") .. 
		((args and genHead(args) == "verb") and "|~" or "") .. 
		"}}\n\n# " .. args
	end
	
	if args then
		result = result .. "\n\n{{C|th|" .. args .. "}}"
	end
	
	return result
end

function export.getTranslit(lemmas, phonSpell)
	local m_th_pron = require("Module:th-pron")
	if not phonSpell then
		phonSpell = lemmas
		for lemma in gmatch(lemmas, "+") do
			local title = mw.title.new(lemma)
			if title and title.exists then
				local content = title:getContent()
				local template = match(content, "{{th%-pron*}}")
				if template ~= "" then
					lemma = gsub(lemma, "%-", "%" .. "-")
					if template == "{{th-pron}}" then phonSpell = lemma break end
					template = match(content, "{{th%-pron|(+)}}")
					phonSpell = gsub(phonSpell, lemma, template and mw.text.split(template, "|") or lemma)
					phonSpell = gsub(phonSpell, "%%%-", "-")
				end
			end
		end
	end
	local transcription = m_th_pron.translit(phonSpell, "th", "Thai", "paiboon", "translit-module")
	transcription = transcription or nil
	return transcription
end
	
function export.format_link(lemma, phonSpell, gloss)
	local transcription = export.getTranslit(lemma, phonSpell)
	return m_links.full_link({lang = lang, term = lemma, gloss = gloss, sc = sc, tr = transcription}, nil, true)
end

function export.link(frame)
	local params = {
		 = {required = true},
		 = {},
		gloss = {alias_of = 2},
		p = {},
	}
	local parent_args = frame:getParent().args
	local args = require("Module:parameters").process(parent_args, params)
	return export.format_link(args, args.p, args)
end

function export.usex(frame)
	local parent_args = frame:getParent().args
	if parent_args.bold then
		track("usex-bold")
	end
	local params = {
		 = {required = true},
		 = {},
		 = {type = "boolean"},
		 = {type = "boolean"},
		 = {}, -- for testing or documentation purposes
	}
	local args = require("Module:parameters").process(parent_args, params)
	local boldCode = "%'%'%'"
	local pagename = args.pagename or mw.title.getCurrentTitle().text
	local text = {}
	local example = args
	local translation = args
	local noBold = args
	local exSet, romSet = {}, {}
	local inline = frame.args.inline or args.inline
	
	boldify = example ~= pagename
	if not match(example, boldCode) and boldify and not noBold and len(pagename) > 1 then
		pagename = gsub(pagename, "%-", u(0x2011))
		example = gsub(example, "%-", u(0x2011))
		example = gsub(example, "(.?)(" .. pagename .. ")(.?)", function(pre, captured, post)
			if not match(pre .. post, "") then
				for captured_part in mw.text.gsplit(captured, " ") do
					captured = gsub(captured, captured_part, "'''" .. captured_part .. "'''")
				end
			end
			return pre .. captured .. post
		end)
	end
	
	example = gsub(example, u(0x2011), "-")
	example = gsub(example, "'''({+})", "%1'''")
	example = gsub(example, "%*", pagename) -- shorthand
	example = gsub(example, "ฯ  ", "ฯ ")
	example = gsub(example, "  ", " & ")
	example = gsub(example, "(+)", " %1 ") -- Allow European digits
	example = gsub(example, " +", " ")
	example = gsub(example, "^ ", "")
	example = gsub(example, " $", "")
	
	local syllables = mw.text.split(example, " ", true)
	local count = 0
	
	for index, thaiWord in ipairs(syllables) do
		local phonSpell, content, template = "", "", ""
		if thaiWord == "'''" then
			count = count + 1
			thaiWord = count % 2 == 1 and "<b>" or "</b>"
		end
		if match(thaiWord, "") then
			phonSpell = thaiWord
			if match(thaiWord, "") then
				phonSpell = match(phonSpell, "{(+)}")
				thaiWord = match(thaiWord, "^+")
			else
				local titleWord = thaiWord == "ๆ" and lastWord or thaiWord
				if match(titleWord, "^+$") and mw.title.new(titleWord).exists then
					content = mw.title.new(titleWord):getContent()
					template = match(content, "{{th%-pron*}}")
					if template ~= "" then
						template = match(content, "{{th%-pron|(+)}}")
						phonSpell = template and mw.text.split(template, "|") or titleWord
					else
						phonSpell = titleWord
					end
				else
					phonSpell = titleWord
				end
			end
			lastWord = thaiWord
			table.insert(exSet, "]")
			thaiWord = gsub(thaiWord, boldCode .. "(+)" .. boldCode, "<b>%1</b>")
			
			local transcript = m_translit.tr(phonSpell, "th", "Thai")
			if not transcript then
				if mw.title.new(thaiWord).exists then
					error("The word " .. thaiWord .. " was not romanised successfully. " ..
						"Please try adding bolding markup to the example, " ..
						"or apply |bold=n to the template. If both are still unsuccessful, " ..
						"please report the problem at ].")
				else
					error("The word ] was not romanised successfully. " ..
						"Please supply its syllabified phonetic respelling, " .. 
						"enclosed by {} and placed after the word (see ]).")
				end
			end
			table.insert(romSet, transcript)
		else
			table.insert(exSet, thaiWord)
			table.insert(romSet, m_translit.tr(thaiWord, "th", "Thai"))
		end
	end
	
	example = table.concat(exSet)
	example = gsub(example, " ", "")
	example = gsub(example, "&", " ")
	example = gsub(example, "ฯ", "ฯ ")
	example = gsub(example, "()(%%])", "%1 %2")
	example = gsub(example, "(%%])()", "%1 %2")
	
	translit = table.concat(romSet, " ")
	translit = gsub(translit, "^ +", "")
	translit = gsub(translit, " & ", " · ")
	translit = gsub(translit, "&", " ")
	
	translit = gsub(translit, "<b> ", "<b>")
	translit = gsub(translit, " </b>", "</b>")
	translit = gsub(translit, " :", ":")
	translit = gsub(translit, "%( ", "(")
	translit = gsub(translit, " %)", ")")
	translit = gsub(translit, " ()", "%1")
	
	while match(translit, "") do
		translit = gsub(translit, "'", "‘", 1)
		translit = gsub(translit, "'", "’", 1)
		translit = gsub(translit, '"', "“", 1)
		translit = gsub(translit, '"', "”", 1)
	end	
	translit = gsub(translit, "() ", "%1")
	translit = gsub(translit, " ()", "%1")
	translit = gsub(translit, "(%a)%- ", "%1-")
	
	if not translation then
		table.insert(text, '<span lang="th" class="Thai e-example">' .. example .. '</span>' .. '<span>(<i>' .. translit .. '</i>)</span>')
	else
		table.insert(text, ('<span lang="th" class="Thai e-example">%s</span>'):format(example))
		if not inline then -- match(example, "") or len(example) > 50 then
			table.insert(text, "<dl><dd class=\"e-transliteration\">''" .. translit .. "''</dd><dd class=\"e-translation\">" .. translation .. "</dd></dl>")
		else
			table.insert(text, "&nbsp; ―&nbsp; <i class=\"e-transliteration\">" .. translit .. "</i>&nbsp; ―&nbsp; <span class=\"e-translation\">" .. translation .. "</span>")
		end
	end
	return table.concat(text)
end

function export.derived(frame, other_types)
	local obsolete_note = '<sup><span class="explain" title="Archaic, obsolete or dated.">†</span></sup>'
	local args = frame:getParent().args
	local pagename = mw.title.getCurrentTitle().text
	local result = {}
	local length = 0
	
	unfold = args and true or false
	title = args or false
	title_text = title or other_types or "Derived terms"

	if args then
		return '<div class="pseudo NavFrame" ><div class="NavHead" style="text-align:left">' .. title_text ..
			' <span style="font-weight: normal" >— <i>see</i></span > ' .. m_links.full_link({ lang = lang, term = args }) .. '</div></div>'
	end

	for i, word in ipairs(args) do
		word, is_obsolete = gsub(word, "†", "")
		obsolete = is_obsolete > 0 and obsolete_note or ""
		local word_parts = mw.text.split(gsub(word, "\n", "" ), ":")
		table.insert(result, obsolete .. 
			m_links.full_link({ lang = lang, term = word_parts, gloss = word_parts or nil }))
		
		length = math.max(len(word), length)
	end
	
	return 
		m_columns.create_table(
			(length > 15 and 2 or 3), 
			result, 
			1, 
			"#F5F5FF",
			((unfold or #result < 7) and false or true), 
			"Derived terms",
			title_text, 
			nil, 
			nil,
			lang
		)
end

function export.synonym(frame)
	return export.derived(frame, "Synonyms")
end

function export.antonym(frame)
	return export.derived(frame, "Antonyms")
end

function export.also(frame)
	return export.derived(frame, "See also")
end

function export.alternative(frame)
	return export.derived(frame, "Alternative forms")
end

function export.related(frame)
	return export.derived(frame, "Related terms")
end

return export