Module:Detect singular: Difference between revisions
Appearance
m 1 revision imported |
Template>Hike395 when flag is set, parse number and determine plurality from that |
||
| Line 31: | Line 31: | ||
local args = {} | local args = {} | ||
-- canonicalize boolean arguments | -- canonicalize boolean arguments | ||
for key, default in pairs({no_comma=false,parse_links=false,any_comma=false,no_and=false}) do | for key, default in pairs({no_comma=false,parse_links=false,any_comma=false, | ||
no_and=false,parse_number=false}) do | |||
if origArgs[key] == nil then | if origArgs[key] == nil then | ||
args[key] = default | args[key] = default | ||
| Line 42: | Line 43: | ||
local rewriteLinks = not args.parse_links | local rewriteLinks = not args.parse_links | ||
local anyComma = args.any_comma | local anyComma = args.any_comma | ||
local parseNumber = args.parse_number | |||
local s = origArgs[1] -- the input string | local s = origArgs[1] -- the input string | ||
if not s then | if not s then | ||
| Line 67: | Line 69: | ||
return plural | return plural | ||
end | end | ||
if parseNumber then | |||
local m = tonumber(mw.ustring.match(s,"^%s*(%d+)")) | |||
if m then | |||
return m > 1 and plural or singular | |||
end | |||
end | |||
-- fix for trailing br tags passed through [[template:marriage]] | -- fix for trailing br tags passed through [[template:marriage]] | ||
s = mw.ustring.gsub(s, '<%s*br[^>]*>%s*(</div>)', '%1') | s = mw.ustring.gsub(s, '<%s*br[^>]*>%s*(</div>)', '%1') | ||