--Module to create plurals for units (initially)Might be split into code and data--
--Plurals by language--local plural =
--local function findLang(langcode) local langobj langcode = mw.text.trim(langcode or "") if mw.language.isKnownLanguageTag(langcode) then langobj = mw.language.new(langcode) else langcode = mw.getCurrentFrame:callParserFunction('int',) if mw.language.isKnownLanguageTag(langcode) then langobj = mw.language.new(langcode) else langobj = mw.language.getContentLanguage end end return langobjend
local p =
--p.pl takes a unit name and an optional language codeIt returns the plural of that unit in the given language, if it can.it is exported for use in other modules.--function p.pl(unit, langcode) langcode = findLang(langcode).code unit = tostring(unit) or "" local ret = "" if plural[langcode] then if plural[langcode][unit] then -- irregular plural from lookup ret = plural[langcode][unit] else local per = plural[langcode].per local u1, u2 = unit:match("(.+) " .. per .. " (.+)") if u1 then -- recurse to give plural of bit before " per " ret = p.pl(u1) .. " per " .. u2 else -- standard plural ret = unit .. plural[langcode][1] end end else -- unknown language, so return unchanged ret = unit end return retend
--p.plural takes a quantity (number and unit name) and an optional language codeIt returns the quantity with proper plural units in the given language, if it can.it is exported for use in other modules.--function p.plural(quant, langcode) local num, unit = quant:match("([%d%.,]+)%A+(.*)") if tonumber(num)
--main|quantity=3 week}} returns "3 weeks"--function p.main(frame) local args = if frame.args.quantity then args = frame.args else args = frame:getParent.args end
-- if nothing supplied, return nothing (or add an error message if debugging) if not args.quantity then return "" end
return p.plural(args.quantity, args.lang)end
return p