Opened 11 years ago

#856 new defect

Time interval localization fails

Reported by: digital-dreamer Owned by:
Priority: minor Milestone:
Component: graphic design/interface Keywords: i18n, timesince
Cc: Parent Tickets:

Description

Time intervals, such as “1 hour, 20 minutes ago” are never translated, even though the i18n is implemented correctly.

Cause: timesince.py uses lazy_pass_to_ungettext for the translation. The function, ungettext, requires a singular-plural pair. But this pair was not recognized when generating the .pot file. To be usable with ungettext, the record must contain both “msgid” and “msgid_plural”. Consequently, ungettext sees neither singular nor plural translation, even when it is present in the language file, and always defaults to the English string.

Solution: when generating the .pot file (template for translators), be sure not to miss the ungettext aliased as “_” in timesince.py.

Easier solution: just patch the .pot file with “fix-plurals-in-pot.patch” that I included in the attachment. This will fix the 6 special cases (year, month, …) and you can continue generating the template the same way you do now.

Note: If you are wondering why “minutes” is mentioned twice, it is because timesince.py uses it via both ungettext and ugettext (in the case of “0 minutes”), and it wouldn't otherwise see it. You can either change it to ungettext with n=1, or have the word “minutes” twice in the .pot, I chose the latter because it didn't require changing the code.

So, I believe it will work like this: if you patch the current mediagoblin_mediagoblin.pot and upload it to transifex, it will add these new words. Once people translate them, the .po files you'll export from transifex will already be in the correct format, and time intervals will appear in those languages, without changing any of the code. I tested it on my machine and it seems to work.

Attachments (1)

fix-plurals-in-pot.patch (995 bytes ) - added by digital-dreamer 11 years ago.

Download all attachments as: .zip

Change History (1)

by digital-dreamer, 11 years ago

Attachment: fix-plurals-in-pot.patch added
Note: See TracTickets for help on using tickets.