Modül:cmn-söyleniş

Merhaba, buraya Modül:cmn-söyleniş kelimesinin anlamını aramaya geldiniz. DICTIOUS'da Modül:cmn-söyleniş kelimesinin tüm sözlük anlamlarını bulmakla kalmayacak, aynı zamanda etimolojisini, özelliklerini ve Modül:cmn-söyleniş kelimesinin tekil ve çoğul olarak nasıl söylendiğini de öğreneceksiniz. Modül:cmn-söyleniş kelimesi hakkında bilmeniz gereken her şey burada. Modül:cmn-söyleniş kelimesinin tanımı, konuşurken veya metinlerinizi yazarken daha kesin ve doğru olmanıza yardımcı olacaktır. XXX'in ve diğer kelimelerin tanımını bilmek, kelime dağarcığınızı zenginleştirir ve size daha fazla ve daha iyi dilsel kaynaklar sağlar.
Modül belgelemesi
local cikart = {}

local find = mw.ustring.find
local gsub = mw.ustring.gsub
local len = mw.ustring.len
local match = mw.ustring.match
local sub = mw.ustring.sub
local split = mw.text.split
local gsplit = mw.text.gsplit

local m_zh = require("Modül:zh")
local _m_zh_data = nil
local hom_data = mw.loadData("Modül:zh/veri/cmn-eşs")

-- if not empty
local function ine(var)
	if var == "" then
		return nil
	else
		return var
	end
end

local breve, hacek = mw.ustring.char(0x306), mw.ustring.char(0x30C)
local decompose = mw.ustring.toNFD
local function breve_error(text)
	if type(text) ~= "string" then
		return
	end
	text = decompose(text)
	if text:find(breve) then
		error('"' .. text .. '" pinyin yazısında kısa çizgi mevcut. Bunu lütfen "' .. text:gsub(breve, hacek) .. '" ile değiştirin.', 2)
	end
end

local function m_zh_data()
	if _m_zh_data == nil then _m_zh_data = mw.loadData("Modül:zh/veri/cmn-eti") end;
	return _m_zh_data;
end

local py_detone = {
	 = 'a',  = 'a',  = 'a',  = 'a', 
	 = 'o',  = 'o',  = 'o',  = 'o', 
	 = 'e',  = 'e',  = 'e',  = 'e',
	 = 'ê',  = 'ê',  = 'ê',  = 'ê',
	 = 'i',  = 'i',  = 'i',  = 'i', 
	 = 'u',  = 'u',  = 'u',  = 'u', 
	 = 'ü',  = 'ü',  = 'ü',  = 'ü',
	 = 'm',  = 'm',  = 'm',  = 'm',
	 = 'n',  = 'n',  = 'n',  = 'n',
}

local py_tone = {
	 = '1',
	 = '2',
	 = '3',
	 = '4'
}

local tones = ''

function cikart.py_detone(f)
	local text = type(f) == 'table' and f.args or f
	return mw.ustring.toNFC(gsub(mw.ustring.toNFD(text), tones, ''))
end

function cikart.py_transf(f)
	local text = type(f) == 'table' and f.args or f
	return cikart.py_detone(text) .. cikart.tone_determ(text)
end

function cikart.tone_determ(f)
	local text = type(f) == 'table' and f.args or f
	text = mw.ustring.toNFD(text)
	return py_tone or '5'
end

function cikart.py_transform(text, detone, not_spaced)
	if type(text) == 'table' then text, detone, not_spaced = text.args, text.args, text.args end
	if find(text, '​') then
		error("Pinyin şu gizli karakteri içermekte: ​ (U+200B). Lütfen metinden bu karakteri kaldırın.")
	end
	detone = ine(detone)
	not_spaced = ine(not_spaced)
	text = gsub(gsub(mw.ustring.toNFD(text), mw.ustring.toNFD('ê'), 'ê'), mw.ustring.toNFD('ü'), 'ü')
	if find(mw.ustring.lower(text), '' .. tones .. '?' .. tones .. '') and not not_spaced then
		error(("Boşluk hecesinden önce eksik kesme işareti - \"%s\" karakteri olmalı."):format(gsub(text, '(' .. tones .. '?)(' .. tones .. ')', "%1'%2"))) end
	original_text = text
	text = gsub(text,'()()(' .. tones .. ')', '%1%3%2')
	text = gsub(text,'()(' .. tones .. ')()', '%1%3%2')
	if text ~= original_text then
		error("Pinyin'de yanlış fonetik işareti kullanımı - \"".. text .. "\" şeklinde olmalı.") end
	text = mw.ustring.lower(text)
	if not mw.ustring.find(text, tones) and text:find('') then
		return gsub(text, '(%d)(%l)', '%1 %2')
	end
	text = gsub(text, "#", " #")
	if find(text, '') then
		text = gsub(text, '()$', { = ' yī',  = ' bù'})
		text = gsub(text, '()', ' %1 ')
		text = gsub(text, '()', ' %1 ')
		text = gsub(text, ' +', ' ')
		text = gsub(text, '^ ', '')
		text = gsub(text, ' $', '')
		text = gsub(text, '%. %. %.', '...')
	end
	text = gsub(text, "", ' ')
	text = gsub(text, '(' .. tones .. '?n?g?r?)(h?)', '%1 %2')
	text = gsub(text, ' ()$', '%1')
	text = gsub(text, ' () ', '%1 ')
	if detone then
		text = mw.ustring.gsub(text, tones, py_tone)
		text = gsub(text, '()(*)', '%2%1')
		text = mw.ustring.gsub(text, '() ', '%15 ')
		text = mw.ustring.gsub(text, '()$', '%15')
	end
	if not_spaced then
		text = gsub(text, ' ', '')
	end
	return mw.ustring.toNFC(text)
end

