-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
naturaltime: wrong translation with delta >= 2 years #21
Comments
Here's a more direct reproducer. The first three asserts are fine, but the last fails because it get "12 years" not "12 ans": import humanize
output = humanize.naturaldelta(1 * 365 * 24 * 60 * 60)
print(output)
assert output == "a year"
output = humanize.naturaldelta(12 * 365 * 24 * 60 * 60)
print(output)
assert output == "12 years"
humanize.i18n.activate("fr_FR")
output = humanize.naturaldelta(1 * 365 * 24 * 60 * 60)
print(output)
assert output == "un an"
output = humanize.naturaldelta(12 * 365 * 24 * 60 * 60)
print(output) # "12 years"
assert output == "12 ans" This was introduced in d1faf1c from PR jmoiron/humanize#246: Instead of passing an integer to the - return _ngettext("%d year", "%d years", years) % years
+ return _ngettext("%s year", "%s years", years) % intcomma(years) And also I think it can't find humanize/src/humanize/locale/fr_FR/LC_MESSAGES/humanize.po Lines 339 to 344 in 7688f20
Ping @carterbox, please could you have a look at this? |
I checked out version 4.2.0, and I cannot run this reproducer.
What am I doing wrong? |
The docs say that this "gettext.translation" function only looks for ".mo" files, but the source only contains ".po" files. I assume there is some autoconversion supposed to be happening. |
OK. I grabbed the compiled translation files from the conda tar. |
The general translation workflow seems to be:
When I added the intcomma feature for years in the time module, I didn't properly test step 2 (translate the format string). Since the translation works directly on the format string and the translation phrases include the formatters (probably because in some locales the order is changed), switching from %d to %s broke the translation step. This means the translation is broken for all translated languages. Notably, this translation error does not occur in Lines 564 to 567 in 29d37fb
So the solution would be to match I don't want to change the translation files or swap the formatters in other places because using %d instead of %s may be used to do rounding or truncation of floating point numbers. |
This patch fixes a bug introduced in 3.14.0, where the format string was changed from %d to %s to add separators to the year. However, this needs to happen after translation because the translator uses the format strings as part of the translation. Closes python-humanize#21
This patch fixes a bug introduced in 3.14.0, where the format string was changed from %d to %s to add separators to the year. However, this needs to happen after translation because the translator uses the format strings as part of the translation. Closes python-humanize#21
What did you do?
Ran the following code:
What did you expect to happen?
Output to be:
What actually happened?
Output was:
What versions are you using?
The text was updated successfully, but these errors were encountered: