A modult a Modul:hi-IPA/doc lapon tudod dokumentálni
local export = {}
local lang = require("Module:languages").getByCode("hi")
local sc = require("Module:scripts").getByCode("Deva")
local m_IPA = require("Module:IPA")
local gsub = mw.ustring.gsub
local gmatch = mw.ustring.gmatch
local find = mw.ustring.find
local correspondences = {
= "ŋ", = "ɡ",
= "t͡ʃ", = "d͡ʒ", = "ɲ",
= "ʈ", = "ɖ", = "n",
= "t̪", = "d̪",
= "j", = "ɾ", = "ʋ", = "l̪",
= "ʃ", = "ʃ", = "ɦ",
= "ɽ", = "ʒ", = "ɭ", = "ɣ", = "q", = "x", = "n", = "ɹ",
= "ə", = "ɑː", = "ɪ",
= "iː", = "oː", = "eː",
= "ʊ", = "uː", = "ɔː", = "æː",
= "ʊ̃", = "õː", = "ə̃", = "ɑ̃ː",
= "oːm", = "ʰ", = "(ʔ)",
}
local perso_arabic = {
= "kh", = "g", = "k", = "z", = "",
}
local lengthen = {
= "ā", = "ī", = "ū",
}
local vowels = "aāiīuūoŏĕʊɪɔɔ̃ɛeæãā̃ẽĩī̃õũū̃ː"
local vowel = "ː?"
local weak_h = "()h"
local aspirate = "()"
local syllabify_pattern = "(̃?)(+)(̃?)"
local function find_consonants(text)
local current = ""
local cons = {}
for cc in mw.ustring.gcodepoint(text .. " ") do
local ch = mw.ustring.char(cc)
if find(current .. ch, "^$") or find(current .. ch, "^h$") then
current = current .. ch
else
table.insert(cons, current)
current = ch
end
end
return cons
end
local function syllabify(text)
for count = 1, 2 do
text = gsub(text, syllabify_pattern, function(a, b, c)
b_set = find_consonants(b)
table.insert(b_set, #b_set > 1 and #b_set or 1, ".")
return a .. table.concat(b_set) .. c
end)
text = gsub(text, "(" .. vowel .. ")(?=" .. vowel .. ")", "%1.")
end
-- text = gsub(text, "(" .. vowel .. ")(" .. vowel .. ")", "%1.%2")
return text
end
local identical = "knlsfzθ"
for character in gmatch(identical, ".") do
correspondences = character
end
local function transliterate(text)
return lang:transliterate(text)
end
function export.link(term)
return require("Module:links").full_link{ term = term, lang = lang, sc = sc }
end
function export.toIPA(text, style)
local translit = transliterate(text)
if not translit then
error('The term "' .. Hindi .. '" could not be transliterated.')
end
if style == "standard" then
translit = gsub(translit, "", perso_arabic)
end
-- force final schwa
translit = gsub(translit, "a~$", "ə")
-- remove final schwa (Pandey, 2014)
translit = gsub(translit, "a$", "")
translit = gsub(translit, "(...)a ", "%1 ")
translit = gsub(translit, "(...)a%-", "%1-")
-- vowels
translit = gsub(translit, "͠", "̃")
translit = gsub(translit, "a()()", function(a, b)
return "a" .. lengthen .. b
end)
translit = gsub(translit, 'a(̃?)i', 'ɛ%1ː')
translit = gsub(translit, 'a(̃?)u', 'ɔ%1ː')
translit = gsub(translit, "%-$", "")
translit = gsub(translit, "^%-", "")
translit = gsub(translit, "%-", ".")
translit = gsub(translit, "ŕ$", "r")
translit = gsub(translit, "ŕ", "ri")
translit = gsub(translit, ",", "")
translit = gsub(translit, " ", "..")
translit = syllabify(translit)
-- gy
translit = gsub(translit, 'jñ', 'gy')
-- aspiration rules
translit = gsub(translit, 'ah%.(h?)', 'ɛːʱ.%1')
translit = gsub(translit, 'a%.ha', 'ɛːʱ')
translit = gsub(translit, aspirate .. "h", '%1ʰ')
translit = gsub(translit, weak_h, '%1ʱ')
translit = gsub(translit, "%.ː", "ː.")
local result = gsub(translit, ".", correspondences)
result = gsub(result, "%.%.", "‿")
-- formatting
result = gsub(result, "ː̃", "̃ː")
result = gsub(result, "ː.̃", "̃ː.")
result = gsub(result, "%.$", "")
-- i and u lengthening
result = gsub(result, "ʊ(̃?)(ʱ?)$", "u%1ː%2")
result = gsub(result, "ɪ(̃?)(ʱ?)$", "i%1ː%2")
result = gsub(result, "ɪ%.j", "iː.j")
return result
end
function export.make(frame)
local args = frame:getParent().args
local pagetitle = mw.title.getCurrentTitle().text
local p, results = {}, {}, {}
if args then
for index, item in ipairs(args) do
table.insert(p, (item ~= "") and item or nil)
end
else
p = { pagetitle }
end
for _, Hindi in ipairs(p) do
table.insert(results, { pron = "/" .. export.toIPA(Hindi, "standard") .. "/" })
if export.toIPA(Hindi, "standard") ~= export.toIPA(Hindi, "persianized") then
table.insert(results, { pron = "/" .. export.toIPA(Hindi, "persianized") .. "/" })
end
end
return m_IPA.format_IPA_full(lang, results)
end
function export.make_ur(frame)
local args = frame:getParent().args
local pagetitle = mw.title.getCurrentTitle().text
local lang = require("Module:languages").getByCode("ur")
local sc = require("Module:scripts").getByCode("ur-Arab")
local p, results = {}, {}, {}
if args then
for index, item in ipairs(args) do
table.insert(p, (item ~= "") and item or nil)
end
else
error("No transliterations given.")
end
for _, Urdu in ipairs(p) do
table.insert(results, { pron = "/" .. export.toIPA(Urdu, "persianized") .. "/" })
end
return m_IPA.format_IPA_full(lang, results)
end
return export