This module implements the {{ka-IPA}} template.


local export = {}

local m_IPA = require("Module:IPA")

local lang = require("Module:languages").getByCode("ka")

local IPA_mapping = {
	["ა"] = "a", ["ბ"] = "b", ["გ"] = "ɡ", ["დ"] = "d",
	["ე"] = "e", ["ვ"] = "v", ["ზ"] = "z", ["თ"] = "tʰ",
	["ი"] = "i", ["კ"] = "kʼ", ["ლ"] = "l", ["მ"] = "m",
	["ნ"] = "n", ["ო"] = "o", ["პ"] = "pʼ", ["ჟ"] = "ʒ",
	["რ"] = "ɾ", ["ს"] = "s", ["ტ"] = "tʼ", ["უ"] = "u",
	["ფ"] = "pʰ", ["ქ"] = "kʰ", ["ღ"] = "ʁ", ["ყ"] = "χʼ",
	["შ"] = "ʃ", ["ჩ"] = "t͡ʃʰ", ["ც"] = "t͡sʰ", ["ძ"] = "d͡z",
	["წ"] = "t͡sʼ", ["ჭ"] = "t͡ʃʼ", ["ხ"] = "χ", ["ჯ"] = "d͡ʒ",
	["ჰ"] = "h"
}

function export.pronunciation(word)
    word = mw.ustring.lower(word)

    word = mw.ustring.gsub(word, "%p", "")

    word = mw.ustring.gsub(word, ".", IPA_mapping)
    
    word = mw.ustring.gsub(word, "([bɡdztʰkʼlmnpʼʒɾstʼpʰkʰʁχʼʃt͡ʃʰt͡sʰd͡zt͡sʼt͡ʃʼχd͡ʒh])v", "%1ʷ")
    word = mw.ustring.gsub(word, "v([tʰkʼpʼstʼpʰkʰχʼʃt͡ʃʰt͡sʰt͡sʼt͡ʃʼχ])", "f%1")
    word = mw.ustring.gsub(word, "l([aou])", "ɫ%1")

    return word
end

function export.show(frame)
    local args = frame:getParent().args
    local pagetitle = mw.title.getCurrentTitle().text

    local p, results = {}, {}

    if args[1] then
        for index, item in ipairs(args) do
            table.insert(p, (item ~= "") and item or nil)
        end
    else
        p = {pagetitle}
    end

    for _, word in ipairs(p) do
        table.insert(results, {pron = "[" .. export.pronunciation(word) .. "]"})
    end

    return m_IPA.format_IPA_full(lang, results)
end

return export