kennethreitz / maya

Datetimes for Humans™
MIT License
3.41k stars 197 forks source link

Allow slang methods to change locale #154

Closed alxwrd closed 6 years ago

alxwrd commented 6 years ago

This attempts to add internationalisation/localisation to the slang_ methods to address #84.

I originally attempted to use the localisation built into humanize. However, I had the issue that the last release for humanize was in 2014, and at the time it only supported 3 locales.

Because of this, I switched to using pendulum which has a much bigger locale selection.

However, pendulum only has diff_for_humans() which is for time. This leaves slang_date without localisation.

I think the questions that are left are:

timofurrer commented 6 years ago

I see some problems when would use pendulums diff_from_humans() for those simple slang methods, as it just gives as a plain datetime diff, but doesn't care if it's about the date or time.

Maybe we could instead use pendulums format to provide an easy way to localize a MayaDT instance given a specific format?

alxwrd commented 6 years ago

@timofurrer Sorry I hadn't done slang_date yet as I was unsure of how to proceed.

I think humanize is not an option to use for localisation because it seems to have gone stale (last commit Dec 2016), and it's current release (2014) only has 3 localisations.

If we use pendulums format for slang_date, we lose 'yesterday', 'today', and 'tomorrow' as pendulum doesn't have support for this. I think that would be a shame.

The options I can see to fully have internationalisation:

  1. Try and restart humanize. Contact the owner about updating/adding collaborator, or a fork?
  2. Use humanize as is, but only get 3 locales.
  3. Suggest the addition of date_for_humans() for pendulum.
  4. Use pendulum as is, but lose 'yesterday', 'today', and 'tomorrow'.
alxwrd commented 6 years ago

@timofurrer I've added localisation for slang_date if you could let me know what you think.

I've used a mix of pendulums .format() and the translation data from dateparser. This has allowed both "today, tomorrow, yesterday", and dates like "25 Mai".

timofurrer commented 6 years ago

@alxwrd sorry for the delay. Looks good to me. Do you mind adding some tests for the i18n features?

alxwrd commented 6 years ago

@timofurrer no worries.

I've just pushed some tests. I think this now closes #84? I can't see anything else that would need internationalisation? All the other Maya methods are for iso.

timofurrer commented 6 years ago

Awesome! Thanks for the contribution! :tada: