Jump to content

Module:ar-common

ពីWiktionary

--[[
This module holds some commonly used functions for Arabic language. It's for use from other modules, not #invoke.
To use from a template, use the function main, e.g. {{#invoke:ar-common|main|remove_diacritics|اَلْلُغَةُ ٱلْعَرَبِيَّةُ}}
]]
 
local export = {}

-- this function enables the module to be called from a template
function export.main(frame)
    if type(export[frame.args[1]]) == 'function' then
        return export[frame.args[1]](frame.args[2], frame.args[3])
    else
        return export[frame.args[1]][frame.args[2]]
    end
end
  
function export.remove_diacritics(word)
    --fátḥa
    word = mw.ustring.gsub(word, "َ", "")
    --ḍámma
    word = mw.ustring.gsub(word, "ُ", "")
    --kásra
    word = mw.ustring.gsub(word, "ِ", "")
    --sukūn
    word = mw.ustring.gsub(word, "ْ", "")
    --šádda
    word = mw.ustring.gsub(word, "ّ", "")
    --fatḥatān
    word = mw.ustring.gsub(word, "ً", "")
    --ḍammatān
    word = mw.ustring.gsub(word, "ٌ", "")
    --kasratān
    word = mw.ustring.gsub(word, "ٍ", "")
    --mádda
    word = mw.ustring.gsub(word, "ٓ", "")
    --ʾálif xanjaríyya
    word = mw.ustring.gsub(word, "ٰ", "")
    -- taṭwīl
    word = mw.ustring.gsub(word, "ـ", "") 
    --replace hámzat-al-wáṣl with an ʾálif
    word = mw.ustring.gsub(word, "ٱ", "ا")

    return word
end
 
return export