obs-advanced-timer icon indicating copy to clipboard operation
obs-advanced-timer copied to clipboard

Formatter with plural forms

Open pmudry opened this issue 4 years ago • 1 comments

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

pmudry avatar Feb 23 '21 19:02 pmudry

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

firstnevyn avatar Oct 15 '21 07:10 firstnevyn