跳去內容

模組:Yue-rom-test

來自維基辭典

呢個模組嘅解說可以喺模組:Yue-rom-test/doc度開

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

-- jp = Jyutping
-- nf = New-French Latinisation

local cantonese_tone_values = { '55', '15', '33', '11', '13', '22' }
local super_numbers = { '¹', '²', '³', '⁴', '⁵', '⁶' }
-- local city_names = { '廣州', '香港', '佛山', '台山', '江門', '珠海', '韶關', '肇慶', '惠州龍門', '寶安', '東莞', '圍頭', '陽江', '茂名', '湛江市區', '雲浮', '梧州', '鬱林', '北海', '南寧', '貴港', '來賓',  }

function export.index_link(frame)
	local jp = type(frame) == 'table' and frame.args[1] or frame
	local nf = export.jp_to_nf(jp)

	-- create index links
	local jp_links = replace(jp, '([^1-6 ]+)([1-6]+)', '[[:Category:粵拼索引/%1|%1%2]]')
	local nf_links = replace(nf, '([^1-6 ]+)([1-6]+)', '[[:Category:新法蘭西索引/%1|%1%2]]')

	-- convert tone numbers to superscript
	jp_links = replace(jp_links, '[1-6]', super_numbers)
	nf_links = replace(nf_links, '[1-6]', super_numbers)

	-- create category text (capture the first alphabetical part of the romanization)
	local jp_cat = '[[Category:粵拼索引/' .. match(jp, '^[^1-6 ]+') ..']]'
	local nf_cat = '[[Category:新法蘭西索引/' .. match(nf, '^[^1-6 ]+') ..']]'

	local count = frame.args.count;
	local city_name = frame.args.city
	local text = [==[* ]==] .. city_name .. [==[音]==] .. count .. [==[:
** [[wikipedia:zh-yue:新法蘭西粵語拼音方案|新法蘭西]]:<span style="font-size:150%; font-weight:bold">]==] .. nf_links .. [==[</span>
** [[wikipedia:zh-yue:粵拼|粵拼]]:<span style="font-size:150%; font-weight:bold">]==] .. jp_links .. [==[</span>]==]

	return text .. jp_cat .. nf_cat
end

function export.jp_to_nf(frame)
	local text = type(frame) == 'table' and frame.args[1] or frame

	text = replace(text, 'z', 'dz') -- IPA: /ʦ/
	text = replace(text, 'c', 'ts') -- IPA: /ʦʰ/
	text = replace(text, 'j', 'y')
	text = replace(text, 'lh', 'ł') -- IPA: /ɬ/; exists in many Cantonese dialects, but not in the Canton/HK dialect.
	text = replace(text, '([gk])w', '%1u')

	text = replace(text, 'aa', '啊') -- IPA: /a/; avoid conversion to 'ää'
	text = replace(text, 'a', 'ä') -- IPA: /ɐ/
	text = replace(text, '啊', 'a')
	text = replace(text, 'eoi', 'œ̈ü') -- IPA: /ɵy/ or /ɵi/
	text = replace(text, 'eo', 'œ̈') -- IPA: /ɵ/
	text = replace(text, 'oi', 'oü')

	text = replace(text, 'ik', 'ëk')
	text = replace(text, 'ing', 'ëng') -- IPA: /eŋ/ or /ɪŋ/
	text = replace(text, 'ei', 'ëi')
	text = replace(text, 'yu', 'ü')
	text = replace(text, 'oe', 'œ') -- IPA: /œ/
	text = replace(text, 'ou', 'öu')
	text = replace(text, 'ung', 'öng')
	text = replace(text, 'uk', 'ök')

	text = replace(text, '[1-6]', cantonese_tone_values) -- convert 1-6 to IPA tone numbers

	return text
end

return export