Localize date/time/datetime format according to local rules

Coming from Rails, we used to have the feature where we could specify date / time / timestamp formats in our translation files, and then use simple helper function to convert date/time/timestamp to current user’s locales using that template. We were also able to specify variants, say :short date format etc. The procedure is described here: https://guides.rubyonrails.org/i18n.html#adding-date-time-formats

Is there something in Elixir ecosystem, that I am not aware of, that allows us to have similar effect?

I think I could hack something like that myself, using gettext to store format strings, then a custom helper to fetch this string from gettext and format timestamps accordingly, but I was wondering if I missed something that’s doing it (possibly better) already in the ecosystem of libraries?

1 Like

Check out: https://github.com/kipcole9/cldr_dates_times#date-time-and-datetime-localization-formatting

I haven’t used it yet but this looks really comprehensive.

4 Likes

I’m using it and it’s really great. With ex_cldr and the cldr database backing it the level of availability and maintenance of formats is just unbeatable compared to any per project database.

1 Like

Here are the links to the packages in the ex_cldr family latest release. I can see the benefit to a tighter integration between Gettext and ex_cldr and would welcome any thoughts along those lines.

4 Likes

the whole bunch of libraries look like something I can definitely use. I will give it a try, thank you so much for doing it :heart:

1 Like