# String.to\_datetime doesn't translate the monthname

**URL:** <https://www.ruby-forum.com/t/string-to-datetime-doesnt-translate-the-monthname/215432>\
**Category:** Rails I18n\
**Created:** [January 4, 2012, 11:45am UTC](https://www.ruby-forum.com/t/string-to-datetime-doesnt-translate-the-monthname/215432 "2012-01-04T11:45:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 4, 2012, 11:45am UTC](https://www.ruby-forum.com/t/string-to-datetime-doesnt-translate-the-monthname/215432/1 "2012-01-04T11:45:14Z")

</div>

For example I have this translation file:

> <https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/it.yml>

And I’ve set:  
I18n.locale = :it

This works fine:  
I18n.localize Time.now → “Mer 04 Gen 2012, 11:26:17 +0100”  
“02 Novembre 2012”.to\_datetime =\> Fri, 02 Nov 2012 00:00:00 +0000

But this gives an invalid date:  
“02 Gennaio 2012”.to\_datetime

Date::MONTHNAMES returns:  
[nil, “January”, “February”, “March”, “April”, “May”, “June”, “July”,  
“August”, “September”, “October”, “November”, “December”]

The fastest way to solve this problem is to add the months to the YAML  
file and translate them into English months. Like this:  
Gennaio: January  
etc…  
Then I do:  
“02 #{I18n.t(Gennaio)} 2012”.to\_datetime =\> Mon, 02 Jan 2012 00:00:00  
+0000

But I was wondering if there is a more cleaner way so I can get it to  
work like this:  
“02 Gennaio 2012”.to\_datetime

---

<div class="post-metadata">

**Author:** ![jeroen\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jeroen\_v](https://www.ruby-forum.com/u/jeroen_v)\
**Post date:** [January 4, 2012, 11:52am UTC](https://www.ruby-forum.com/t/string-to-datetime-doesnt-translate-the-monthname/215432/2 "2012-01-04T11:52:59Z")

</div>

The question is “how to get a DateTime object from an Italian date  
string”?

---

<div class="post-metadata">

**Author:** ![jeroen\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jeroen\_v](https://www.ruby-forum.com/u/jeroen_v)\
**Post date:** [January 4, 2012, 12:12pm UTC](https://www.ruby-forum.com/t/string-to-datetime-doesnt-translate-the-monthname/215432/3 "2012-01-04T12:12:07Z")

</div>

Yup, that’s right

But even better: how to get a DateTime object from a date string where  
the language is other then English?

---

<div class="post-metadata">

**Author:** ![jeroen\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jeroen\_v](https://www.ruby-forum.com/u/jeroen_v)\
**Post date:** [September 12, 2013, 3:08pm UTC](https://www.ruby-forum.com/t/string-to-datetime-doesnt-translate-the-monthname/215432/4 "2013-09-12T15:08:03Z")

</div>

Basically you are looking for something like Chronic  
([GitHub - mojombo/chronic: Chronic is a pure Ruby natural language date parser.](https://github.com/mojombo/chronic)), but for Italien not English?

As far as I know Chronic only supports English, but if you are  
interested  
we could work on making it available to multiple languages. I think many  
Ruby devs would need something similar.
