Module:frm-utilities

From Wiktionary, the free dictionary
Jump to navigation Jump to search

--[[
    Utilities for Middle French
]]--

local export = {}
local links = require("Module:links")

-- Reduce any words or phrases to sorting order form
function export.sort(word)
    return require('Module:fr-utilities').sort(word)
end

-- Return plural form(s) of a word
function export.pluralize(word)
    local plurals = {}
    
    local pl = word
    pl = pl:gsub('e[lfp]$', 'és')
    pl = pl:gsub('al$', 'aulx')
    pl = pl:gsub('t$', 's')
    pl = pl:gsub('é$', 'ez')
    pl = pl:gsub('([^sxz])$', '%1s')
    if pl ~= word then
        table.insert(plurals, pl)

    end
    
    return plurals
end

-- Return feminine form of a word
function export.feminine(word)
    if type(word) == 'table' then word = word.args[1] end

    if mw.ustring.sub(word, -1) == "e" then
        return word
    elseif mw.ustring.sub(word, -2) == "if" then
        return mw.ustring.sub(word, 1, -2) .. 'fve'
    else
        word = word .. 'e'
        word = word:gsub('ée$', 'ee')

        return word
    end
end