Module:User:Trimpulot/tr-IPA-test
Appearance
- This module sandbox lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • sandbox
local export = {}
local modIPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("tr")
function export.main(frame)
local phonemes = {
["c"] = "dʒ",
["ç"] = "tʃ",
["g"] = "ɡ",
["G"] = "ɟ",
["ı"] = "ɯ",
["j"] = "ʒ",
["K"] = "c",
["l"] = "ɫ",
["L"] = "l",
["ö"] = "ø",
["q"] = "(ʔ)",
["r"] = "ɾ",
["ş"] = "ʃ",
["ü"] = "y",
["y"] = "j",
["â"] = "a",
["î"] = "i",
["û"] = "u",
["'"] = "ˈ",
[":"] = "ː"
}
local voiced = {
["ç"] = "c",
["k"] = "ğ",
["p"] = "b",
["t"] = "d"
}
local IPA = {}
local function transcribe(value, isAcc, accVowel)
local s = ""
local syllables = ""
local trans = ""
if mw.ustring.match(isAcc, "%+") then
value = mw.ustring.sub(value, 1, -2) .. ":" .. mw.ustring.sub(value, -1) .. accVowel
elseif mw.ustring.match(isAcc, "%-") then
value = mw.ustring.sub(value, 1, -2) .. ":" .. voiced[mw.ustring.sub(value, -1)] .. accVowel
end
mw.log(value)
local item = mw.ustring.gsub(mw.ustring.gsub(value, "çç", "tç"), "cc", "dc") .. "SO" --SO stands for StOp bc I couldn't figure out how else to tell this thing when to stop counting syllables
repeat
if mw.ustring.match(item, "^[bcçdfgğhjklmnpqrsştvyzGKL']*[aeıioöuüâîû][:]?[bcçdfgğhjklmnprsştvyzGKL']*%s") then
s, item = mw.ustring.match(item, "^(.-%s)(.*)")
else
s, item = mw.ustring.match(item, "^([bcçdfgğhjklmnpqrsştvyzGKL']*[aeıioöuüâîû][:]?[bcçdfgğhjklmnprsştvyzGKL']-)([bcçdfgğhjklmnpqrsştvyzGKLS]?[aeıioöuüâîûO].*)$")
end
if mw.ustring.match(s, "[eiöüâîû]") then
s = mw.ustring.gsub(s, "g", "G")
s = mw.ustring.gsub(s, "ğ", "Ğ")
s = mw.ustring.gsub(s, "k", "K")
s = mw.ustring.gsub(s, "l", "L")
end
syllables = syllables .. (mw.ustring.find(syllables, "'", -1) and "" or (item == "SO" and not mw.ustring.find(syllables, "'") and "'" or "." )) .. s
until(item == "SO")
syllables = mw.ustring.sub(mw.ustring.gsub(syllables, "%s%.", " "), 2)
for i=1,mw.ustring.len(syllables) do
local letter = mw.ustring.sub(syllables, i, i)
local nextLetter = mw.ustring.sub(syllables, i+1, i+1)
local prevLetter = mw.ustring.sub(syllables, i-1, i-1)
if mw.ustring.match(letter, "[ğĞ]") then
trans = trans .. (mw.ustring.match(prevLetter, "[%.']") and (letter == "ğ" and "" or "(j)") or "ː")
else
trans = trans .. (phonemes[letter] or letter) ..((mw.ustring.match(letter, "[âîû]") and (mw.ustring.match(nextLetter, "[%.'%s]") or i == mw.ustring.len(syllables))) and "ː" or "")
end
end
IPA[#IPA+1] = {pron = "/" .. trans .. "/", q = {(mw.ustring.match(isAcc, "[%+%-]") and "definite accusative")}}
end
local words = {}
for _, word in ipairs(frame:getParent().args) do
words[#words+1] = word
end
if #words == 0 then
words[1] = mw.ustring.lower(mw.title.getCurrentTitle().text)
end
for i in ipairs(words) do
local value, isAcc, accVowel = mw.ustring.match(words[i], "^(.-)([%+%-]?)([ıiuü]?)$")
if value == "" then
value = mw.ustring.lower(mw.title.getCurrentTitle().text)
end
if mw.ustring.match(isAcc, "[%+%-]") then
transcribe(value, "notAcc", false)
transcribe(value, isAcc, accVowel)
else
transcribe(value .. accVowel, "notAcc", false)
end
end
return modIPA.format_IPA_full{lang = lang, items = IPA}
end
return export