Module:Name

From Guild of Archivists

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

--[[
Lua module in order to work on names
Done for Author template of Wikisources
]]--
 
function getSortKey( firstName, lastName )

    --Particle Managment Buggy because pa
    local particles = { "della", "de la", "des", "del", "dal", "da", "de", "du", "of", "von", "van", "d’", "d'" }
    local particle = ""
    local i = 1
    local length = table.getn( particles )

    while i <= length and particle == "" do
        if string.find( lastName, "^" .. string.gsub( particles[i], "%s", "%%s" ) ) then
            particle = particles[i]
            lastName = string.sub( lastName, string.len(particle) + 1 )
        end
        i = i + 1
    end

    local key = removeAccentuation( lastName )
    if firstName ~= nil and firstName ~= "" then
        key = key .. ", " .. removeAccentuation( firstName )
    end
    if particle ~= "" then
        key = key .. " " .. particle
    end

    return key
end

-- Only works for Basic Latin-based languages
function removeAccentuation( text )
    local list = { ["’"]="'", ["á"]='a', ["Á"]='A', ["ć"]='c', ["Ć"]='C', ["é"]='e', ["É"]='E', ["ģ"]='g', ["í"]='i', ["Í"]='I', ["ó"]='o', ["Ó"]='O', ["ĺ"]='I', ["Ĺ"]='L', ["ń"]='n', ["Ń"]='N', ["ŕ"]='r', ["Ŕ"]='R', ["ś"]='s', ["Ś"]='S', ["ú"]='u', ["Ú"]='U', ["ý"]='y', ["Ý"]='Y', ["ź"]='z', ["Ź"]='Z', ["ǿ"]='o', ["Ǿ"]='o', ["à"]='a', ["À"]='A', ["è"]='e', ["È"]='E', ["ì"]='i', ["Ì"]='I', ["ò"]='o', ["Ò"]='O', ["ù"]='u', ["Ù"]='U', ["ã"]='a', ["ẽ"]='e', ["õ"]='o', ["æ"]='ae', ["Æ"]='Ae', ["œ"]='oe', ["Œ"]='oe', ["ç"]='c', ["Ç"]='C', ["â"]='a', ["Â"]='A', ["ê"]='e', ["Ê"]='E', ["î"]='i', ["Î"]='I', ["ô"]='o', ["Ô"]='O', ["û"]='u', ["Û"]='U', ["ä"]='a', ["Ä"]='A', ["ë"]='e', ["Ë"]='E', ["ï"]='i', ["Ï"]='I', ["ö"]='o', ["Ö"]='O', ["ü"]='u', ["Ü"]='U' }
    for key,value in next,list do
       text = string.gsub( text, key, value )
    end
    return text
end


local p = {}

function p.getSortKey( frame )
    return getSortKey( frame.args[1], frame.args[2] )
end

function p.removeAccentuation( frame )
    return removeAccentuation( frame.args[1] )
end

return p