local export = {}
local mn = require("Module:mn-common")
local gsub = mw.ustring.gsub
local u = require("Module:string/char")
local vowels1 = {
= 'a', = 'ɔ', = 'ʊ',
= 'e', = 'ɵ', = 'u',
= 'i', = 'i', = 'i', --й very occasionally used at the start of loanwords
= 'ja', = 'jʊ', = 'jɔ', = 'jɵ',
= '', = 'ə',
}
local vowels2 = {
= 'aː', = 'ɛː', = 'jaː', = 'jɛː', = 'ja', = 'ɒː', = 'aʊ̯', = 'jaʊ̯',
= 'oː', = 'ɔi̯', = 'jɔː', = 'jɔi̯', = 'jɔ', = 'ʊ̯a', = 'joʊ',
= 'ʊː', = 'ʊi̯', = 'u̯a', = 'jʊː', = 'jʊi̯', = 'u̯iː',
= 'eː', = 'ei̯', = 'jeː', = 'jei̯', = 'ia', = 'eɔ', = 'iʊ̯', = 'iuː',
= 'ɵː', = 'ɵi̯', = 'jɵ',
= 'uː', = 'ui̯', = 'juː', = 'jui̯',
= 'iː', = 'iː', = 'i̯aː', = 'i̯oː', = 'i̯ʊː', = 'i̯eː', = 'i̯ɵː', = 'i̯uː',
}
local vowels3 = {
= 'jaː', = 'jɔː', = 'jeː',
= 'jɛː', = 'u̯ɛː', = 'jiː',
= 'aʊ̯a',
}
local consonants1 = {
= 'pʰ', = 'p', = 'tʰ', = 't', = 'kʰ', = 'k',
= 't͡sʰ', = 't͡s', = 't͡ɕʰ', = 't͡ɕ',
= 'f', = 'w̜', = 's', = 'ɕ', = 'ɕ', = 'x',
= 'm', = 'n',
= 'r', = 'ɮ',
= 'ʲ',
}
local consonants2 = {
= 'b',
= 'b',
= 't͉.t',
= 'ɮː', = 'ɬʰ',
= 'mː',
= 'mp', = 'nː',
= 'r̥kʰ', = 'r̥pʰ', = 'r̥tʰ', = 'r̥t͡sʰ', = 'r̥t͡ɕʰ',
= 'sː',
}
local double_consonants = {
= 'п', = 'т', = 'к', = 'г',
= 'ц', = 'з', = 'ч', = 'ж',
= 'ф', = 'в', = 'ш', = 'щ', = 'х',
= 'р',
}
local palatalisation = {
= 'пʲө', = 'пʲу', = 'пʲо', = 'пʲа',
= 'бʲө', = 'бʲу', = 'бʲо', = 'бʲа',
= 'тʲө', = 'тʲу', = 'тʲо', = 'тʲа',
= 'дʲө', = 'дʲу', = 'дʲо', = 'дʲа',
= 'кʲө', = 'кʲу', = 'кʲо', = 'кʲа',
= 'гʲө', = 'гʲу', = 'гʲо', = 'гʲа',
= 'фʲө', = 'фʲу', = 'фʲо', = 'фʲа',
= 'вʲө', = 'вʲу', = 'вʲо', = 'вʲа',
= 'хʲө', = 'хʲу', = 'хʲо', = 'хʲа',
= 'мʲө', = 'мʲу', = 'мʲо', = 'мʲа',
= 'нʲө', = 'нʲу', = 'нʲо', = 'нʲа',
= 'рʲө', = 'рʲу', = 'рʲо', = 'рʲа',
= 'лʲө', = 'лʲу', = 'лʲо', = 'лʲа',
}
function export.to_IPA(text)
local orig_text = text
text = mw.ustring.lower(text)
text = gsub(text, '-', '')
text = gsub(text, "ы$", "ы~")
text = gsub(text, "ы(%s)", "ы~%1")
--primary stress
-- U+0301 COMBINING ACUTE ACCENT, U+02C8 MODIFIER LETTER VERTICAL LINE
--secondary stress
-- U+0300 COMBINING GRAVE ACCENT, U+02C8 MODIFIER LETTER LOW VERTICAL LINE
text = gsub(text, "'", u(0x02C8)) -- can use apostrophe for convenience
if not mw.ustring.match(text, u(0x02C8)) then
if not mw.ustring.match(text, '') then
text = u(0x02C8) .. text
end
text = gsub(text, '()()'..u(0x0301), '%1'..u(0x02C8)..'%2')
text = gsub(text, '(%*?)()'..u(0x0301), u(0x02C8)..'%1%2')
text = gsub(text, '()()'..u(0x0300), '%1'..u(0x02CC)..'%2')
text = gsub(text, '(%*?)()'..u(0x0300), u(0x02CC)..'%1%2')
end
for k, v in pairs(double_consonants) do
text = gsub(text, k, v)
text = gsub(text, k, v) --remove double consonants
end
for k, v in pairs(palatalisation) do
text = gsub(text, k, v)
text = gsub(text, k, v) --convert iotated vowels following consonants
end
for k, v in pairs(vowels3) do
text = gsub(text, k, v)
text = gsub(text, k, v)
text = gsub(text, k, v)
end
for k, v in pairs(vowels2) do
text = gsub(text, k, v)
text = gsub(text, k, v)
end
for k, v in pairs(vowels1) do
text = gsub(text, k, v)
end
for k, v in pairs(consonants2) do
text = gsub(text, k, v)
text = gsub(text, k, v)
end
text = gsub(text, '%*?', consonants1)
text = gsub(text, '()t͡ɕ()', '%1d͡ʑ%2')
text = gsub(text, '()p()', '%1β%2')
text = gsub(text, '()k()', '%1ɣ%2')
text = gsub(text, 'n(*)%f', 'm%1')
text = gsub(text, 'n%f', 'ŋ')
text = gsub(text, 'r%f', 'r̥')
text = gsub(text, '()i%f', '%1ⁱ')
if #mn.syllables( orig_text ) ~= 1 then
text = gsub(text, '%f', '')
end
text = gsub(text, 'ⁱ', 'i')
text = gsub(text, 'ʲj', 'j')
--put ~ at the end of respelling to prevent vowel cutoff
text = gsub(text, '~', '')
return text
end
-- only works with Cyrillic Mongolian
function export.show(frame)
local args = frame:getParent().args
local page_title = mw.title.getCurrentTitle().text
local text = args or page_title
local qualifier = args or nil
local lang = require("Module:languages").getByCode("mn")
local script = require("Module:scripts").getByCode("Cyrl")
local syllables = mn.syllables(text)
local transcription = export.to_IPA(text)
local IPA = "<li>" .. (qualifier and require("Module:qualifier").format_qualifier{qualifier} .. " " or "") ..
require("Module:IPA").format_IPA_full {
lang = lang,
items = {{ pron = "/" .. transcription .. "/" }},
} .. "</li>"
local hyphenation = "<li>" .. require("Module:hyphenation").format_hyphenations {
lang = lang,
hyphs = { { hyph = syllables } },
sc = script,
caption = "]",
} .. mw.ustring.char( 0x2002 ) .. "(" .. #syllables .. " syllable"
if #syllables >= 2 then hyphenation = hyphenation .. "s" end
hyphenation = hyphenation .. ")</li>"
return "<ul>" .. IPA .. hyphenation .. "</ul>"
end
return export