Module:mnc-IPA: difference between revisions

From Wiktionary, the free dictionary
Jump to navigation Jump to search
Content deleted Content added
Wyang (talk | contribs)
No edit summary
Wyang (talk | contribs)
No edit summary
Line 48: Line 48:


function export.toIPA(text, style)
function export.toIPA(text, style)
text = gsub(text, "[᠋᠌᠍]", "")
local text = transliterate(text)
local text = transliterate(text)
text = mw.ustring.lower(text)
text = mw.ustring.lower(text)

Revision as of 10:31, 20 August 2019

Manchu IPA pronunciation module. See {{mnc-IPA}}.

Testcases

Module:mnc-IPA/testcases:

1 of 0 tests failed. (refresh)

TextExpectedActualComments
test_all:
Script error during testing: bad argument #1 to 'lc' (string expected, got nil)
stack traceback:
	[C]: ?
	[C]: in function '?'
	mw.language.lua:94: in function <mw.language.lua:89>
	(tail call): ?
	Module:mnc-IPA:52: in function 'toIPA'
	Module:mnc-IPA/testcases:11: in function 'func'
	Module:UnitTests:295: in function 'iterate'
	Module:mnc-IPA/testcases:82: in function <Module:mnc-IPA/testcases:17>
	(tail call): ?
	[C]: in function 'xpcall'
	Module:UnitTests:369: in function <Module:UnitTests:328>
	(tail call): ?
	mw.lua:527: in function <mw.lua:507>
	[C]: ?
	[C]: in function 'expandTemplate'
	mw.lua:333: in function 'expandTemplate'
	Module:documentation:856: in function 'chunk'
	mw.lua:527: in function <mw.lua:507>
	[C]: ?

local export = {}

local lang = require("Module:languages").getByCode("mnc")
local sc = require("Module:scripts").getByCode("Mong")
local m_translit = require("Module:mnc-translit").tr
local m_IPA = require("Module:IPA")

local gsub = mw.ustring.gsub
local sub = mw.ustring.sub
local gmatch = mw.ustring.gmatch
local find = mw.ustring.find
local len = mw.ustring.len

local correspondences = {
	["ñ"] = "ɲ", ["y"] = "j", ["š"] = "ʃ", ["h"] = "χ",
	["d"] = "t", ["g"] = "k", ["b"] = "p", ["j"] = "t͡ʃ", 
	["t"] = "tʰ", ["k"] = "kʰ", ["p"] = "pʰ", ["c"] = "t͡ʃʰ",
	["e"] = "ə", ["o"] = "ɔ", ["ū"] = "ʊ",
}

local function transliterate(text)
	return m_translit(text, lang, "Mong")
end

local dialects = {
	[1] = { name = "peking", link = "[[w:Peking|Peking dialect]]" },
	[2] = { name = "alcuka", link = "[[w:Acheng District|Alcuka dialect]]" },
	[3] = { name = "sibe", link = "[[w:Xibe language|Sibe vernacular]]" },
	[4] = { name = "ningguta", link = "[[w:Ningguta|Ningguta dialect]]" },
	[5] = { name = "mukden", link = "[[w:Mukden|Mukden dialect]]" },
	[6] = { name = "sanjiazi", link = "[[w:Sanjiazi|Sanjiazi dialect]]" },
}

function export.link(term)
	if find(term, "[A-Za-z]") then
		term = require("Module:mnc-Latn-translit").tr(term)
	end
	return require("Module:links").full_link{ term = term, lang = lang, sc = sc }
end

local function syllabify(term)
	for i = 1, 2 do
		term = gsub(term, "([aeiouū])([^aeiouū%.]+)([aeiouū])", function(a, b, c)
			return len(b) > 1 and a .. sub(b, 1, 1) .. "." .. sub(b, 2, -1) .. c or a .. "." .. b .. c end)
	end
	return term
end

function export.toIPA(text, style)
	text = gsub(text, "[᠋᠌᠍]", "")
	local text = transliterate(text)
	text = mw.ustring.lower(text)
	text = gsub(text, "niy", "ñ")
	text = gsub(text, "uw", "w")
	text = gsub(text, "iy", "y")
	
	for original in gmatch(text, "[a-zñšū]+") do
		word = gsub(original, "ng", "ŋ")
		word = syllabify(word)
		
		word = gsub(word, ".", correspondences)
		word = gsub(word, "ɔɔ", "oː")
		word = gsub(word, "ŋ%.k", "ŋ.ŋ")
		word = gsub(word, "χi", "xi")
		word = gsub(word, "[sʃ](ʰ?)([ij])", "ɕ%1%2")
		word = gsub(word, "k(ʰ?)([aɔʊ])", "q%1%2")
		text = gsub(text, original, word, 1)
	end
	
	text = gsub(text, "%.? %.?", ".")
	text = gsub(text, "\n", "")
	return text
end

function export.make(frame)
	local args = frame:getParent().args
	local pagetitle = mw.title.getCurrentTitle().text
	
	local p, output_t = {}, {}
	local results = {
		["standard"] = {},
		["peking"] = {},
		["alcuka"] = {},
		["sibe"] = {},
		["ningguta"] = {},
		["mukden"] = {},
		["sanjiazi"] = {},
	}
	
	if args[1] then
		for index, item in ipairs(args) do
			table.insert(p, (item ~= "") and item or nil)
		end
	else
		p = { pagetitle }
	end
	
	for _, Manchu in ipairs(p) do
		table.insert(results["standard"], { pron = "[" .. export.toIPA(Manchu, "standard") .. "]" })
	end
	
	table.insert(output_t, "* (''[[w:Manchu language|standard pronunciation]]'') " .. m_IPA.format_IPA_full(lang, results["standard"]))
	
	for _, data in pairs(dialects) do
		if args[data.name] then
			for dial_pronunciation in mw.text.gsplit(args[data.name], "/") do
				table.insert(results[data.name], { pron = "[" .. dial_pronunciation .. "]" })
			end
			table.insert(output_t, "* (''" .. data.link .. "'') " .. m_IPA.format_IPA_full(lang, results[data.name]))
		end
	end
	
	return table.concat(output_t, "\n")
end

return export