Skip to content
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

German localisation should be improved #48

Closed
Luflosi opened this issue Aug 13, 2022 · 6 comments
Closed

German localisation should be improved #48

Luflosi opened this issue Aug 13, 2022 · 6 comments

Comments

@Luflosi
Copy link
Contributor

Luflosi commented Aug 13, 2022

What did you do?

Execute

import humanize
import datetime as dt
_t = humanize.i18n.activate("de_DE")
humanize.naturaltime(dt.datetime.now() - dt.timedelta(seconds=3600))

What did you expect to happen?

I would expect the output to be 'vor einer Stunde'.

What actually happened?

The output was 'vor eine Stunde', which is grammatically incorrect.
"one hour" translates to "eine Stunde" but "one hour ago" translates to "vor einer Stunde". I think 1 is the only number where this special case happens.

What versions are you using?

  • OS: macOS 10.15.7
  • Python: 3.10.5
  • Humanize: 4.2.3

Overall the support for German seems a bit lacking.
For example the . and , in numbers are swapped compared to what's common in English, which this library doesn't support (humanize.intcomma(12345) for example).
humanize.intword(123455913) outputs 123.5 Million but Million is singular. The correct output with a plural would be 123.5 Millionen, since 123.5 is more than 1 (actually I think it's correct to always use the plural when the value is not exactly equal to 1).

Is this something you think would be worthwhile to improve? I could help you by trying to find more of these problems, testing patches or even writing some fixes myself if you help me a bit. I'm afraid if I just mess around in the translation file, I'll fix some specific problem I found but break other cases I didn't think about.

@carterbox
Copy link
Contributor

The translation files are located here: https://github.com/python-humanize/humanize/tree/main/src/humanize/locale

I'm not sure whether they can handle a special case for single number like that because the pattern matches for "%s ago". Maybe poke around the language files and see if there are other languages that have a solution for this.

humanize.intword(123455913) outputs 123.5 Million but Million is singular. The correct output with a plural would be 123.5 Millionen, since 123.5 is more than 1 (actually I think it's correct to always use the plural when the value is not exactly equal to 1).

The translation files do support this type of plural selection. It probably just needs to be implemented in the translation file for German (see Spanish for an example).

For example the . and , in numbers are swapped compared to what's common in English, which this library doesn't support (humanize.intcomma(12345) for example).

Separator swapping is supported. This is done for French.

I'm afraid if I just mess around in the translation file, I'll fix some specific problem I found but break other cases I didn't think about.

That's what unit tests are for 😉.

@hugovk
Copy link
Member

hugovk commented Aug 15, 2022

I'm not sure whether they can handle a special case for single number like that because the pattern matches for "%s ago". Maybe poke around the language files and see if there are other languages that have a solution for this.

This may be possible using something along the lines of:

msgid "One file removed"
msgid_plural "%d files removed"

https://www.gnu.org/software/gettext/manual/html_node/Translating-plural-forms.html

@Luflosi
Copy link
Contributor Author

Luflosi commented Aug 23, 2022

Separator swapping is supported. This is done for French.

Are you sure this is supported? As far as I can tell, this only allows replacing , as the thousands separator with another character. Is there a way to also replace the decimal point . with another character? I think I will need to implement this myself.

@carterbox
Copy link
Contributor

Are you sure this is supported?

No. I suggest starting with a PR for the simplest translation fixes, then we can discuss in further detail the scope of replacing . with ,.

@hugovk
Copy link
Member

hugovk commented Feb 25, 2024

@Luflosi Anything left to fix here?

@Luflosi
Copy link
Contributor Author

Luflosi commented Feb 26, 2024

As you said in #93 (comment), intword doesn't yet use thousands_separator and decimal_separator.
I also created #175 for another problem.
Since there are now GitHub issues for these problems, I'm fine with closing this issue.

Thank you for maintaining this project!

@hugovk hugovk closed this as completed Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants