Module:User:AmazingJus/so

From Wiktionary, the free dictionary
Jump to navigation Jump to search

3 of 2 tests failed. (refresh)

TextExpectedActual
test_pron:
Failedinán<F>inǽnʔɪnɑ́n<f>
Failedínan<F>ínænʔɪ́nɑn<f>
Script error during testing: Module:User:AmazingJus/so:56: Entry does not have a tone mark.
stack traceback:
	[C]: ?
	[C]: in function 'error'
	Module:User:AmazingJus/so:56: in function 'toIPA'
	Module:User:AmazingJus/so/testcases:11: in function 'func'
	Module:UnitTests:295: in function 'iterate'
	Module:User:AmazingJus/so/testcases:23: in function <Module:User:AmazingJus/so/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:894: in function 'chunk'
	mw.lua:527: in function <mw.lua:507>
	[C]: ?

local export = {}

local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("so")
local sc = require("Module:scripts").getByCode("Latn")
local hyphen = require("Module:hyphenation")
local table = require("Module:table")

function export.tag_text(text, face)
	return require("Module:script utilities").tag_text(text, lang, sc, face)
end

function export.link(term, face)
	return require("Module:links").full_link( { term = term, lang = lang, sc = sc }, face )
end

local U = mw.ustring.char
local decomp = mw.ustring.toNFD
local find = mw.ustring.find
local gsub = mw.ustring.gsub
local lower = mw.ustring.lower
local strip = mw.text.trim

local acute = U(0x301)
local grave = U(0x300)
local circumflex = U(0x302)
local semibreve = U(0x32F)
local tones = "[" .. acute .. grave .. "]"

local cons = {
	["j"] = "d͡ʒ", ["x"] = "ħ", ["kh"] = "ħ", ["sh"] = "ʃ", ["dh"] = "ɖ",
	["c"] = "ʕ", ["g"] = "ɡ", ["y"] = "j", ["'"] = "ʔ"
}

-- order of vowels: front, back
local vowels = {
	["a"] = { "æ", "ɑ" },
	["e"] = { "e", "ɛ" },
	["i"] = { "i", "ɪ" },
	["o"] = { "ɵ", "ɔ" },
	["u"] = { "ʉ", "u" }
}

function export.toIPA(term, front)
	if type(term) == "table" then
		term = term.args[1]
	end

	-- make all term lowercase and word borders have a space
	term = lower(term)
	term = " " .. term .. " "

	-- decompose tone accents where entries must have tones marked
	term = decomp(term)
	if not find(term, tones) then
		error("Entry does not have a tone mark.")
	end

	term = gsub(term, "([aeo])w([aeiou^]?)(w?)", "%1u" .. semibreve .. "%2%3")
	term = gsub(term, "([ao])y([aeiou^]?)(y?)", "%1i" .. semibreve .. "%2%3")
	term = gsub(term, "([a-z])%1(h?)", "%1%2ː")
	term = gsub(term, " ([aeiou])", " ʔ%1")

	-- assign consonant values
	term = gsub(term, "[a-z]h?", cons)

	-- assign appropriate values for vowels
	if front then
		term = gsub(term, "[aeiou]", function(vowel)
			return vowels[vowel][1]
		end)
	else
		term = gsub(term, "[aeiou]", function(vowel)
			return vowels[vowel][2]
		end)
	end

	-- grave accent is falling tone
	term = gsub(term, grave, circumflex)

	return strip(term)
end

return export