Open Exoth opened 11 years ago
Now when this solution couldn't match the Thai February month name translation I decided to go even further and defined mmm like this:
months = I18n.available_locales.flat_map do |locale|
I18n.t('date.month_names', locale: locale) + I18n.t('date.abbr_month_names', locale: locale)
end
months.compact.uniq.map { |month| Regexp.escape(month) }.join('|')
and enabled case insensitive search. This way I'm guaranteed to match any possible month translation. But regexp is much bigger now and I don't know how it affects the performance. Anyway tell me if you find this solution suitable for the timeliness gem and I'll make a pull request.
Let's try the usual case:
So far everything is ok. But in fact there are a lot of locales, which have lowercase and long abbreviated month names, like 'octobre' and 'oct.' in French.
So that pull request fixes the month detection behavior to properly handle such situations.
And the second part is about regexp used for ddd and mmm formats.
Here's a simple code, checking how well the regexps perform against translations from all the locales found in the rails-i18n gem:
So there are quite a lot of misses. So far these are the best results I've managed to get by making minor changes to the regexps:
Much better already, though there are still some locales left, but they mostly involve multiword names, and this probably can't be fixed just by changing the format regexps. The way I see is to use the list of month/day names of the current locale at the stage of format processing.
Anyway, the pull request includes the changes in formats as specified above.