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

Improve/fix registration status icon text #10527

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kr-matthews
Copy link
Contributor

This competition is in just over a month. Previously it also said "in 1 month".

image

This competition is tomorrow. Previously it would have said "in 2 hours".

image

Unfortunately Luxon doesn't seem to be using the locale, so that will need to be fixed if possible (in another PR). Also, other languages have the extra "in" too, it seems (and missing periods).

image

@kr-matthews kr-matthews self-assigned this Jan 4, 2025
@kr-matthews
Copy link
Contributor Author

Actually these strings are also used in the 'all competitions' page (both the old and new UI), so this PR just shifts the extra 'in' problem. However, that page is correctly translating the 'days' message. So we probably want a consistent approach between the two - using luxon in both (with correct locale), or explicitly calculating the number of days and directly translating that (note this never would show "1 month", it's always days). For the former approach, I'm not sure how to make those changes in ruby, so someone else would have to pick this up.

@kr-matthews kr-matthews marked this pull request as draft January 4, 2025 06:09
Copy link
Member

@gregorbg gregorbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments about locale handling

if (competition.registration_status === 'not_yet_opened') {
return I18n.t('competitions.index.tooltips.registration.opens_in', { duration: DateTime.fromISO(competition.registration_open).toRelative() });
return I18n.t('competitions.index.tooltips.registration.opens_in', { duration: DateTime.fromISO(competition.registration_open).toRelative(toRelativeOptions) });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in terms of Luxon respecting the locale, it's (supposed to be) as simple as passing the locale ISO code to fromISO like so: DateTime.fromISO(dateIsoString, { locale: 'fr' }). Cf. https://moment.github.io/luxon/#/intl?id=setting-the-locale

We expose the currently seleted locale as I18n.locale on the same I18n object that also does t and tArray.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, even the toRelativeOptions object supports a locale key.

}
if (competition.registration_status === 'past') {
return I18n.t('competitions.index.tooltips.registration.closed', { days: DateTime.fromISO(competition.start_date).toRelative() });
return I18n.t('competitions.index.tooltips.registration.closed', { days: DateTime.fromISO(competition.start_date).toRelative(toRelativeOptions) });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above for passing locale information to Luxon

@gregorbg
Copy link
Member

gregorbg commented Jan 4, 2025

About the handling of in: This is a "devil or the deep blue sea" scenario. Luxon does have luxonDt.diffNow().toHuman() method, which (with a little bit of fiddling in terms of passing in the correct config options) would boil down to 3 days, 8 hours without the "in".

However, for most languages there's a notable difference because of grammar. In German for example, if you just enumerate the time units in a "raw" fashion, it's 6 Monate, 3 Tage (six months and three days). In case of a relative time difference, as in "the event happens in 6 months and 3 days" you'd have to change the noun declension to in 6 Monate**n** und 3 Tage**n**.

So I personally feel like it's best to let the Luxon library handle the "in" and "ago" and nasty declensions, and remove them from our translatable I18n keys like you did here.

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

Successfully merging this pull request may close these issues.

2 participants