TandaHQ / stamp-l10n

Stamp :lion:
MIT License
0 stars 0 forks source link

This isn't actually solving US problems as well as I thought it would #1

Open ghiculescu opened 7 years ago

ghiculescu commented 7 years ago

Here's a problem I'm coming up against a lot:

image

In the US, the dates should show up as "03/13 - 03/19". Another example is in the page title:

image

l_stamp isn't helping with this yet, because while it would translate the "Mar" to something else if I was in France, it won't change the format that stamp is given.

Rails has support for this built in, you can customise your localisation formats http://guides.rubyonrails.org/i18n.html#adding-date-time-formats and then you can call I18n.l(Date.new(2017, 3, 13), format: :short) (in fact, this one's a builtin).

So the challenge is designing an API for l_stamp that will let us do both. My goal is to be able to do:

I18n.format = 'en-AU'
Date.new(2017, 3, 13).l_stamp("13 Mar") # => "13 Mar"
I18n.format = 'en-US'
Date.new(2017, 3, 13).l_stamp("13 Mar") # => "Mar 13"
I18n.format = 'fr'
Date.new(2017, 3, 13).l_stamp("13 Mar") # => "13 mar."

I18n.l(Date.new(2013, 3, 13), format: :short, locale: 'fr') does what I want, so the challenge is basically if we can do this but with stamp-like formats.

daveallie commented 7 years ago

Interesting concept, there are only a few I18n defined date formats, but it should be possible to reorder emitters based on the format in I18n, if the current emitter pattern matches a format.

i.e.

I18n.format = 'en-AU'
Date.new(2017, 3, 13).l_stamp("13 Mar") # => "13 Mar"
Date.new(2017, 3, 13).l_stamp("Mar 13") # => "13 Mar"
Date.new(2017, 3, 13).l_stamp("March 13") # => "March 13"  --  Doesn't match a format
Date.new(2017, 3, 13).l_stamp("2017-31-12") # => "2017-12-31"
Date.new(2017, 3, 13).l_stamp("March 13, 2013") # => "13 March, 2017"
Date.new(2017, 3, 13).l_stamp("March 13 2013") # => "March 13 2017"  --  Doesn't match a format

For the lines that don't match a format, the ordering wasn't changed.

Would something like this suffice?

ghiculescu commented 7 years ago

Yeah I think that would work.