function cikart.py_ipa(text)
	local ipa_initial = {
		 = 'p',  = 'pʰ',  = 'm',  = 'f', 
		 = 't',  = 'tʰ',  = 'n',  = 'l', 
		 = 'k',  = 'kʰ',  = 'x',  = 'ŋ', 
		 = 't͡ɕ',  = 't͡ɕʰ',  = 'ɕ', 
		 = 't͡s',  = 't͡sʰ',  = 's',  = 'ʐ', 
		 = 'ʈ͡ʂ',  = 'ʈ͡ʂʰ',  = 'ʂ', 
		 = ''
	}

	local ipa_initial_tl = {
		 = 'b̥',  = 'd̥',  = 'g̊',  = 'd͡ʑ̥',  = 'd͡z̥',  = 'ɖ͡ʐ̥'
	}

	local ipa_final = {
		 = 'ɥɑɻ',  = 'jɑ̃ɻ',  = 'jɑ̃ɻ',  = 'wɑ̃ɻ',  = 'wɑ̃ɻ',  = 'iɤ̯̃ɻ',  = 'ʊ̃ɻ',  = 'jʊ̃ɻ',  = 'jʊ̃ɻ', 
		 = 'ɥɛn',  = 'jɑŋ',  = 'jɑŋ',  = 'wɑŋ',  = 'wɑŋ',  = 'iŋ',  = 'wəŋ',  = 'jʊŋ',  = 'jʊŋ',  = 'jɑɻ',  = 'jɑɻ',  = 'wɑɻ',  = 'wɑɻ',  = 'wɑɻ',  = 'wɑɻ',  = 'jaʊ̯ɻʷ',  = 'jaʊ̯ɻʷ',  = 'ɥɑɻ',  = 'ɥɑɻ',  = 'ɑ̃ɻ',  = 'ɥɛɻ',  = 'wəɻ',  = 'wəɻ',  = 'jɤʊ̯ɻʷ',  = 'iə̯ɻ',  = 'yə̯ɻ',  = 'ɤ̃ɻ',  = 'iɤ̯̃ɻ',  = 'ʊ̃ɻ', 
		 = 'waɪ̯',  = 'waɪ̯',  = 'jaɪ̯',  = 'jɑʊ̯',  = 'jɑʊ̯',  = 'jɛn',  = 'jɛn',  = 'wän',  = 'wän',  = 'ɥɛn',  = 'ɥɛn',  = 'ɑŋ',  = 'ɥɛ',  = 'weɪ̯',  = 'joʊ̯',  = 'in',  = 'wən',  = 'yn',  = 'ɤŋ',  = 'iŋ',  = 'ʊŋ',  = 'ɑɻ',  = 'ɑɻ',  = 'jɑɻ',  = 'jɑɻ',  = 'wɑɻ',  = 'wɑɻ',  = 'aʊ̯ɻʷ',  = 'jɛɻ',  = 'jɛɻ',  = 'wɔɻ',  = 'wɔɻ',  = 'ɥɛɻ',  = 'ɥɛɻ',  = 'əɻ',  = 'əɻ',  = 'wəɻ',  = 'wəɻ',  = 'ɤʊ̯ɻʷ',  = 'jɤʊ̯ɻʷ',  = 'iə̯ɻ',  = 'yə̯ɻ',  = 'yə̯ɻ',  = 'iə̯ɻ',  = 'uɻʷ',  = 'yə̯ɻ',  = 'jɔɻ', 
		 = 'jɔ',  = 'jɔ',  = 'jä',  = 'jä',  = 'wä',  = 'wä',  = 'aɪ̯',  = 'ɑʊ̯',  = 'än',  = 'jɛ',  = 'jɛ',  = 'wɔ',  = 'wɔ',  = 'ɥɛ',  = 'ɥɛ',  = 'ɥɛ',  = 'eɪ̯',  = 'weɪ̯',  = 'oʊ̯',  = 'joʊ̯',  = 'ən',  = 'in',  = 'wən',  = 'yn',  = 'yn',  = 'i',  = 'u',  = 'y',  = 'm̩',  = 'ŋ̍',  = 'ŋ̍',  = 'ŋ̍',  = 'ɛ',  = 'ɛ',  = 'ɑɻ',  = 'ɤɻ',  = 'wɔɻ',  = 'iə̯ɻ',  = 'uɻʷ',  = 'yə̯ɻ',  = 'yə̯ɻ', 
		 = 'ä',  = 'ɤ',  = 'wɔ',  = 'i',  = 'u',  = 'y',  = 'y',  = 'm̩',  = 'm̩',  = 'n̩',  = 'n̩',  = 'n̩',  = 'ɛ'
	}

	local ipa_null = {
		 = true,  = true,  = true,  = true,
		 = true,  = true,  = true,  = true,
		 = true,  = true,  = true, 
		 = true,  = true,  = true,
	}

	local ipa_tl_ts = {
		 = '²',  = '³',  = '⁴',  = '¹',  = '¹'
	}

	local ipa_third_t_ts = {
		 = '²¹⁴⁻²¹¹',  = '²¹⁴⁻³⁵',  = '²¹⁴⁻²¹¹',  = '²¹⁴',  = '²¹⁴⁻²¹¹',  = '²¹⁴⁻²¹¹',  = '²¹⁴⁻²¹¹',  = '²¹⁴⁻²¹¹',  = '²¹⁴⁻²¹¹'
	}

	local ipa_t_values = {
		 = '⁵¹',  = '⁵⁵⁻⁵¹',  = '⁵⁵',  = '³⁵',  = '⁵⁵⁻³⁵',  = '⁵¹⁻³⁵'
	}

	local tone = {}
	local tone_cat = {}
	text = gsub(cikart.py_transform(text), '', '')
	text = gsub(text, ' +', ' ')
	local p = split(text, " ")
	
	for i = 1, #p do
		tone_cat = cikart.tone_determ(p)
		p = gsub(p, '.?', py_detone)

		if p == '一' then
			tone_cat = (cikart.tone_determ(p) == '4' or p == 'ge') and '1-2' or '1-4'
			p = 'yi'
		elseif p == '不' then
			tone_cat = (cikart.tone_determ(p) == '4') and '4-2' or '4'
			p = 'bu'
		end
	end
	
	tone_cat.length = #tone_cat
	
	local function get_initial_and_final_IPA(a, b, c)
		return a ..
		(ipa_initial or error(("Tanınmayan başlangıç: \"%s\""):format(b))) .. 
		(ipa_final or error(("Tanınmayan bitiş: \"%s\". Boşluk hecesinden önce bir kesme işareti unutmuş veya geçersiz bir Pinyin bitişi girmiş olabilir misiniz?"):format(c)))
	end

	for i, item in ipairs(p) do
		if ipa_null then item = 'ˀ' .. item end
		item = gsub(item, '()u', '%1ü')

		if item == 'ng' then
			item = ipa_final
		else
			item = gsub(item, '^(#?ˀ?)(?h?)(.+)$', 
				get_initial_and_final_IPA)
		end
		
		item = gsub(item, '(ʈ?͡?ʰ?)ir', '%1ʐ̩ɻ')
		item = gsub(item, '(ʈ?͡?ʰ?)i', '%1ʐ̩')
		item = gsub(item, '(t?͡?sʰ?)ir', '%1z̩ɻ')
		item = gsub(item, '(t?͡?sʰ?)i', '%1z̩')
		item = gsub(item, 'ʐʐ̩', 'ʐ̩')
		item = gsub(item, 'ˀwɔ', 'ˀɔ')
		
		local curr_tone_cat, next_tone_cat = tone_cat, tone_cat

		if curr_tone_cat == '5' then
			item = gsub(item, '^()()', function(a, b) return ipa_initial_tl .. b end)
			item = gsub(item, '^(͡)()', function(a, b) return ipa_initial_tl .. b end)
			item = gsub(item, 'ɤ$', 'ə')
			tone = ipa_tl_ts] or ""

		elseif curr_tone_cat == '3' then
			if p and match(p, "#") then next_tone_cat = "#3" end
			if i == tone_cat.length then
				if i == 1 then tone = '²¹⁴' else tone = '²¹⁴⁻²¹⁽⁴⁾' end
			else
				tone = ipa_third_t_ts
			end

		elseif curr_tone_cat == '4' and next_tone_cat == '4' then
			tone = '⁵¹⁻⁵³'

		elseif curr_tone_cat == '4' and next_tone_cat == '1-4' then
			tone = '⁵¹⁻⁵³'

		elseif curr_tone_cat == '1-4' and next_tone_cat == '4' then
			tone = '⁵⁵⁻⁵³'

		else
			tone = ipa_t_values
		end
		p = item .. tone
		p = gsub(p, "#", "")
	end
	return table.concat(p, " ")
