Module:ConvertSantaliDigit

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

Documentation for this module may be created at Module:ConvertSantaliDigit/doc

Code

-- First, define a table of text to search for, and what to convert it to.
local convertDigitOnly = {
   ['0'] = '᱐',
   ['1'] = '᱑',
   ['2'] = '᱒',
   ['3'] = '᱓',
   ['4'] = '᱔',
   ['5'] = '᱕',
   ['6'] = '᱖',
   ['7'] = '᱗',
   ['8'] = '᱘',
   ['9'] = '᱙',
}

local santali2EngDigitOnly = {
   ['᱐'] = '0',
   ['᱑'] = '1',
   ['᱒'] = '2',
   ['᱓'] = '3',
   ['᱔'] = '4',
   ['᱕'] = '5',
   ['᱖'] = '6',
   ['᱗'] = '7',
   ['᱘'] = '8',
   ['᱙'] = '9',
}

local conversionTable = {
   ['January'] = 'ᱡᱟᱱᱩᱣᱟᱨᱤ',
   ['February'] = 'ᱯᱷᱮᱵᱽᱨᱩᱣᱟᱨᱤ',
   ['March'] = 'ᱢᱟᱨᱪ',
   ['April'] = 'ᱮᱯᱨᱤᱞ',
   ['May'] = 'ᱢᱮ',
   ['June'] = 'ᱡᱩᱱ',
   ['July'] = 'ᱡᱩᱞᱟᱭ',
   ['August'] = 'ᱚᱜᱚᱥᱴ',
   ['September'] = 'ᱥᱮᱯᱴᱮᱢᱵᱚᱨ',
   ['October'] = 'ᱚᱠᱴᱚᱵᱚᱨ',
   ['November'] = 'ᱱᱚᱵᱷᱮᱢᱵᱚᱨ',
   ['December'] = 'ᱰᱤᱥᱮᱢᱵᱚᱨ',
   ['january'] = 'ᱡᱟᱱᱩᱣᱟᱨᱤ',
   ['february'] = 'ᱯᱷᱮᱵᱽᱨᱩᱣᱟᱨᱤ',
   ['march'] = 'ᱢᱟᱨᱪ',
   ['april'] = 'ᱮᱯᱨᱤᱞ',
   ['may'] = 'ᱢᱮ',
   ['june'] = 'ᱡᱩᱱ',
   ['july'] = 'ᱡᱩᱞᱟᱭ',
   ['august'] = 'ᱚᱜᱚᱥᱴ',
   ['september'] = 'ᱥᱮᱯᱴᱮᱢᱚᱨ',
   ['october'] = 'ᱚᱠᱴᱚᱵᱚᱨ',
   ['november'] = 'ᱱᱚᱵᱷᱮᱢᱵᱚᱨ',
   ['december'] = 'ᱰᱤᱥᱮᱢᱵᱚᱨ',
   ['mile'] = 'ᱢᱟᱭᱤᱞ',
   ['miles'] = 'ᱢᱟᱭᱤᱞ',
   ['kilometre'] = 'ᱠᱤᱞᱚᱢᱤᱴᱚᱨ',
   ['kilometres'] = 'ᱠᱤᱞᱚᱢᱤᱴᱚᱨ',
   ['km'] = 'ᱠᱤᱹᱢᱤᱹ',
   ['0'] = '᱐',
   ['1'] = '᱑',
   ['2'] = '᱒',
   ['3'] = '᱓',
   ['4'] = '᱔',
   ['5'] = '᱕',
   ['6'] = '᱖',
   ['7'] = '᱗',
   ['8'] = '᱘',
   ['9'] = '᱙',
}

-- Then we define a table to hold our function
local p = {}

-- define a function that converts english digits to santali digits only nothing else.
function p.En2satdigit(frame)
    local s = frame.args[1] -- This gets the first positional argument.
    for en, santali in pairs(convertDigitOnly) do -- This converts every digit found in the table.
        s = mw.ustring.gsub(s, en, santali)
    end
    return s -- Get the result of the function.
end

-- define a function that converts santali digits to English digits only nothing else.
function p.Sat2endigit(frame)
    local s = frame.args[1] -- This gets the first positional argument.
    for en, santali in pairs(santali2EngDigitOnly) do -- This converts every digit found in the table.
        s = mw.ustring.gsub(s, en, santali)
    end
    return s -- Get the result of the function.
end

-- Then we define a function that converts strings using conversionTable.
function p.main(frame)
    local s = frame.args[1] -- This gets the first positional argument.
    for en, santali in pairs(conversionTable) do -- This converts every string found in the table.
        s = mw.ustring.gsub(s, en, santali)
    end
    return s -- Get the result of the function.
end

return p -- Pass our table containing our function back to Lua.
-- Now we can call our function using {{#invoke:ConvertDigit|main|<!-- your text here 

-->}}.