Hi All,
It comes up quite a lot, and after much searching, I’ve not been able to
find a solution to handling dates in Gettext that I actually liked.
Overriding array constants inside various libraries and expecting things
to work didn’t do it for me.
So I made my own solution.
The attached gettext_date.rb file is a preview to try and get a bit of
feedback about the viability of this approach. Dates are messy, so I’m
expecting that my solution does not cover all the possible exceptions to
the basic rules I’ve defined.
It’s primarily designed for Ruby on Rails, but should work with any ruby
app, although the TimeExtensions is unnecessary.
To install, copy the gettext_date.rb file to your /lib directory, and
add the following line to your environment.rb:
require ‘lib/gettext_date’
Assuming you have every other part of Rails setup for Gettext, and
you’re .po files contain the translated month and day names, it should
“just work”. There is no need to add the .localize call to all your time
methods, and you can stick with the standard strftime calls. Its also
designed so that Time.now.to_s(:rfc822) or similar RFC calls will use
the standard ruby strftime method, and remain in english as the standard
requires.
The key advantage with my approach, is that if your application does not
use English as your native language, the GettextDate::Conversions class
can be overwritten with the names in the other language, therefore
removing any confusing language inconsistencies for the translators.
I’ll set up a web site as soon as possible with more details, but I’d
love to get some feedback! At least now Gettext fans don’t have to be
jealous of the Globalize crowd
Cheers, sam