მოდული:ქართული ანბანი

მასალა ვიკიპედიიდან — თავისუფალი ენციკლოპედია

შეგიძლიათ შექმნათ დოკუმენტაცია ამ მოდულისათვის: მოდული:ქართული ანბანი/ინფო

-- მოდული რიცხვებისა და ქართული ასოების რიცხვითი მნიშვნელობების ორმხრივი გადაყვანისათვის.
local p = {}

function p.to_digital(frame) -- ქართული ასოების გადაყვანა რიცხვებში
    local georgianText = frame.args[1]
    if not georgianText then
        return "შეცდომა: შეიყვანეთ ქართული ასოები"
    end

    local georgianToDigitalMap = {
        units = {["ა"] = 1, ["ბ"] = 2, ["გ"] = 3, ["დ"] = 4, ["ე"] = 5, ["ვ"] = 6, ["ზ"] = 7, ["ჱ"] = 8, ["თ"] = 9},
        tens = {["ი"] = 1, ["კ"] = 2, ["ლ"] = 3, ["მ"] = 4, ["ნ"] = 5, ["ჲ"] = 6, ["ო"] = 7, ["პ"] = 8, ["ჟ"] = 9},
        hundreds = {["რ"] = 1, ["ს"] = 2, ["ტ"] = 3, ["ჳ"] = 4, ["ფ"] = 5, ["ქ"] = 6, ["ღ"] = 7, ["ყ"] = 8, ["შ"] = 9},
        thousands = {["ჩ"] = 1, ["ც"] = 2, ["ძ"] = 3, ["წ"] = 4, ["ჭ"] = 5, ["ხ"] = 6, ["ჴ"] = 7, ["ჯ"] = 8, ["ჰ"] = 9},
        ten_thousands = {["ჵ"] = 1}
    }

    local result = 0
    local places = {"units", "tens", "hundreds", "thousands", "ten_thousands"}

    for i = 1, #georgianText do
        local char = mw.ustring.sub(georgianText, i, i)
        for _, place in ipairs(places) do
            local placeValue = georgianToDigitalMap[place][char]
            if placeValue then
                result = result * 10 + placeValue
                break
            end
        end
    end

    return result
end

function p.to_georgian(frame) -- რიცხვების გადაყვანა ქართულ ასოებში
    local numericValue = tonumber(frame.args[1])
    if not numericValue then
        return "შეცდომა: შეიყვანეთ ციფრები"
    end

    local digitalToGeorgianMap = {
        units = {"ა", "ბ", "გ", "დ", "ე", "ვ", "ზ", "ჱ", "თ"},
        tens = {"ი", "კ", "ლ", "მ", "ნ", "ჲ", "ო", "პ", "ჟ"},
        hundreds = {"რ", "ს", "ტ", "ჳ", "ფ", "ქ", "ღ", "ყ", "შ"},
        thousands = {"ჩ", "ც", "ძ", "წ", "ჭ", "ხ", "ჴ", "ჯ", "ჰ"},
        ten_thousands = {"ჵ"}
    }

    local result = ""
    local places = {"units", "tens", "hundreds", "thousands", "ten_thousands"}
    local remainingValue = numericValue

    for _, place in ipairs(places) do
        local placeValue = remainingValue % 10
        if placeValue > 0 then
            result = digitalToGeorgianMap[place][placeValue] .. result
        end
        remainingValue = math.floor(remainingValue / 10)
    end

    return result
end

return p