Hi,

Of course you can define it yourself, even make it a bit more common:

def method_missing(method, *args)
  if method.to_s =~ /^find_by_\W+$/
    send(:"find_by_#{i18n_attr($1)}")
  else
    super
  end
end

def i18n_attr(attribute)
  I18n.fallbacks[I18n.locale].map{|tag| tag.to_s}.first
end

This needs to be cleared up, and tested and so on, it's just as an
illustration and out of the top of my head.

As for intercepting SQL generation, I would much rather see something like:

Post.all(:conditions => { i18n_attr(:title) => "baz" } )


or something like it. My prediction is that applying too much magic to
the find-method will break things in obscure places and scenarios. It
might be fine for what you are using, but probably not for a common
option in globalize.

Note that I haven't even begun to try to find something over multiple
translations.

Tip: To be sure that you've covered all instances it would be best to
run the Rails ActiveRecord test suite. (i.e. build it into Rails first
before extracting it into a plugin)

Hope this helps a bit,
Iain


On Mon, Jan 12, 2009 at 19:56, Sébastien Grosjean - ZenCocoon
<[email protected]> wrote:
>
> On 12 jan, 19:45, "Iain Hecker" <[email protected]> wrote:
>> Hi Sébastien,
>
> Hi Iain, so glad to ear from you.
>
>> Stuff like find_by_title might be done, but not so soon, since it's
>> rather complex to implement it properly.
>
> I've actually started to work on it, as actual model specific pacth
> this works for me:
>
> class << self
>  def find_by_title(title)
>    self.first(:joins => :globalize_translations,
>               :conditions => ["page_translations.title = :title AND
> page_translations.locale IN (:locales)",
>                              {:title => title, :locales =>
> I18n.fallbacks[I18n.locale].map{|tag| tag.to_s}}])
>  end
> end
>
>> The conditions like you describe are probably never going to happen.
>
> I've actually came to this point porting an existing application
>
>> To change this, we would need to monkeypatch Rails to not query it,
>> although it should. No sane programmer would attempt such a thing.
>> It's unmaintainable.
>
> Don't you think intercepting the SQL generation to replace translated
> column names (eg. title) by appropriate value (eg. page.title) would
> be fine and maintainable ?
>
>
> As usage I would fine awesome to keep using the translatable
> attributes as not translated.
> Makes sense ?
>
> Warm regards,
> --
>  Sebastien Grosjean - ZenCocoon
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"rails-i18n" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rails-i18n?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to