end

function cikart.py_number_to_mark(text)
	local priority = { "a", "o", "e", "ê", "i", "u", "ü" }
	local toneMark = {  = "̄",  = "́",  = "̌",  = "̀",  = "",  = "",  = "" }
	
	local mark = toneMark?$")]
	local toneChars = ""
	text = gsub(text, "?$", "")
	
	for _, letter in ipairs(priority) do
		text = gsub(text, letter, letter .. mark)
		if find(text, toneChars) then break end
	end
	return mw.ustring.toNFC(gsub(text, "i("..toneChars..")u", "iu%1"))
end

function cikart.py_zhuyin(text)
	local zhuyin_initial = {
		 = 'ㄅ',  = 'ㄆ',  = 'ㄇ',  = 'ㄈ', 
		 = 'ㄉ',  = 'ㄊ',  = 'ㄋ',  = 'ㄌ', 
		 = 'ㄍ',  = 'ㄎ',  = 'ㄏ', 
		 = 'ㄐ',  = 'ㄑ',  = 'ㄒ', 
		 = 'ㄗ',  = 'ㄘ',  = 'ㄙ',  = 'ㄖ', 
		 = 'ㄓ',  = 'ㄔ',  = 'ㄕ', 
		 = ''
	}

	local zhuyin_final = {
		 = 'ㄩㄢ',  = 'ㄧㄤ',  = 'ㄧㄤ',  = 'ㄨㄤ',  = 'ㄨㄤ',  = 'ㄧㄥ',  = 'ㄨㄥ',  = 'ㄩㄥ',  = 'ㄩㄥ', 
		 = 'ㄨㄞ',  = 'ㄨㄞ',  = 'ㄧㄞ',  = 'ㄧㄠ',  = 'ㄧㄠ',  = 'ㄧㄢ',  = 'ㄧㄢ',  = 'ㄨㄢ',  = 'ㄨㄢ',  = 'ㄩㄢ',  = 'ㄤ',  = 'ㄩㄝ',  = 'ㄨㄟ',  = 'ㄧㄡ',  = 'ㄧㄣ',  = 'ㄨㄣ',  = 'ㄩㄣ',  = 'ㄥ',  = 'ㄧㄥ',  = 'ㄨㄥ', 
		 = 'ㄧㄛ',  = 'ㄧㄛ',  = 'ㄧㄚ',  = 'ㄧㄚ',  = 'ㄨㄚ',  = 'ㄨㄚ',  = 'ㄞ',  = 'ㄠ',  = 'ㄢ',  = 'ㄧㄝ',  = 'ㄧㄝ',  = 'ㄨㄛ',  = 'ㄨㄛ',  = 'ㄩㄝ',  = 'ㄩㄝ',  = 'ㄟ',  = 'ㄨㄟ',  = 'ㄡ',  = 'ㄧㄡ',  = 'ㄣ',  = 'ㄧㄣ',  = 'ㄨㄣ',  = 'ㄩㄣ',  = 'ㄧ',  = 'ㄨ',  = 'ㄩ', 
		 = 'ㄚ',  = 'ㄜ',  = 'ㄛ',  = 'ㄧ',  = 'ㄨ',  = 'ㄩ',  = 'ㄝ',  = ''
	}

	local zhuyin_er = {
		 = 'ㄦ',  = ''
	}
	
	local zhuyin_tone = {
		 = '',  = 'ˊ',  = 'ˇ',  = 'ˋ',  = '˙',  = '˙'
	}
	
	if type(text) == 'table' then
		if text.args == '' then
			text = mw.title.getCurrentTitle().text
		else
			text = text.args
		end
	end
	breve_error(text)
	text = gsub(text, "#", "")
	text = cikart.py_transform(text, true)
	text = gsub(text, '()u', '%1ü')
	text = gsub(text, '(h?)i', '%1')
	text = gsub(text, '()i', '%1')
	
	local function add_tone(syllable, tone)
		if tone == '5' then
			return zhuyin_tone .. syllable
		else
			return syllable .. zhuyin_tone
		end
	end
	local function fun1(a, b) return add_tone((({ = 'ㄫ',  = 'ㄏㄇ'}) or a), b) end
	local function fun2(number) return add_tone('ㄏㄫ', number) end
	local function fun3(number) return add_tone('ㄦ', number) end
	local function fun4(a, b, c, d) return add_tone(zhuyin_initial .. zhuyin_final, d) .. zhuyin_er end
	
	local word = split(text, " ", true)
	for i, syllable in ipairs(word) do
		if find(syllable, '^$') then
			syllable = gsub(syllable, '^()()$', fun1)
		elseif find(syllable, '^hng$') then
			syllable = gsub(syllable, '^hng()$', fun2)
		elseif find(syllable, '^er$') then
			syllable = gsub(syllable, '^er()$', fun3)
		else
			syllable = gsub(syllable, '^(?h?)(????)(r?)()$', 
				fun4)
		end
		if find(syllable, '') then
			error(("Zhuyin çevirisi başarısız oldu: \"%s\". Geçerli bir Pinyin hecesi kullandığınıza emin misiniz? Metinde kısa ifade yerine vurgu ifadesi kullanıyor olabilir misiniz?"):format(syllable))
		end
		word = syllable
	end
	text = gsub(table.concat(word, " "), ' , ', ', ')
	return text
end

function cikart.zhuyin_py(text)
	local zhuyin_py_initial = {
		 = "b",  = "p",  = "m",  = "f", 
		 = "d",  = "t",  = "n",  = "l", 
		 = "g",  = "k",  = "h", 
		 = "j",  = "q",  = "x", 
		 = "zh",  = "ch",  = "sh",  = "r", 
		 = "z",  = "c",  = "s", 
		 = ""
	}

	local zhuyin_py_final = {
		 = 'a',  = 'o',  = 'e',  = 'ê',  = 'ai',  = 'ei',  = 'ao',  = 'ou',  = 'an',  = 'en',  = 'ang',  = 'eng', 
		 = 'i',  = 'ia',  = 'io',  = 'ie',  = 'iai',  = 'iao',  = 'iu',  = 'ian',  = 'in',  = 'iang',  = 'ing', 
		 = 'u',  = 'ua',  = 'uo',  = 'uai',  = 'ui',  = 'uan',  = 'un',  = 'uang',  = 'ong', 
		 = 'ü',  = 'ue',  = 'üe',  = 'üan',  = 'ün',  = 'iong', 
		 = 'er',  = 'ng',  = 'm',  = 'i'
	}

	local zhuyin_py_tone = {
		 = "\204\129",  = "\204\140",  = "\204\128",  = "",  = "\204\132"	
	}
  
	if type(text) == "table" then text = text.args end
 	local word = split(text, " ", true)
 	
 	local function process_syllable(syllable)
 		syllable = gsub(syllable, '^()(?)$', '%1ㄧ%2')
 		return gsub(syllable, '(?)(?)(?)(ㄦ?)', function(initial, final, tone, erhua)
			initial = zhuyin_py_initial
			final = zhuyin_py_final

			if erhua ~= '' then
				final = final .. 'r'
			end
			if initial == '' then
				final = final:gsub('^()(n?g?)$', function(a, b) return a:gsub('', { = 'yi',  = 'wu'}) .. b end)
				final = final:gsub('^(w?u)()$', 'ue%2')
				final = final:gsub('^iu$', 'iou')
				final = final:gsub('^()', { = 'y',  = 'w'})
				final = final:gsub('^ong', 'weng')
				final = gsub(final, '^ü', 'yu')
			end
			if initial:find('') then
				final = gsub(final, '^ü', 'u')
			end
			local tone = zhuyin_py_tone
			
			if final:find('') then
				final = final:gsub("()", "%1" .. tone)
			elseif final:find('i') then
				final = final:gsub("(i)", "%1" .. tone)
			elseif final:find('') then
				final = final:gsub("()", "%1" .. tone)
			else
				final = gsub(final, "^(?)(.)", "%1" .. "%2" .. tone)
			end

 			return initial .. final
 		end)
 	end
 	
 	for i, syllable in ipairs(word) do
 		word = process_syllable(syllable)
 	end
  return mw.ustring.toNFC(table.concat(word, " "))
