cg2121 / obs-advanced-timer

GNU General Public License v2.0
188 stars 33 forks source link

Formatter with plural forms #14

Open pmudry opened 3 years ago

pmudry commented 3 years ago

I sometimes like to have the words minutes and seconds spelled correctly in the timer. Here is a working suggestions for plural forms (basic but working).

if string.match(text, "%%fm") then
    local minutes = math.floor(ms / 60000) % 60
    if minutes < 1 then
        minutes = string.format("%d", minutes) .. " minute"
    else
        minutes = string.format("%d", minutes) .. " minutes"
    end

    text = string.gsub(text, "%%fm", minutes)
end

if string.match(text, "%%fs") then
    local seconds = math.floor(ms / 1000) % 60
    if seconds < 1 then
        seconds = string.format("%d", seconds) .. " second"
    else
        seconds = string.format("%d", seconds) .. " seconds"
    end

    text = string.gsub(text, "%%fs", seconds)
end
firstnevyn commented 2 years ago

the logic needs work. 0 minute ? 1 minute 2 minutes 0 minutes remaining s/</==/g