Forum: Ruby on Rails Extending AR::B to provide translations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Nickolay K. (Guest)
on 2005-12-18 02:41
(Received via mailing list)
Hi all,

I want to extend AR::B is such a way as to be able to support and
display different language versions of objects. I know of and have
tried Globalize but still want to do this on my own for a multitude
of reasons (the educational value probably being most important).

My table for the objects has columns named like en_name, de_name,
fr_name, en_description, de_description, fr_description and so on.

I plan to write method_missing for AR::B like this:

class AR::B
   def method_missing(method_name)
     self.send((current_lang + method_name.to_s).to_sym)
   end
end

so that when I call obj.name it will return de_name or en_name or
whatever based on the current language setting.

The language will be set as part of the request url. I can write a
before_filter for the ApplicationController and get the value (de,
en, whatever) out of the request url. How do I tell AR::B what the
current language is? I obviously cannot set a class variable, so it
would have to be session based I suppose.

Many thanks in advance,
Nickolay
This topic is locked and can not be replied to.