end

function cikart.py_wg(text)
	local py_wg_initial = {
		 = "p",  = "pʻ", 
		 = "t",  = "tʻ", 
		 = "k",  = "kʻ", 
		 = "ch",  = "chʻ",  = "hs", 
		 = "ts",  = "tsʻ",  = "j", 
		 = "ch",  = "chʻ", 
	}
	
	local py_wg_final = {
		?)e()"] = "%1ê%2", 
		 = "ê", 
		)an$"] = "%1en", 
		 = "%1ung", 
		)e$"] = "%1eh", 
		e"] = "üeh", 
		 = "rh", 
		 = "eh", 
		 = "i", 
		 = "i", 
	}
	
	local py_wg_syl = {
		 = "%1o", 
		h?ʻ?)uo"] = "%1o",
		 = "shih",  = "jih",
		 = "tzŭ",  = "tzʻŭ",  = "ssŭ", 
		?ʻ?)ê$"] = "%1o", 
		 = "yen", 
		 = "yu",  = "i",
		 = "k%1uei"
	}
	
	if type(text) == 'table' then text = text.args end
	local text = gsub(cikart.py_transform(text, true), '', '')
	text = gsub(gsub(text, ' +', ' '), '', { = 'yi1',  = 'bu4'})
	text = gsub(text, '()u', '%1ü')
	local p = split(text, " ", true)
	
	local function process_syllable(initial, final, tone)
		for text, replace in pairs(py_wg_final) do
			final = gsub(final, text, replace)
		end
		if (initial == "zh" or initial == "ch") and final == "i" then
			final = "ih"
		end
		local untoned = (py_wg_initial or initial) .. final
		for text, replace in pairs(py_wg_syl) do
			untoned = gsub(untoned, text, replace)
		end
		return untoned .. '<sup>' .. tone .. '</sup>'
	end

	for i = 1, #p do
		p = gsub(p, '^(?h?)(.+)()$', process_syllable)
	end
	return table.concat(p, " ")
end

local function temp_bg(text, bg)
	if bg == 'y' then
		return '<' .. text .. '>'
	end
	return text
end
	
local function make_bg(text, bg)
	if bg == 'y' then
		return '<span style="background-color:#F5DEB3">' .. text .. '</span>'
	else
		return text
	end
end

function cikart.py_gwoyeu(text, original_text)
	local initials = {
		 = 'b',   = 'p',   = 'm',   = 'f', 
		 = 'd',   = 't',   = 'n',   = 'l', 
		 = 'g',   = 'k',   = 'h', 
		 = 'j',   = 'ch',   = 'sh', 
		 = 'j',  = 'ch',  = 'sh',  = 'r', 
		 = 'tz',  = 'ts',   = 's', 
		 = 'i',   = 'u', 
		 = ''
	}
	local finals = {
		 = 'a',    = 'ai',   = 'au',    = 'an',    = 'ang',    = 'e',    = 'ei',   = 'ou',   = 'en',   = 'eng',    = 'o', 
		 = 'ia',          = 'iau',   = 'ian',   = 'iang',   = 'ie',           = 'iou',   = 'in',   = 'ing',    = 'i', 
		 = 'ua',   = 'uai',          = 'uan',   = 'uang',   = 'uo',   = 'uei',          = 'uen',  = 'ong',    = 'u', 
		 = 'y',                   = 'iuan',           = 'iue',                  = 'iun',  = 'iong',   = 'iu', 
		 = 'io',
		--erhua
		 = 'al',   = 'al',   = 'aul',   = 'al',   = 'angl',   = 'el',   = 'eil',  = 'oul',  = 'el',  = 'engl',   = 'ol', 
		 = 'ial',         = 'iaul',  = 'ial',  = 'iangl',  = 'iel',          = 'ioul',  = 'iel',  = 'iengl',  = 'iel', 
		 = 'ual',  = 'ual',          = 'ual',  = 'uangl',  = 'uol',  = 'ueil',         = 'uel',  = 'ongl',   = 'ul', 
		 = 'el',                  = 'iual',           = 'iuel',                 = 'iul',  = 'iongl',  = 'iuel', 
	}
	if type(text) == 'table' then text = text.args end
	if text:find('^%s') or text:find('%s$') then error('invalid spacing') end
	local words = split(text, " ")
	local count = 0
	for i, word in ipairs(words) do
		local uppercase
		if word:find('^%u') then uppercase = true else uppercase = false end
		word = cikart.py_transform(word, true, true)
		word = gsub(word, "()", "%1 ")
		word = gsub(word, " $", "")
		word = gsub(word, '()', ' %1 ')
		word = gsub(word, ' +', ' ')
		word = gsub(word, ' $', '')
		word = gsub(word, '^ ', '')
		local syllables = split(word, " ")
		for j, syllable in ipairs(syllables) do
			count = count + 1
			if not find(syllable, '^+$') then
				local current = sub(mw.title.getCurrentTitle().text, count, count)
				if find(current, '^$') then
					local exceptions = { = 'i',  = 'chi',  = 'ba',  = 'bu'}
					syllables = exceptions
				else
					local initial, final, tone = '', '', ''
					syllable = gsub(syllable, '()u', '%1ü')
					syllable = gsub(syllable, '^(h?)i(r?)$', '%1ɨ%2')
					if mw.ustring.find(syllable, '(?h?)(??g?r?)()') then
						syllable = gsub(syllable, '(?h?)(??g?r?)()', function(a, b, c)
							initial = initials or error('Tanınmayan başlangıç:' .. a); final = finals or error('Tanınmayan bitiş:' .. b); tone = c
							return (initial .. final .. tone) end)
					elseif not find(mw.title.getCurrentTitle().text, "") then
						error('Tanınmayan hece:' .. syllable)
					end
					local original = initial..final..tone
					if initial:find('^$') then
						final = initial .. final
						initial = ''
					end
					final = gsub(final, '()%1', '%1')
					local len = len(initial) + len(final)
					local detone = initial..final
					local replace = detone
					local fullstop = false
					if tone == 5 or tone == '5' then
						fullstop = true
						if original_text then
							tone = split(cikart.py_transform(original_text, true), ' '):match('')
						else tone = 1 end
						if tone == 5 or tone == '5' then
							tone = cikart.tone_determ(m_zh.py(current))
						end
					end
					if tone == 1 or tone == '1' then
						if initial == 'l' or initial == 'm' or initial == 'n' or initial == 'r' then
							replace = initial .. 'h' .. sub(detone, 2, len)
						else
							replace = detone
						end
					elseif tone == 2 or tone == '2' then
						if not (initial == 'l' or initial == 'm' or initial == 'n' or initial == 'r') then
							if final:sub(1, 1) == 'i' or final:sub(1, 1) == 'u' then
								replace = gsub(detone, '', { = 'y',  = 'w'}, 1)
								if replace:sub(len, len) == 'y' or replace:sub(len, len) == 'w' then
									replace = gsub(replace, '$', { = 'yi',  = 'wu'})
								end
							else
								replace = gsub(detone, '(+)', '%1r')
							end
						else
							replace = detone
						end
					elseif tone == 3 or tone == '3' then
						if detone:find('^') then
							detone = detone:gsub('^', { = 'yi',  = 'wu'})
						end
						if final:find('') and not final:find('^') and not final:find('^') then
							replace = detone:gsub('', { = 'e',  = 'o'}, 1)
						else
							if final:find('') then replace = detone:gsub('', '%1%1', 1)
							else error('Tanınmayan bitiş:'..final)
							end
						end
					elseif tone == 4 or tone == '4' then
						if detone:find('^') then
							detone = detone:gsub('^', { = 'yi',  = 'wu'})
						end
						if detone:find('g?$') then
							replace = detone:gsub('g?$', { = 'y',  = 'w',  = 'll',  = 'nn',  = 'nq'})
						else
							replace = detone .. 'h'
						end
						replace = replace:gsub('yi()', 'y%1')
						replace = replace:gsub('wu()', 'w%1')
					end
					if fullstop then replace = '.' .. replace end
					syllables = syllable:gsub(original, replace)
				end
			end
		end
		words = table.concat(syllables, "")
		if uppercase then
			words = gsub(words, '^%l', mw.ustring.upper)
		end
	end
	return table.concat(words, " ")
