online-go / online-go.com

Source code for the Online-Go.com web interface
https://online-go.com/
GNU Affero General Public License v3.0
1.23k stars 344 forks source link

Vacation Day Accrued not displaying properly for 0 Days #915

Closed BHydden closed 4 years ago

BHydden commented 4 years ago

Describe the bug September 22, 2019 [21:22]💖 KoBa 💖: Vacation Accrued: (Supporter) out of 60 Days [21:22]💖 KoBa 💖: that thing only says "out of 60 days" if player has less than 1 day of vacation time available

Expected behavior Display "0 Days" not ""

Screenshots image

kobakitty commented 4 years ago

Expected behavior Display "0 Days" not ""

Or make it show "<1 days" instead "0 days" for the sake of clarity?

BHydden commented 4 years ago

Or make it show "<1 days" instead "0 days" for the sake of clarity?

It'll depend on whether I need to hardcode it or just change a setting...

BHydden commented 4 years ago

I can't tell exactly what this line does;

https://github.com/online-go/online-go.com/blob/7b8c2903efb8c41c0bde0bb2e695c4c2dc6e1a90/src/lib/translate.ts#L46

...but I suspect this is why the function returns "" instead of "0 Days"

any chance @GreenAsJade or @flovo could take a quick look at this for me? I'd rather not hardcode in a back door if I can avoid it.

Below is the whole function the above snippet came from

```typescript export function ngettext(singular, plural, count) { let key = singular + "" + plural; if (key in catalog) { if (catalog[key].length === 1) { count = 1; } return catalog[key][count === 1 ? 0 : 1]; } return debug_wrap(count === 1 ? singular : plural); } ```

GreenAsJade commented 4 years ago

As a first observation, this works for me:

    console.log("NGT DBG", ngettext("a", "b", 1));
    console.log("NGT DBG", ngettext("a", "b", 2));
    console.log("NGT DBG", ngettext("a", "b", 0));

NGT DBG a NGT DBG b NGT DBG b

BHydden commented 4 years ago

grr... that's how anoek said it should work... so why isn't it then? :/

BHydden commented 4 years ago

_() is just a gettext so I guess it must be inside interpolate() somewhere

GreenAsJade commented 4 years ago

... which strongly hints that vacation_time_accrued is not '0' but rather an empty string or some other thing by the time it hits ngettext.

IE check your code and assumptions before blaming the libraries ;)

BHydden commented 4 years ago

hmm ok good call maybe math.round small/big doesn't = 0 like I assumed... time for some of my own console logs lol

BHydden commented 4 years ago

Thanks @GreenAsJade

It turns out if(0) returns false, who knew 😛