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

Localize dates and numbers #30

Open
milotype opened this issue Nov 20, 2020 · 8 comments
Open

Localize dates and numbers #30

milotype opened this issue Nov 20, 2020 · 8 comments

Comments

@milotype
Copy link
Contributor

Please enable localized forms for dates (in this case year) and numbers.

For instance, Croatian needs a period after the year. Also, a period is used as thousands separator … other languages use different forms …

Localized-Punctuation

@bnewbold
Copy link
Member

bnewbold commented Nov 20, 2020

Numbers should be simple using http://babel.pocoo.org/en/latest/numbers.html

In [24]: format_number(14900, locale='hr')
Out[24]: '14.900'

Though it doesn't seem to work for shorter numbers:

In [31]: format_number(2, locale='hr')
Out[31]: '2'

Do you know how to localize just years (vs. full dates) using babel or a similar python library? I tried treating the year a number (which wouldn't really expect to work) and formatting just the year using a made-up date (expecting "2019."):

In [23]: format_number(2019, locale='hr')
Out[23]: '2.019'

In [30]: format_date(datetime.date(2019,1,1), "yyyy", locale='hr')
Out[30]: '2019'

When printing dates I usually use https://en.wikipedia.org/wiki/ISO_8601 instead of localizing; at least in the USA the "normal" local format is ambiguous about month/day coming first. That standard specifies years as being printed as just 4 digits. Adding localization like a period after the year seems reasonable though.

@milotype
Copy link
Contributor Author

Unfortunately, I'm not a programmer, so I can't help really help in this case :-((

I don't understand why you think that it does not work for shorter numbers (it looks good to me, it's just one number which does not need a separator anyway):

In [31]: format_number(2, locale='hr')
Out[31]: '2'

@bnewbold
Copy link
Member

Shouldn't it be "2.", like we would use "Showing {num} out of {num}..." at the bottom of the page? Or maybe I am misunderstanding... is it only ordinals like "1." meaning "first"?

In the example of the bottom of the page, "Prikaz rezultata: 1. – 15. od 4,396,586", should the total be "4.396.586" or "4.396.586."? And if we had (hypothetically) paged to late results, would it be ""Prikaz rezultata: 1.000. – 1.015. od 4.396.586"?

@milotype
Copy link
Contributor Author

Yes, it's about ordinals. Just as dates and years, ordinals also need the period.

"Prikaz rezultata: ordinalordinal od total"

"Prikaz rezultata: 1. – 15. od 4.396.586"
"Prikaz rezultata: 1.000. – 1.015. od 4.396.586"

Thousands separator character:
Both period and space are used in many languages, not just Croatian.

If space is used as separator, it's actually better to use (in the order of my preference):

  • 'NARROW NO-BREAK SPACE' (U+202F)
  • 'NO-BREAK SPACE' (U+00A0)

in order to avoid breaking long numbers due to automatic line wrap and word wrap.

@bnewbold
Copy link
Member

Finally revisiting this, and maybe I understand better.

The ordinal/non-ordinal distinction can be handled in the template, as opposed to trying to get babel's number formatting routine to figure it out. But the separators (etc) are best left to babel.

For the year, I can create a template that passes the 4-digit year through with no separator, but allows locale-specific wrapping of the year string; in this case adding a period in the template.

I will try to get these changes pushed soon.

@bnewbold
Copy link
Member

Most of the numbers should be fixed now. I believe that the year display will be fixed once the translation files are pulled from weblate; i'll keep this issue open until I do that (next week?) and confirm.

@bnewbold
Copy link
Member

Pushed updates, and they look correct to me (from a brief scan). @milotype if you get a chance, please verifiy and close this issue if it looks good. I'll close some time in the next week or two if I don't hear back.

Thanks! It was good to learn how to do this correctly, and should improve localization for all users.

@milotype
Copy link
Contributor Author

@bnewbold Your changes look good! But I found one more instance of the issue on the homepage (https://scholar-qa.archive.org/). Please see screenshot below.

Slika zaslona 2021-01-30 u 13 43 03

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

2 participants