end

-- Converts Hanyu Pinyin into Tongyong Pinyin.
function cikart.py_tongyong(text)
	if type(text) == 'table' then text = text.args end
	
	local ty_tone = {
		 = "",  = "\204\129",  = "\204\140",  = "\204\128",  = "\204\138"
	}
	
	local function num_to_mark(syllable, tone)
		tone = ty_tone
		if tone ~= "" then
			if syllable:find('') then
				syllable = syllable:gsub("()", "%1" .. tone)
			elseif syllable:find('o') then
				syllable = syllable:gsub("(o)", "%1" .. tone)
			elseif syllable:find('') then
				syllable = syllable:gsub("()", "%1" .. tone)
			end
		end
		return syllable
	end
	
	local words = {}
	for word in gsplit(text, " ") do
		local cap = word:find("^")
		word = cikart.py_transform(word, true)
		local syllables = {}
		for syllable in gsplit(word, " ") do
			syllable = syllable:gsub("(h?)i", "%1ih")
			syllable = syllable:gsub("ü", "yu")
			syllable = syllable:gsub("()u", "%1yu")
			syllable = syllable:gsub("iu", "iou")
			syllable = syllable:gsub("ui", "uei")
			syllable = syllable:gsub("()eng", "%1ong")
			syllable = syllable:gsub("wen", "wun")
			syllable = syllable:gsub("iong", "yong")
			syllable = syllable:gsub("^zh", "jh")
			syllable = syllable:gsub("^q", "c")
			syllable = syllable:gsub("^x", "s")
			syllable = #syllables ~= 0 and syllable:gsub("^()", "'%1") or syllable
			syllable = syllable:gsub("^(+)()$", num_to_mark)
			
			table.insert(syllables, syllable)
		end
		word = table.concat(syllables, "")
		word = cap and word:gsub("^.", string.upper) or word
		table.insert(words, word)
	end
	
	return mw.ustring.toNFC(table.concat(words, " "))
end

function cikart.py_format(text, cap, bg, simple, nolink)
	if cap == false then cap = nil end
	if bg == false then bg = 'n' else bg = 'y' end
	if simple == false then simple = nil end
	if nolink == false then nolink = nil end
	text = mw.ustring.toNFD(text)
	local phon = text
	local title = mw.title.getCurrentTitle().text
	local cat = ''
	local spaced = mw.ustring.toNFD(cikart.py_transform(text))
	local space_count
	spaced, space_count = gsub(spaced, ' ', '@')
	local consec_third_count
	
	for _ = 1, space_count do
		spaced, consec_third_count = gsub(spaced, "(+)̌(*)@(+̌)", function(a, b, c)
			return temp_bg(a..'́'..b, bg)..'@'..c end, 1)
		if consec_third_count > 0 then
			phon = gsub(spaced, '@', '')
		end
	end
	text = gsub(text, "#", "")
	phon = gsub(phon, "#", "")
	
	if title:find('一') and not text:find('一') and not simple then
		cat = cat .. ']'
	end
	
	if text:find('') and not simple then
		text = gsub(text, '$', { = 'yī',  = 'bù'})
		phon = gsub(phon, '$', { = 'yī',  = 'bù'})
		
		if find(text, '一') then
			if find(text, '一*') then
				cat = cat .. ']'
				phon = gsub(phon, '一(*)', function(a) return temp_bg('yì', bg) .. a end)
				text = gsub(text, '一(*)', 'yī%1')
			end
			if find(text, '一*̀') or find(text, '一ge$') or find(text, '一ge') then
				cat = cat .. ']'
				phon = gsub(phon, '一(*̀)', function(a) return temp_bg('yí', bg) .. a end)
				phon = gsub(phon, '一ge', temp_bg('yí', bg) .. 'ge')
				text = gsub(text, '一(*)', 'yī%1')
			end
		end
		if find(text, '不 ??h?*̀') then
			cat = cat .. ']'
			phon = gsub(phon, '不( ??h?*̀)', function(a) return temp_bg('bú', bg) .. a end)
		end
	end
	text = gsub(text, '', { = 'yī',  = 'bù'})
	text = gsub(text, '兒', function() return make_bg('r', bg) end) -- character is deleted
	phon = gsub(phon, '<(+)>', '<span style="background-color:#F5DEB3">%1</span>')
	
	if not simple then
		if cap then
			text = gsub(text, '^%l', string.upper)
			phon = gsub(phon, '^%l', string.upper)
		end
		if not nolink then
			text = ']'
		end
		if '', { = 'yī',  = 'bù'}) .. ']]' ~= text then
			phon = gsub(phon, '', { = 'yī',  = 'bù'})
			text = text .. ' '
		end
		if mw.title.getCurrentTitle().nsText ~= 'Şablon' and not nolink then
			text = text .. cat
		end
	end
	return mw.ustring.toNFC(text)
end

