Module:xkz-IPA
Appearance
- This module lacks a documentation subpage. Please create it.
- Useful links: subpage list • links • transclusions • testcases • sandbox
local find = mw.ustring.find
local rsub = mw.ustring.gsub
local m_a = require("Module:accent qualifier")
local u = require("Module:string/char")
local export = {}
local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("xkz")
local function format_accent(qual)
return m_a.format_qualifiers(lang, {qual})
end
local function phonetic(text, col)
text = rsub(text, "([öüáéíóú́])([bdgsmnrl]g?)a", "%1%2")
text = rsub(text, "([aiuoáíúó])'([ui])", "%1%2")
text = rsub(text, "%-'([ui])", "-%1")
text = rsub(text, "thr", "trh")
text = rsub(text, "%.%'", ".")
text = rsub(text, "ā́", "áː")
text = rsub(text, "ḗ", "éː")
text = rsub(text, "ī́", "íː")
text = rsub(text, "ṓ", "óː")
text = rsub(text, "ū́", "úː")
text = rsub(text, "ā", "aː")
text = rsub(text, "ē", "eː")
text = rsub(text, "ī", "iː")
text = rsub(text, "ō", "oː")
text = rsub(text, "ū", "uː")
text = rsub(text, "%'([aeiouöü])", "X%1")
text = rsub(text, "^([aeiouöü])", "'%1")
text = rsub(text, " ([aeiouöü])", " '%1")
text = rsub(text, "X", "!")
text = rsub(text, "^", "H")
text = rsub(text, " ", " H")
text = rsub(text, "H(t?[ptcksh]r?[sh]?[rylw]?)([aeiouöü])", "%1'%2")
text = rsub(text, "H([bdjgz][zhr]?[rylw]?)([aeiouöü])", "%1!%2")
text = rsub(text, "Hlh([aeiou])", "lh'%1")
text = rsub(text, "H([mnrlyw][ygr]?)([áéíóúöü])", "%1'%2")
text = rsub(text, "H([mnrlyw][ygr]?)([aeiouöü])", "%1!%2")
text = rsub(text, "á", "a")
text = rsub(text, "é", "e")
text = rsub(text, "í", "i")
text = rsub(text, "ó", "o")
text = rsub(text, "ú", "u")
text = rsub(text, "([ai])u", "%1u̯")
text = rsub(text, "([uo])i", "%1i̯")
text = rsub(text, "%!([aeiouöü])", "%1G")
text = rsub(text, "%'([aeiouöü])", "%1A")
text = rsub(text, "a", "ɐ")
text = rsub(text, "ng", "ŋ")
text = rsub(text, "lh", "l̥")
text = rsub(text, "ny", "ɲ")
text = rsub(text, "tr", "ʈ")
text = rsub(text, "dr", "ɖ")
text = rsub(text, "j", "ɟ")
text = rsub(text, "y", "j")
text = rsub(text, "([ptʈck]s?)h", "%1ʰ")
text = rsub(text, "[sz]h", "ç")
text = rsub(text, "c", "c͡ɕ")
text = rsub(text, "ɟ", "ɟ͡ʑ")
text = rsub(text, "ts", "t͡s")
text = rsub(text, "ʈ", "ʈ(r)")
text = rsub(text, "ɖ", "ɖ(r)")
text = rsub(text, "pj", "(p)c")
text = rsub(text, "mj([ɐeiouöü])", "(m)ɲ%1")
text = rsub(text, "b%.", "p.")
text = rsub(text, "b ", "p ")
text = rsub(text, "b$", "p$")
text = rsub(text, "d%.", "t.")
text = rsub(text, "d ", "t ")
text = rsub(text, "d$", "t$")
text = rsub(text, "g%.", "k.")
text = rsub(text, "g ", "k ")
text = rsub(text, "g$", "k$")
text = rsub(text, "g", "ɡ")
text = rsub(text, "t", "t̪")
text = rsub(text, "d", "d̪")
text = rsub(text, "%(r%)ʰ", "ʰ(r)")
text = rsub(text, "H", "")
if col == 1 then
text = rsub(text, "ü", "u")
text = rsub(text, "ö", "o")
elseif col == 2 then
text = rsub(text, "ü([AG]?)", "u%1i̯")
text = rsub(text, "ö([AG]?)", "o%1i̯")
end
text = rsub(text, "ü([AG]?)", "y%1ː")
text = rsub(text, "ö([AG]?)", "ø%1ː")
text = rsub(text, " $", "")
text = rsub(text, "^ ", "")
text = rsub(text, "G", "̀")
text = rsub(text, "A", "́")
text = rsub(text, "^([ɐeiouøy])", "ʔ%1")
text = rsub(text, " ([ɐeiouøy])", "ʔ%1")
return text
end
function export.IPA(frame)
local words = {}
for _, word in ipairs(frame:getParent().args) do
word = rsub(word, "་", ".")
word = require("Module:Tibt-translit").tr(word, "xkz", 'Tibt')
table.insert(words, word)
local test = word
word = rsub(word, "g ", "ː ")
word = rsub(word, "g$", "ː")
word = rsub(word, "s ", "ː ")
word = rsub(word, "s$", "ː")
word = rsub(word, "nː", "ng")
if word ~= test then
table.insert(words, word)
end
end
if #words == 0 then
word = rsub(mw.title.getCurrentTitle().text, "་", ".")
word = require("Module:Tibt-translit").tr(word, "xkz", 'Tibt')
table.insert(words, word)
local test = word
word = rsub(word, "g ", "ː ")
word = rsub(word, "g$", "ː")
word = rsub(word, "s ", "ː ")
word = rsub(word, "s$", "ː")
word = rsub(word, "nː", "ng")
if word ~= test then
table.insert(words, word)
end
end
local IPA_results = {}
local IPA_col = {}
local IPA_edu = {}
for _, word in ipairs(words) do
if mw.ustring.match(word, "ü") or mw.ustring.match(word, "ö") then
table.insert(IPA_col, { pron = "[" .. phonetic(word, 1) .. "]" })
table.insert(IPA_edu, { pron = "[" .. phonetic(word, 2) .. "]" })
table.insert(IPA_edu, { pron = "[" .. phonetic(word, 3) .. "]" })
else
table.insert(IPA_results, { pron = "[" .. phonetic(word, 3) .. "]" })
end
end
if #IPA_col == 0 and #IPA_edu == 0 then
return m_IPA.format_IPA_full { lang = lang, items = IPA_results }
else
return "*" .. format_accent("colloquial") .. " " .. m_IPA.format_IPA_full { lang = lang, items = IPA_col } .. "\n*" ..
format_accent("educated") .. " " .. m_IPA.format_IPA_full { lang = lang, items = IPA_edu }
end
end
return export