weewar.com corner

Translating day and month names in Ruby

Posted by alex on May 24, 2007

A few days ago, I ran into a problem translating the day and monthnames in the ruby “Date” class. The howtos I read recommended using replace to modify the array constants. That did not work, because these days, those arrays are frozen, making them immutable.

My first solution was to just comment out the part, where the arrays are frozen, but then everyone working on the code has to fiddle with the core ruby installation. Not a very clean solution.

Luckily, I found the remove_const method. Using that, the constants in Date can be easily exchanged for the translated version:

Date.send(:remove_const, "ABBR_DAYNAMES") Date.const_set("ABBR_DAYNAMES", [ _("sun"), _("mon"), _("tue"), _("wed"), _("thu"), _("fri"), _("sat") ]) Date.send(:remove_const, "DAYNAMES") Date.const_set("DAYNAMES", [_("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday") ]) Date.send(:remove_const, "ABBR_MONTHNAMES") Date.const_set("ABBR_MONTHNAMES", [nil, _("Jan"), _("Feb"), _("Mar"), _("Apr"), _("May"), _("Jun"), _("Jul"),_("Aug"),_("Sep"), _("Oct"), _("Nov"), _("Dec") ]) Date.send(:remove_const, "MONTHNAMES") Date.const_set("MONTHNAMES", [nil, _("January"), _("February"), _("March"), _("April"), _("May"), _("June"), _("July"),_("August"),_("September"), _("October"), _("November"), _("December") ])

Almost. Best. Mail. Ever.

Posted by alex on March 22, 2006

Your order for The Elder Scrolls IV: Oblivion (Collector’s Edition) has been posted.

Sweet!

Please allow 3-5 days delivery.

Bummer

Random thought of the day

Posted by alex on January 16, 2006

“What the fuck is wrong with you people?”

Ihre Amazon.de Bestellung wurde versandt 1

Posted by alex on November 08, 2005

SingsStar 80's

I can’t hardly wait.

So much for blogging

Posted by alex on September 25, 2005

Blogging has become way too mainstream.

In three different episodes of three different shows, one of the characters made a reference to blogging. The first one was “How I met your mother”, where Barney says “This is totally going in my blog”.

I don’t remember what the other two shows were, probably “The War at Home” and “The Showbiz Show”, but I think blogging is about to jump the shark…

Lucky for me this isn’t a blog. It gets updated not nearly enough to qualify ;)

Finally on Typo

Posted by alex on September 18, 2005

I finally made the move to Typo.

Since I am planning on doing some typo hacking, I first set up a svk environment, as described by Scott Laird.

At the moment, this blog is still mostly “out-of-the-box”, but at least now there’s some “tangible” code to hack on.

BTW: I just noticed, that MarsEdit can preview Markdown. That’s some sweet program.