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
on 31.10.2007 12:25
on 31.10.2007 14:01
Forgot to mention, the _( ) method needs to be accessible to the
GettextDate library, a quick fix for this is to add the following in
/config/environment.rb just after the 'gettext/rails' require.
include GetText::Rails
bindtextdomain('DOMAIN')
require 'lib/gettext_date'
DOMAIN should be replaced with your current application domain. This
approach provides the _( ) method for everything, and duplicates the
init_gettext call, which is a bit lame, so I'll work on doing it another
way. Good for testing though!
Cheers,
sam
on 31.10.2007 14:41
Samuel Lown wrote: > > include GetText::Rails > bindtextdomain('DOMAIN') > require 'lib/gettext_date' > Scrap that, use this version instead, which automatically extends the ActionController::Base with a version of init_gettext that adds the text domain to the Conversions: http://www.samlown.com/uploads/ruby/gettext_date.rb sam.