function cikart.make_tl(original_text, tl_pos, bg, cap)
	if bg == false then bg = 'n' else bg = 'y' end
	local _, countoriginal = gsub(original_text, " ", " ")
	local spaced = cikart.py_transform(original_text)
	if sub(spaced, -1, -1) == ' ' then spaced = sub(spaced, 1, -2) end
	local _, count = gsub(spaced, " ", " ")
	local index = {}
	local start, finish
	local pos = 1
	for i = 1, count, 1 do
		if i ~= 1 then pos = (index + 1) end
		index = mw.ustring.find(spaced, ' ', pos)
	end
	if tl_pos == 2 then
		start = index - count + countoriginal + 2
		finish = index - count + countoriginal
	elseif tl_pos == 3 then
		start = index - count + countoriginal + 3
		finish = index - count + countoriginal + 1
	else
		start = count == 0 and 1 or (index - count + countoriginal + 1)
		finish = -1
	end
	local text = (sub(original_text, 1, start-1) .. make_bg(gsub(sub(original_text, start, finish), '.', py_detone), bg))
	if finish ~= -1 then text = (text .. sub(original_text, finish+1, -1)) end
	if cap == true then text = gsub(text, '^%l', string.upper) end
	return text
end

function cikart.tag(first, second, third, fourth, fifth)
	local text = "(''"
	local tag = {}
	local tagg = first or "Standart Çince"
	tag = (second ~= '') and second or "Standart Çince"
	tag = (third ~= '') and third or nil
	tag = (fourth ~= '') and fourth or nil
	tag = (fifth ~= '') and fifth or nil
	text = text .. ((tagg == '') and table.concat(tag, ", ") or tagg) .. "'')"
	text = gsub(text, 'Standart Çince', "]")
	text = gsub(text, 'Çin anakarası', "]")
	text = gsub(text, 'Tayvan', "]")
	text = gsub(text, 'Pekin', "]")
	text = gsub(text, 'erhua', "]")
	text = gsub(text, 'Min Nan dili', "]")
	text = gsub(text, 'shangkouzi', "'']''")
	return text
end

function cikart.straitdiff(text, pron_ind, tag)
	local conv_text = text
	for i = 1, #text do
		if m_zh_data().MT then conv_text = 'y' end
	end
	if tag == 'tag' then
		conv_text = (conv_text == 'y') and m_zh_data().MT_tag')] or ''
	elseif pron_ind == 1 or pron_ind == 2 or pron_ind == 3 or pron_ind == 4 or pron_ind == 5 then
		local reading = {}
		for a, b in pairs(m_zh_data().MT) do
			reading = b
			if reading then reading = gsub(reading, "^()", "'%1") end
		end
		conv_text = gsub(text, '.', reading)
		text = gsub(text, "^'", "")
		text = gsub(text, " '", " ")
		if conv_text == text and tag == 'exist' then return nil end
	end
	conv_text = gsub(conv_text, "^'", "")
	return conv_text
end

function cikart.diz_analiz(text, conv_type, other_m_vars)
	if type(text) == 'table' then text, conv_type = text.args, (text.args or "") end
	local MT = m_zh_data().MT
	
	text = gsub(text, '=', '—')
	text = gsub(text, ',', '隔')
	text = gsub(text, '隔 ', ', ')
	if conv_type == 'baş' or conv_type == 'bağ' then
		if find(text, '隔cap—') then
			text = gsub(text, '', { = 'Yī',  = 'Bù'})
		end
		text = gsub(text, '', { = 'yī',  = 'bù'})
	end
	local comp = split(text, '隔', true)
	local reading = {}
	local alternative_reading = {}
	local zhuyin = {}
	--[[
	-- not used
	local param = {
		'1n', '1na', '1nb', '1nc', '1nd', 'py', 'cap', 'tl', 'tl2', 'tl3', 'a', 'audio', 'er', 'ertl', 'ertl2', 'ertl3', 'era', 'eraudio',
		'2n', '2na', '2nb', '2nc', '2nd', '2py', '2cap', '2tl', '2tl2', '2tl3', '2a', '2audio', '2er', '2ertl', '2ertl2', '2ertl3', '2era', '2eraudio',
		'3n', '3na', '3nb', '3nc', '3nd', '3py', '3cap', '3tl', '3tl2', '3tl3', '3a', '3audio', '3er', '3ertl', '3ertl2', '3ertl3', '3era', '3eraudio',
		'4n', '4na', '4nb', '4nc', '4nd', '4py', '4cap', '4tl', '4tl2', '4tl3', '4a', '4audio', '4er', '4ertl', '4ertl2', '4ertl3', '4era', '4eraudio',
		'5n', '5na', '5nb', '5nc', '5nd', '5py', '5cap', '5tl', '5tl2', '5tl3', '5a', '5audio', '5er', '5ertl', '5ertl2', '5ertl3', '5era', '5eraudio'
	}
	--]]
	
	if conv_type == '' then
		return comp
	elseif conv_type == 'baş' or conv_type == 'bağ' then
		for i, item in ipairs(comp) do
			if not find(item, '—') then
				if find(item, '') then
					local M, T, t = {}, {}, {}
					for a, b in pairs(MT) do
						M = b; T = b; t = b;
						M = gsub(M, "^()", "'%1")
						T = gsub(T, "^()", "'%1")
						if t then t = gsub(t, "^()", "'%1") end
					end
					local mandarin = gsub(item, '.', M)
					local taiwan = gsub(item, '.', T)
					mandarin = gsub(mandarin, "^'", "")
					mandarin = gsub(mandarin, " '", " ")
					if conv_type == 'bağ' then return mandarin end
					taiwan = gsub(taiwan, "^'", "")
					taiwan = gsub(taiwan, " '", " ")
					local tt = gsub(item, '.', t)
					if find(text, 'cap—') then
						mandarin = gsub(mandarin, '^%l', mw.ustring.upper)
						taiwan = gsub(taiwan, '^%l', mw.ustring.upper)
						tt = gsub(tt, '^%l', mw.ustring.upper)
					end
					if tt == item then
						zhuyin = cikart.py_zhuyin(mandarin, true) .. ', ' .. cikart.py_zhuyin(taiwan, true)
						reading = mandarin .. ']], [[' .. taiwan
					else
						tt = gsub(tt, "^'", "")
						tt = gsub(tt, " '", " ")
						zhuyin = cikart.py_zhuyin(mandarin, true) .. ', ' .. cikart.py_zhuyin(taiwan, true) .. ', ' .. cikart.py_zhuyin(tt, true)
						reading = mandarin .. ']], ], [[' .. tt
					end
				else
					if conv_type == 'bağ' then return item end
					zhuyin = cikart.py_zhuyin(item, true)
					reading = item
					if len(mw.title.getCurrentTitle().text) == 1 and #mw.text.split(cikart.py_transform(item), " ") == 1 then
						alternative_reading = ") .. "|" .. mw.ustring.gsub(cikart.py_transf(reading), '()', '<sup>%1</sup>') .. "]]"
					end
				end
				if reading ~= '' then reading = ' .. ']]' end
				reading = gsub(reading, "#", "")
			end
			comp = item
			if conv_type == 'bağ' then return comp end
		end
		local id = m_zh.ts_determ(mw.title.getCurrentTitle().text)
		local accel
		if id == 'geleneksel' then
			accel = '<span class="form-of pinyin-t-form-of transliteration-' .. m_zh.ts(mw.title.getCurrentTitle().text)
		elseif id == 'basit' then
			accel = '<span class="form-of pinyin-s-form-of transliteration-' .. m_zh.st(mw.title.getCurrentTitle().text)
		elseif id == 'ikisi' then
			accel = '<span class="form-of pinyin-ts-form-of'
		end
		accel = accel .. '" lang="cmn" style="font-family: Consolas, monospace;">'
		local result = other_m_vars and "*: <small>('']'')</small>\n*::" or "*:"
		result = result .. "<small>('']'')</small>: " .. accel .. gsub(table.concat(reading, ", "), ", ,", ",")
		if alternative_reading then
			result = result .. " (" .. table.concat(alternative_reading, ", ") .. ")"
		end
		result = result .. (other_m_vars and "</span>\n*::" or "</span>\n*:")
		result = result .. "<small>('']'')</small>: " .. '<span lang="zh-Bopo" class="Bopo">' .. gsub(table.concat(zhuyin, ", "), ", ,", ",") .. "</span>"
		return result

	elseif conv_type == '2' or conv_type == '3' or conv_type == '4' or conv_type == '5' then
		if not find(text, '隔') or (comp and find(comp, '—')) then
			return ''
		else
			return comp
		end
	else
		for i = 1, #comp, 1 do
			local target = '^' .. conv_type .. '—'
			if find(comp, target) then
				text = gsub(comp, target, '')
				return text
			end
		end
		text = ''
	end
	return text
