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

feat: Use Babel for numbers and dates to support many locales #67

Merged
merged 9 commits into from
Oct 19, 2022

Conversation

DenverCoder1
Copy link
Owner

@DenverCoder1 DenverCoder1 commented Oct 16, 2022

Summary

closes #65

  • Uses Babel to translate numbers into a given locale (eg. "1.2K" => "1,2 k" in locale "fr")
  • Use Babel to translate relative time differences

This formats the compact numbers in the selected locale, for example:

image

Locales not yet translated, can now be used for number formatting and relative time difference, but the word "views" will remain in English until translated. For example:

image

Note
Compact number formats are not supported by any Babel formatters yet, but for now are implemented using the CLDR data from Babel according to the specifications at https://www.unicode.org/reports/tr35/tr35-45/tr35-numbers.html#Compact_Number_Formats.

Type of change

  • Bug fix (added a non-breaking change which fixes an issue)
  • New feature (added a non-breaking change which adds functionality)
  • Updated documentation (updated the readme, templates, or other repo files)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

  • Added or updated test cases to test new features

@DenverCoder1 DenverCoder1 added the feature New feature or request label Oct 16, 2022
@vercel
Copy link

vercel bot commented Oct 16, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
ytcards ✅ Ready (Inspect) Visit Preview Oct 19, 2022 at 10:42PM (UTC)

@DenverCoder1
Copy link
Owner Author

Hi @Vyvy-vi, do you mind if I ask your opinion on this? Also if you think the French translations look good after this change?

@Vyvy-vi
Copy link
Contributor

Vyvy-vi commented Oct 16, 2022

This looks good to me though I'd have to test this sometime later to check for different decimal formats.

Like - 10,000,000 (10 million) is equivalant to 1,00,00,000 (1 crore) when writen in Hindi.

The French translation looks right to me (though I'm not sure about the text for thousandth, millionth and billionth).

Also, I don't mind the ping.

@DenverCoder1
Copy link
Owner Author

Like - 10,000,000 (10 million) is equivalant to 1,00,00,000 (1 crore) when writen in Hindi.

That's an interesting thought. I suppose it's similar to how in Japanese and Chinese they use units of 10,000's (万 / mahn), eg. 3250万 = 32,500,000.

For now, all that is supported is thousands, millions, and billions. By default it will be K, M, and B (similar to English YouTube), but those letters can be overridden per locale.

Maybe at a later time, units other than the three metric ones can be supported, but I think it's fine as is for now and can be improved at a later time.

The French translation looks right to me (though I'm not sure about the text for thousandth, millionth and billionth).

As far as I can tell, it seems it gives the same results as French YouTube.com now which is the reason I chose those translations specifically.

Hindi and others currently will still display like the English numbers, besides , instead of . in some locales. The translations for those other languages that have different K, M, B can be updated in separate PRs.

@DenverCoder1
Copy link
Owner Author

DenverCoder1 commented Oct 19, 2022

It seems like the CLDR has support for compact numbers in 370+ locales which should fix the issue with Hindi, Japanese.

Babel implements the CLDR, but currently does not support compact numbers (python-babel/babel#908, PR in progress).

Babel does, however support localizing relative time difference, so we can simplify the translation files to just requiring "1 view" / "_ views" since everything else can be handled using CLDR data.

I think we should be able to switch things over to use Babel. Using the CLDR data imported by Babel, I can make a workaround to support compact numbers here before it's supported in Babel if the PR takes a while to get merged.

@DenverCoder1 DenverCoder1 changed the title feat: Support translating number formats feat: Use Babel for numbers and dates to support many locales Oct 19, 2022
@DenverCoder1 DenverCoder1 merged commit 2ab38ea into main Oct 19, 2022
@DenverCoder1 DenverCoder1 deleted the views-number-formats branch October 19, 2022 22:50
@DenverCoder1
Copy link
Owner Author

Hi @Vyvy-vi, I'd like a second opinion on this again if you don't mind.

So I ended up removing all the "time ago" translations in this PR in favor of a simpler solution of just letting Babel handle it.

I'm thinking now that it may be nice, at least for some languages, to be able to override the translations and only use Babel if no overrides are present.

It should be pretty simple to put all the translations back and implement it this way instead, but on the other hand, having fewer things for people to translate makes that aspect simpler and while the translations from Babel occasionally differ from YouTube, they are not bad at all.

So basically I'm stuck deciding whether to keep the implementation simple or make it more flexible with the drawback that it makes it more complex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 Feature: Support for translating thousands, millions, billions, etc
2 participants