Module:Age: Difference between revisions

642 bytes added ,  11 years ago
m
Documented unusual plural/singular handling (no code changes were made, only comments); tested with :Australian_Labor_Party
(add support for {{Age in days}} and {{Gregorian serial date}})
m (Documented unusual plural/singular handling (no code changes were made, only comments); tested with :Australian_Labor_Party)
Line 15: Line 15:
     sep = sep or ' '
     sep = sep or ' '
     return tostring(number) .. sep .. ((number == 1) and singular or plural)
     return tostring(number) .. sep .. ((number == 1) and singular or plural)
    -- this uses an interesting trick of Lua:
    --  * and reurns false if the first argument is false, and the second otherwise, so (number==1) and singular returns singular if its 1, returns false if it is only 1
    --  * or returns the first argument if it is not false, and the second argument if the first is false
    --  * so, if number is 1, and evaluates (true and singular) returning (singular); or evaluates (singular or plural), finds singular non-false, and returns singular
    --  * but, if number is not 1, and evaluates (false and singular) returning (false); or evaluates (false or plural), and is forced to return plural
end
end


Anonymous user