end

function cikart.homophones(pinyin)
	local text = ''
	if mw.title.getCurrentTitle().nsText == '' then
		local args = hom_data.list
		text = '<div style="visibility:hidden; float:left"><sup><span style="color:#FFF">düzenle</span></sup></div>'
		for i, term in ipairs(args) do
			if i > 1 then
				text = text .. "<br>"
			end
			if mw.title.new(term).exists and term ~= mw.title.getCurrentTitle().text then
				local forms = { term }
				local content = mw.title.new(term):getContent()
				local template = match(content, "{{zh%-biçimler*}}")
				if template then
					local simp = match(template, "|s=()+")
					if simp then
						table.insert(forms, simp)
					end
					for tradVar in mw.ustring.gmatch(template, "|t=()+") do
						table.insert(forms, tradVar)
					end
					for simpVar in mw.ustring.gmatch(template, "|s=()+") do
						table.insert(forms, simpVar)
					end
					term = table.concat(forms, "/")
				end
			end
			text = text .. mw.getCurrentFrame():expandTemplate{ title = "Şablon:zh-b", args = { term, tr = "-" } }
		end
		text = text .. ']'
	end
	return text
end

local function erhua(word, erhua_pos, pagename)
	local title = split(pagename, '')
	local linked_title = ''
	local syllables = split(cikart.py_transform(word), ' ')
	local count = #syllables
	erhua_pos = find(erhua_pos, '') and split(erhua_pos, ';') or { count }
	for _, pos in ipairs(erhua_pos) do
		pos = tonumber(pos)
		title = title .. '兒'
		syllables = syllables .. 'r'
	end
	local title = table.concat(title)
	if mw.title.new(title).exists then
		linked_title = ' (' .. m_zh.link(nil, nil, {title, tr='-'}) .. ')'
	end
	for i, syllable in pairs(syllables) do
		if i ~= 1 and mw.ustring.toNFD(syllable):find('^') then
			syllables = "'" .. syllable
		end
	end
	word = table.concat(syllables, '')
	return (cikart.tag('', '', 'erhua-ed') .. linked_title), word
end

cikart.erhua = erhua

function cikart.make(frame)
	local args = frame:getParent().args
	return cikart.yap_args(args)
end

