spesmilo / electrum

Electrum Bitcoin Wallet
https://electrum.org
MIT License
7.4k stars 3.08k forks source link

Localization problem in utils.py #8304

Closed lionkmp closed 1 year ago

lionkmp commented 1 year ago

In utils.py:

return (_("{} ago") if from_date < sincedate else ("in {}")).format(td)

This code builds up a sentence from parts like these:

"about 1 year" "about 5 years"

Plus then "ago" or "in" like

"in about 1 year" "in about 5 years" "about 1 year ago" "about 5 years ago"

But in my language, Hungarian, this cannot be translated from parts, because words like "year", "month", "day", "minute" require a different format for these sentences.

"in about 5 years" -> "körülbelül 5 éven belül" (or "körülbelül 5 év múlva") "about 5 years ago" -> "körülbelül 5 éve" (or "körülbelül 5 évvel ezelőtt")

(év = year) (month is "hónap" and would use forms: "hónapon" "hónapja", "hónappal".)

So for a grammatically correct translation I would need the "in" and "ago" versions separately available as language string along with all combinations of: year, years, month, months, day, days. I know that duplicates the number of current strings.

So that this part would need to appear two times, once with "in" and once with "ago" INCLUDED:

    if distance_in_minutes == 0:
        if include_seconds:
            return _("{} seconds").format(distance_in_seconds)
        else:
            return _("less than a minute")
    elif distance_in_minutes < 45:
        return _("about {} minutes").format(distance_in_minutes)
    elif distance_in_minutes < 90:
        return _("about 1 hour")
    elif distance_in_minutes < 1440:
        return _("about {} hours").format(round(distance_in_minutes / 60.0))
    elif distance_in_minutes < 2880:
        return _("about 1 day")
    elif distance_in_minutes < 43220:
        return _("about {} days").format(round(distance_in_minutes / 1440))
    elif distance_in_minutes < 86400:
        return _("about 1 month")
    elif distance_in_minutes < 525600:
        return _("about {} months").format(round(distance_in_minutes / 43200))
    elif distance_in_minutes < 1051200:
        return _("about 1 year")
    else:
        return _("over {} years").format(round(distance_in_minutes / 525600))

Thanks in advance.

ps: there are some smaller similar localization issues, where code builds string to add e.g. numbers or parts of the sentence together, like Var + " of " + var + " more text". Should I report those too, and could be replaced to something like "{1} of {2} more text" ? (So that there is no barrier for translations, regarding order of parts of the sentence.)

SomberNight commented 1 year ago

It's not just about languages where in/ago does not work the same as in English. Even for languages where it could work, the translated string will not get properly substituted in. util.age() is double-translating strings, and this does not work... e.g. consider: EDIT: ah brainfart, nvm.

(btw localisation for this method was only added recently, in https://github.com/spesmilo/electrum/commit/4d4d2e2206c7d596ec36132e19254f1e7106933b)

SomberNight commented 1 year ago

should be fixed in https://github.com/spesmilo/electrum/commit/f528758c292c006ad4c12df392789819acb3d372

ps: there are some smaller similar localization issues, where code builds string to add e.g. numbers or parts of the sentence together, like Var + " of " + var + " more text". Should I report those too, and could be replaced to something like "{1} of {2} more text" ? (So that there is no barrier for translations, regarding order of parts of the sentence.)

Sure, feel free to report these in new issues. Depending on how many instances there are, it might make sense to not create one issue for each, but group them somehow (if they are related).