Module:IPA

Úr Wikipediu, frjálsa alfræðiritinu

Þessi skrifta inniheldur kóðann á bak við {{IPAc-is}} sniðið. Vinsamlegast líttu á síðu sniðsins fyrir leiðbeiningar.


local z = {}

local function audiolink(s)
    local contents = "([[File:Speaker Icon.svg|13px|link=File:" .. s .. "|alt=]] [[:Media:" .. s .. "|hlusta]])"
    return '<small class="nowrap">' .. contents .. '</small>'
end

local function plainaudiolink(s)
    local contents = "[[File:Speaker Icon.svg|13px|link=Media:" .. s .. "|alt=Hlusta á þetta|hlusta]]"
    return '<small class="nowrap">' .. contents .. '</small>'
end

local function IPA(s)
    return  '<span title="Representation in the International Phonetic Alphabet (IPA)" class="IPA">' .. s .. '</span>'
end

local function HTITLE(s, title, dotted)
    local b
    if dotted then b = " dotted" else b = "" end
    return '<span class="IPA" style="border-bottom:1px '.. b ..';white-space:nowrap;" title="' .. title .. '">' .. s .. '</span>'
end

local INprefixes = { IPA = "IPA:", lang = "Hindustani:", langhi = "Hindi:", langur = "Urdu:", pron = "pronounced", hi = "Hindi:", ur = "Urdu:" }