function cikart.yap_args(args)
	local pagename = mw.title.getCurrentTitle().text
	local text = {}
	local reading = {args or '', args or '', args or '', args or '', args or ''}
	args = ine(args)
	if reading ~= '' then
		local title = cikart.tag((args or ''), (args or ''), (args or cikart.straitdiff(args, 1, 'tag')), (args or ''), (args or ''))
		local pinyin = cikart.straitdiff(reading, 1, '')
		table.insert(text, cikart.make_table(title, pinyin, (args or ''), (args or ''), (args or ''), (args or ''), (args or ''), (args or args or '')))
		
		if args and args ~= '' then
			title, pinyin = erhua(pinyin, args, pagename)
			table.insert(text, cikart.make_table(title, pinyin, '', (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true))
		end
	end
	
	if reading ~= '' or cikart.straitdiff(reading, 2, 'exist') then
		if args and args ~= '' then tagb = args else tagb = cikart.straitdiff(args, 2, 'tag') end
		title = cikart.tag((args or ''), (args or ''), tagb, (args or ''), (args or ''))
		pinyin = (reading ~= '') and reading or cikart.straitdiff(reading, 2, '')
		table.insert(text, cikart.make_table(title, pinyin, (args or ''), (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true))
		table.insert(text, ', 1, '') or args) .. ']]')
		
		if args and args ~= '' then
			title, pinyin = erhua(pinyin, args, pagename)
			table.insert(text, cikart.make_table(title, pinyin, '', (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true))
		end
		
		if reading ~= '' or cikart.straitdiff(reading, 3, 'exist') then
			if args and args ~= '' then tagb = args else tagb = cikart.straitdiff(args, 3, 'tag') end
			title = cikart.tag((args or ''), (args or ''), tagb, (args or ''), (args or ''))
			if reading ~= '' then pinyin = reading else pinyin = cikart.straitdiff(reading, 3, '') end
			table.insert(text, cikart.make_table(title, pinyin, (args or ''), (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true))
			
			if args and args ~= '' then
				title, pinyin = erhua(pinyin, args, pagename)
				table.insert(text, cikart.make_table(title, pinyin, '', (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true))
			end
			
			if reading ~= '' or cikart.straitdiff(reading, 4, 'exist') then
				if args and args ~= '' then tagb = args else tagb = cikart.straitdiff(args, 4, 'tag') end
				title = cikart.tag((args or ''), (args or ''), tagb, (args or ''), (args or ''))
				if reading ~= '' then pinyin = reading else pinyin = cikart.straitdiff(reading, 4, '') end
				table.insert(text, cikart.make_table(title, pinyin, (args or ''), (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true))
			
				if args and args ~= '' then
					title, pinyin = erhua(pinyin, args, pagename)
					table.insert(text, cikart.make_table(title, pinyin, '', (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true))
				end
				if reading ~= '' or cikart.straitdiff(reading, 5, 'exist') then
					if args and args ~= '' then tagb = args else tagb = cikart.straitdiff(args, 5, 'tag') end
					title = cikart.tag((args or ''), (args or ''), tagb, (args or ''), (args or ''))
					if reading ~= '' then pinyin = reading else pinyin = cikart.straitdiff(reading, 5, '') end
					table.insert(text, cikart.make_table(title, pinyin, (args or ''), (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true))
				
					if args and args ~= '' then
						title, pinyin = erhua(pinyin, args, pagename)
						table.insert(text, cikart.make_table(title, pinyin, '', (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true))
					end
				end
			end
		end
	end
	if (args or '') .. (args or '') .. (args or '') .. (args or '') .. (args or '') .. (args or '') ~= '' then
		table.insert(text, ', 1, '') .. ']]')
	end
	return table.concat(text)
end

function cikart.yap_ses(args)
	local text, reading, pinyin = {}, {}, ""
	local audio = {
		args or args or '',
		args or args or '',
		args or args or '',
		args or args or '',
		args or args or '',
	}
	for i=1,5 do
		reading = args or ''
		if i == 1 then
			pinyin = cikart.straitdiff(reading, 1, '')
		else
			pinyin = (reading ~= '') and reading or cikart.straitdiff(reading, i, '')
		end
		pinyin = cikart.py_format(pinyin, false, false, true)
		add_audio(text, audio, pinyin)
	end
	return table.concat(text)
end

function add_audio(text, audio, pinyin)
	if audio and audio ~= "" then
		if audio == "e" then audio = string.format('zh-%s.ogg', pinyin) end
		table.insert(text, '\n*:: [[Dosya:')
		table.insert(text, audio)
		table.insert(text, ']]')
		table.insert(text, ']')
	end
end

function cikart.make_table(title, pinyin, py, cap, tl, tl2, tl3, a, novariety)
	py = ine(py);cap = ine(cap);tl = ine(tl);tl2 = ine(tl2);tl3 = ine(tl3);a = ine(a);novariety = ine(novariety)
	local text = {}
	
	local pinyin_simple_fmt = cikart.py_format(pinyin, false, false, true)
	local pinyin_simple_fmt_nolink = cikart.py_format(pinyin, false, false, true, true)
	
	if not novariety then
		table.insert(text, '* ]')
	else
		table.insert(text, '<br>')
	end
	table.insert(text, '\n** <small>' .. title .. '</small>')
	local hom_found
	if hom_data.list then
		hom_found = true
	else
		hom_found = false
		table.insert(text, '<sup><small><abbr title="Mandarin dili eşseslisi ekle"><span class="plainlinks">="edit"})) .. ' +]</span></abbr></small></sup>')
	end
	table.insert(text, "\n*** <small>'']''</small>: ")
	local id = m_zh.ts_determ(mw.title.getCurrentTitle().text)
	if id == 'geleneksel' then
		table.insert(text, '<span class="form-of pinyin-t-form-of transliteration-')
		table.insert(text, m_zh.ts(mw.title.getCurrentTitle().text))
	elseif id == 'basit' then
		table.insert(text, '<span class="form-of pinyin-s-form-of transliteration-')
		table.insert(text, m_zh.st(mw.title.getCurrentTitle().text))
	else -- both
		table.insert(text, '<span class="form-of pinyin-ts-form-of')
	end
	table.insert(text, '" lang="cmn" style="font-family: Consolas, monospace;">')
	if py then
		table.insert(text, py)
	else
		if cap then
			table.insert(text, cikart.py_format(pinyin, true, true))
		else
			table.insert(text, cikart.py_format(pinyin, false, true))
		end
		if tl or tl2 or tl3 then
			table.insert(text, ' → ')
			if tl then tl_pos = 1 elseif tl2 then tl_pos = 2 elseif tl3 then tl_pos = 3 end
			if cap then
				table.insert(text, cikart.make_tl(cikart.py_format(pinyin, true, false, true, true), tl_pos, true, true))
			else
				table.insert(text, cikart.make_tl(pinyin_simple_fmt_nolink, tl_pos, true))
			end
		end
		if tl then table.insert(text, ' <small>(vurgusuz bitiş hece çeşiti)</small>')
			elseif tl2 or tl3 then table.insert(text, ' <small>(vurgusuz çeşit)</small>') end
	end
	table.insert(text, "</span>\n*** <small>'']''</small>: ")
	table.insert(text, '<span lang="zh-Bopo" class="Bopo">')
	table.insert(text, cikart.py_zhuyin(pinyin_simple_fmt, true))
	if tl or tl2 or tl3 then
		table.insert(text, ' → ')
		table.insert(text, cikart.py_zhuyin(cikart.make_tl(pinyin_simple_fmt_nolink, tl_pos, false), true))
	end
	table.insert(text, '</span>')
	if tl then table.insert(text, ' <small>(vurgusuz bitiş hece çeşiti)</small>')
		elseif tl2 or tl3 then table.insert(text, ' <small>(vurgusuz çeşit)</small>') end
	if len(mw.title.getCurrentTitle().text) == 1 then
		table.insert(text, "\n*** <small>'']''</small>: <code>")
		table.insert(text, cikart.py_wg(pinyin_simple_fmt))
		table.insert(text, '</code>')
	end
	table.insert(text, "\n*** <small>'']''</small>: <code>")
	if tl or tl2 or tl3 then
		table.insert(text, cikart.py_gwoyeu(cikart.make_tl(pinyin_simple_fmt_nolink, tl_pos, false), pinyin_simple_fmt))
	else
		table.insert(text, cikart.py_gwoyeu(pinyin_simple_fmt))
	end
	table.insert(text, '</code>')
	table.insert(text, "\n*** <small>'']''</small>: <code>")
	if tl or tl2 or tl3 then
		table.insert(text, cikart.py_tongyong(cikart.make_tl(pinyin_simple_fmt_nolink, tl_pos, false), pinyin_simple_fmt))
	else
		table.insert(text, cikart.py_tongyong(pinyin_simple_fmt))
	end
	table.insert(text, '</code>')
	table.insert(text, '\n*** <small>Sinolojik ] <sup>(])</sup></small>: <span class="IPA">/')
	table.insert(text, cikart.py_ipa(pinyin))
	if tl or tl2 or tl3 then
		table.insert(text, '/ → /')
		table.insert(text, cikart.py_ipa(cikart.make_tl(pinyin_simple_fmt_nolink, tl_pos, false)))
	end
	table.insert(text, '/</span>')
	-- if a then
	-- 	if a == 'y' then a = 'zh-' .. pinyin_simple_fmt .. '.ogg' end
	-- 	table.insert(text, '\n*** <div style="display:inline-block; position:relative; top:0.5em;">[[File:')
	-- 	table.insert(text, a)
	-- 	table.insert(text, ']]</div>]')
	-- end
	if hom_found then
		table.insert(text, "\n*** <small>Eşsesliler</small>: " ..
			'<table class="wikitable" style="width:15em;margin:0; position:left; text-align:center">' ..
			'<tr><th class="mw-customtoggle-cmnhom" style="color:#3366bb"></th></tr>' ..
			'<tr class="mw-collapsible mw-collapsed" id="mw-customcollapsible-cmnhom">' ..
			'<td><sup><div style="float: right; clear: right;"><span class="plainlinks">[')
		table.insert(text, tostring(mw.uri.fullUrl("Modül:zh/veri/cmn-eşs", {="edit"})))
		table.insert(text, ' düzenle]</span></div></sup>')
		table.insert(text, cikart.homophones(mw.ustring.lower(pinyin_simple_fmt)))
		table.insert(text, '</td></tr></table>')
	end
	return table.concat(text)
end

return cikart