Translate "hours ago" in utils.js

asked 2013-05-17 07:29:21 -0500

wowas gravatar image

updated 2013-05-20 00:41:48 -0500

Evgeny gravatar image

When translate string from utils.js then appear bugs. See row 3074:

return interpolate(
                    ngettext(
                        '%s hour ago',
                        '%s hours ago',
                        hours
                    ),
                    [Math.floor(hours),]
                )

If translate to Russian and add three variants:

msgid "%s hour ago"
msgid_plural "%s hours ago"
msgstr[0] "%s час назад"
msgstr[1] "%s часа назад"
msgstr[2] "%s часов назад"

We get:

1 часа назад (must be 1 час назад)

4 часов назад (must be 4 часа назад)

Cause by shifting from floor.

Code must be:

return interpolate(
                        ngettext(
                            '%s hour ago',
                            '%s hours ago',
                            Math.floor(hours)
                        ),
                        [Math.floor(hours),]
                    )

The same for minutes. Please update.

edit retag flag offensive close merge delete

Comments

There is incorrect pluralization formula in django.po and djangojs.po. I am looking into how to fix this while retaining the Transifex service.

Evgeny gravatar imageEvgeny ( 2013-05-17 16:44:09 -0500 )edit

I check pluralization formula - it is OK. Other translation work OK. Problem only in this point (file utils.js).

wowas gravatar imagewowas ( 2013-05-19 02:49:55 -0500 )edit

If the formula is ok and the translations are ok, then maybe the counter is wrong? Maybe you could try on django shell manually?

Evgeny gravatar imageEvgeny ( 2013-05-19 10:32:50 -0500 )edit

Because in js code hours is float then we return float value that then round. If I change code like above then all OK.

wowas gravatar imagewowas ( 2013-05-19 23:55:38 -0500 )edit

Ah, great - does it work correctly with hours < 1? Hmm, actually I don't see this in the code. In the github version we already have the .floor() part and it's on a different line number.

Evgeny gravatar imageEvgeny ( 2013-05-20 00:01:31 -0500 )edit