-- This is used by {{IPA-hns}}
function z.IPAhns(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
--  local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself

    local Word = args[1]
    if ( Word ) then Word = IPA("[[Wikipedia:IPA for Hindi and Urdu|[" .. Word .. "]]]") else Word = "" end
    local Prefix = args[2]
    if ( Prefix ) then 
        Prefix = INprefixes[Prefix]
        if ( Prefix ) then Prefix = Prefix .. "&nbsp;" else Prefix = "" end
    else 
        Prefix = "" 
    end
    local Audio = args[3]
    if ( Audio ) then Audio = "&nbsp;" .. audiolink(Audio) else Audio = "" end
    return Prefix .. Word .. Audio
end

local IPAprefixes = { 
    ["tungum"]    = "Íslenska",
    ["íslenska"]    = "Íslenska",
    ["framb"]	= "borið fram",
    ["framburður"]	= "borið fram",
    ["local"]	= "local",
    ["ipa"]	    = "[[Alþjóðlega hljóðstafrófið|IPA]]",
    ["is"]	    = "[[Íslenska]]"
}

local IPAH = {
	["a"] = "'a' í 'karl'",
	["aː"] = "'a' í 'aka'",
    ["c"] = "'g' í 'gys'",
    ["cʰ"] = "'k' í 'kær'",
	["ç"] = "'hj' í 'hjá'",
	["ð"] = "'ð' í 'verða'",
	["ɛ"] = "'e' í 'kenna'",
	["ɛː"] = "'e' í 'lesa'",
	["f"] = "'f' í 'fyrir'",
	["h"] = "'h' í 'hús'",
	["ʰ"] = "fráblástur",
	["ɪ"] = "'i' í 'inni'",
	["ɪː"] = "'i' í 'siður'",
	["i"] = "'í' í 'fínt'",
	["iː"] = "'í' í 'líf'",
	["j"] = "'j' í 'jú'",
	["ʝ"] = "'j' í 'játa'",
	["k"] = "'g' í 'gaman'",
	["kʰ"] = "'k' í 'kind'",
	["l"] = "'l' í 'líf'",
	["l̥"] = "'l' í 'stelpa'",
	["ɫ"] = "áhersla",
	["ɫ̥"] = "áhersla",
	["m"] = "'m' í 'miði'",
	["m̥"] = "'m' í 'lampi'",
	["n"] = "'n' í 'níu'",
	["n̥"] = "'n' í 'hnífur'",
	["ɲ"] = "'n' í 'lengi'",
	["ɲ̊"] = "'n' í 'banki'",
	["ŋ"] = "'ng' í 'ungs'",
	["ŋ̊"] = "'ng' í 'þungt'",
	["ɔ"] = "'o' í 'loft'",
	["ɔː"] = "'o' í 'nota'",
	["θ"] = "'þ' og 'ð' í 'það'",
	["p"] = "'b' í 'böl'",
    ["pʰ"] = "'p' í 'pera'",
	["r"] = "'r' í 'rós'",
	["r̥"] = "'hr' í 'hreinn'",
	["s"] = "'s' í 'saga'",
	["t"] = "'d' í 'dagur'",
	["tʰ"] = "'t' í 'tennur'",
	["u"] = "'ú' í 'pússa'",
	["uː"] = "'ú' í 'súpa'",
	["v"] = "'f' í 'afi'",
	["ʏ"] = "'u' í 'undir'",
	["ʏː"] = "'u' í 'muna'",
	["ɣ"] = "'g' í 'saga'",
	["x"] = "'k' í 'sjúkt'",
	["æ"] = "'ö' í 'dökk'",
	["æː"] = "'ö' í 'böl'",
	["ʔ"] = "(stopphljóð í kokinu)",
	["ai"] = "'æ' í 'æfing'",
	["aiː"] = "'æ' í 'æfa'",
	["au"] = "'á' í 'sjálfur'",
	["auː"] = "'á' í 'láta'",
	["ei"] = "'ei' í 'eitt'",
	["eiː"] = "'ei' í 'leika'",
	["ou"] = "'ó' í 'hóll'",
	["ouː"] = "'ó' í 'ljós'",
	["ɔi"] = "'o' í 'flogin'",
	["ʏi"] = "'u' í 'flugið'",
	["œi"] = "'au' í 'laust'",
	["øi"] = "'au' í 'laust'",
	["æy"] = "'au' í 'laust'",
	["œiː"] = "'au' í 'auga'",
	["øiː"] = "'au' í 'auga'",
	["æyː"] = "'au' í 'auga'",
	["ˈ"] = "áhersla",
	["ˌ"] = "vara-áhersla",
	["ː"] = "langt sérhljóð eða tvöfalt samhljóð",
	["."] = "skil atkvæðis",
	["-"] = "(aðskeyti)",
	["_"] = "''ekkert'' (bil)",
}

local SAMPA = {
    ["b"] = "p",
    ["p"] = "pʰ",
    ["d"] = "t",
    ["t"] = "tʰ",
    ["J_"] = "c",
    ["c"] = "cʰ",
    ["g"] = "k",
    ["k"] = "kʰ",
    ["f"] = "f",
    ["v"] = "v",
    ["D"] = "ð",
    ["T"] = "θ",
    ["s"] = "s",
    ["j"] = "ʝ",
    ["C"] = "ç",
    ["G"] = "ɣ",
    ["x"] = "x",
    ["h"] = "h",
    ["m"] = "m",
    ["m0"] = "m̥",
    ["n"] = "n",
    ["n0"] = "n̥",
    ["J0"] = "ɲ̊",
    ["N0"] = "ŋ̊",
    ["J"] = "ɲ",
    ["N"] = "ŋ",
    ["I"] = "ɪ",
    ["I:"] = "ɪː",
    ["i"] = "i",
    ["i:"] = "iː",
    ["E"] = "ɛ",
    ["E:"] = "ɛː",
    ["a"] = "a",
    ["a:"] = "aː",
    ["Y"] = "ʏ",
    ["Y:"] = "ʏː",
    ["9"] = "æ",
    ["9:"] = "æː",
    ["u"] = "u",
    ["u:"] = "uː",
    ["O"] = "x",
    ["O:"] = "ɔː",
    ["au"] = "au",
    ["au:"] = "auː",
    ["ou"] = "ou",
    ["ou:"] = "ouː",
    ["ei"] = "ei",
    ["ei:"] = "eiː",
    ["ai"] = "ai",
    ["ai:"] = "aiː",
    ["9y"] = "æy",
    ["Yi"] = "ʏi",
    ["Oi"] = "ɔi",
}

-- This is used by {{IPAc-is}}
function z.IPAcen(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
--  local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
	local templatestyles = mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = "Snið:IPA/styles.css"} }

    local index = 1
    
    local result = {}
    while true do
        local arg = args[index]
        if nil == arg then break end
        if "icon" == arg then
            table.insert(result, HTITLE("[[File:Loudspeaker.svg|13px|link=|alt=play]]", "framburður:"))
        else
            local prefix = IPAprefixes[arg]
            if nil == prefix then break end
            table.insert(result, prefix)
        end
        index = index + 1
    end
    
    local Audio = args["hljóð"]
    if ( Audio ) then 
        table.insert(result, plainaudiolink(Audio))
    end
    
    local phonemes = {}
    table.insert(result, '<span class="IPA">')
    table.insert(result, "[[Hjálp:Alþjóðlega hljóðstafrófið|/]]")
    local failure = "?"
    while true do
        local arg = args[index]
        if nil == arg then break end
        local title = IPAH[arg] or IPAH[SAMPA[arg]]
        if nil ~= title then
            table.insert(result, "[[Hjálp:Alþjóðlega hljóðstafrófið|" .. HTITLE(arg, title, true) .. "]]")
        else
            table.insert(result, HTITLE(arg, "Óþekkt hljóðan", false) .. "[[Category:Illa-sniðnar IPAc-is ítengingar]]")
        end
        index = index + 1
    end
    table.insert(result, "[[Hjálp:Alþjóðlega hljóðstafrófið|/]]")
    table.insert(result, '</span>')
    
    return templatestyles .. table.concat(result)
end

return z