[Rails-core] Localization ideas/proposal

Tobias Luetke
Mon, 07 Nov 2005 23:49:10 -0000

I think you hit the nail on the head in the first few paragraphs of
your mail where you list your specific requirements which are unlike
the way other people solved the problem  which presumably solved their
problems fine.

Localization is application and requirement specific. I believe that a
plugin would be the right place for such code.
There could be a rails endorsed Localization plugin if there will be a
generally agreed upon golden way to do it of course...

On 11/7/05, Kyle Maxwell <kyle@kylemaxwell.com>
wrote:
> So far all I''ve seen from the Rails community, with respect to
> internationalization or localization have been gettext ports.
>
> This doesn''t help me much, as I have two problems:
> 1. All of my text is in the database, and I prefer to keep it there.
> 2. I need different view code for different languages.
>
> Below is the solution I am proposing.  I am willing to do most/all of
> the legwork in the near future (next few weeks).  I''m not trying
to
> sneak this into 1.0 or something; I''m just looking for someone in
the
> core team to review this and give it his/her blessing, or possibly,
> say that its an overworked pile of crap.  I know localization was a
> point of empahasis for 1.0, but I haven''t seen any indication that
it
> ever was finished.
>
> This solution has multiple parts.
> 0. General
> 1. Gettext
> 2. ActionPack changes
> 3. ActiveRecord changes
>
> -- General --
> def ActionController.set_locale(locale_code) ..
> def ActionController.get_locale ..
> Also, there would be a global variable like $L to retrieve the locale
> code from.  The locales would be stored in a AR model called Locale.
> It would have a singleton method "current."
> AC.get_locale == $L == Locale.current.code
>
> It''s possible that Locale would use a yaml/csv fixture as the data
> store, rather than a database table
>
> -- Gettext --
> Someone else''s gettext port will be adapted to fit this system,
and
> work where other methods are not preferred.
>
> -- ActionPack changes --
> Modify the render method so that if $L != nil, it will look for
> template_name_#{$L}.rhtml, then if not found, template_name.rhtml,
> then if not found, error.  It would also look for localized layouts
> and partials.
>
> -- ActiveRecord changes --
> A model can have a magic "locale" field (similar to created_on),
that
> will (possibly with a acts_as_localized declaration) set up a Locale
> has_many :models (and Model belongs_to :locale) relationship.
> Model.find will use Locale.current.models.find, and Model.new will
> inject the current locale automatically.
>
> Thanks a lot,
> Kyle Maxwell
> _______________________________________________
> Rails-core mailing list
> Rails-core@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-core
>


--
Tobi
http://jadedpixel.com    - modern e-commerce software
http://typo.leetsoft.com - Open source weblog engine
http://blog.leetsoft.com - Technical weblog