Module:Util

-- Lua utility module. -- Usage: local p = {} -- Pluralize a word based on local dictionary or rules. -- Usage: function p.pluralize(frame) local base= frame.args[1] local return_val local base_len=string.len(base) local base_end=string.sub(base,base_len-1,1) local base_2ndlast=string.sub(base,base_len-2,1) -- dictionary first - irregular plurals if (string.lower(base)=="nebula") then return_val = string.sub(base,1,1).."ebulae" elseif(string.lower(base)=="torpedo") then return_val = string.sub(base,1,1).."orpedoes" -- rules elseif (base_end=="y") then if (base_2ndlast=="e") then -- ex - money return_val = string.sub(base,1,base_len-2).."ies" else -- ex - Secretary return_val = string.sub(base,1,base_len-1) .. "ies" end elseif (base_end=="h") then if (base_2ndlast=="c" or base_2ndlast=="s") then -- ex church or fish return_val = string.sub(base,1,base_len-2) .. "es" else return_val = base .. "s" -- ex - blah end elseif (base_end=="s") then -- ex - Idris - Or should we deal with things like crisis/crises as a rule? return_val = base else -- default rule return_val = base .. "s" end return return_val end return p