Hello, a) yes, you could force loading locales like that, probably, or this should work: `I18n.backend.send(:init_translations)` (I am not 100% sure if this is uptodate. It *was* for a long long time :)
b) any reason, why you're not using standard Rails i18n mechanism for declaring validation messages? Ie. in the dictionaries, see http://guides.rails.info/i18n.html#translations-for-active-record-models Karel On Apr 24, 8:42 am, Pat Allan <[email protected]> wrote: > On re-reading emails from RailsConf, I think I don't need to get those > slides and such done until the actual conference, it's just materials > attendees should have before the day. ie: Sphinx source and Thinking > Sphinx. Much easier to take care of, so I've put that aside, and dug > into the ActiveSupport source... > > While I18n loads the YAML files before Thinking Sphinx loads, it > doesn't process them automatically. Lazy loading if you like, just > like how Rails normally behaves with modesl... except then TS loads > the model forcibly, without the YAML parsing being considered > 'complete'. > > I guess one quick way of forcing it, in vendor/plugins/thinking_sphinx/ > rails/init.rb, add this line inside the block, before the load_models > call: > I18n.available_locales > > Which *should* force the full loading. > > It's not ideal, and I'd love some better ideas on how to approach > this, but hopefully it'll do the job for the moment. > > -- > Pat > > On 24/04/2009, at 3:42 PM, Pat Allan wrote: > > > Hi Mark > > > Definitely sounds like something to do with the order of loading > > (and yes, your demo app fails for me too). I'm *supposed* to be > > sorting out my RailsConf tutorial content at the moment, so I really > > shouldn't spend time digging into this at the moment. > > > But, a vague description of my approach: go hunting through Rails > > source, find out when the environment is prepared (ie: when TS > > manually reloads models), and when the I18n YAML file is parsed. I'm > > assuming the former happens before the latter, and it really should > > be the other way around... so if there's some later event hook we > > can tie the TS loading to, that'd hopefully make things better. > > > -- > > Pat > > > On 24/04/2009, at 2:37 PM, DrMark wrote: > > >> Ok. I have identified an I18N issue caused by ThinkingSphinx and I > >> would appreciate thoughts on what is causing the issue. It has driven > >> me crazy all day. The problem wasn't obvious due to a large number of > >> recent changes in my app, but I have finally tracked the problem to > >> ThinkingSphinx. > > >> I use TS in my app and I use i18n extensively in a large app. I > >> upgraded to the latest TS a short while ago (I was running my fork > >> but > >> switched to the main one). When running my unit tests today, many of > >> my validation tests started failing with messages about "translation > >> missing". This is odd because all of my tests had been passing. > > >> After many hours of debugging I have shown that TS is causing the > >> problem. I have created a sample application that demonstrates the > >> problem. (http://files.me.com/drmarklane/rrxgcm) > > >> In the sample app I have a simple User model with the following > >> sample > >> validations: > > >> validates_presence_of :first_name, > >> :message => I18n.t > >> ('users.errors.first_name_cant_be_blank') > >> validates_format_of :last_name, :with=>/[^ \t\n\r\f\v ]/, > >> :message=>"#{I18n.t > >> ('users.errors.last_name_wrong_format')}" > > >> if you log in to the console then do: > >>>> u = User.new > >> => #<User id: nil, first_name: nil, last_name: nil, created_at: nil, > >> updated_at: nil> > >>>> u.valid? > >> => false > >>>> u.errors > >> => #<ActiveRecord::Errors:0x21d0f2c @errors={"first_name"=> > >> ["translation missing: en, users, errors, first_name_cant_be_blank"], > >> "last_name"=>["translation missing: en, users, errors, > >> last_name_wrong_format"]}, @base=#<User id: nil, first_name: nil, > >> last_name: nil, created_at: nil, updated_at: nil>> > > >> Notice the "translation missing" errors in the errors hash. Any unit > >> tests will also fail because of the translation missing errors. > >> Adding > >> default i18n settings in config.rb doesn't help. > > >> If you remove ThinkingSphinx, log out of the console, then repeat the > >> above steps you will get: > > >>>> u = User.new > >> => #<User id: nil, first_name: nil, last_name: nil, created_at: nil, > >> updated_at: nil> > >>>> u.valid? > >> => false > >>>> u.errors > >> => #<ActiveRecord::Errors:0x2357da0 @errors={"first_name"=>["Your > >> first name can't be blank"], "last_name"=>["Your first name is the > >> wrong format"]}, @base=#<User id: nil, first_name: nil, last_name: > >> nil, created_at: nil, updated_at: nil>> > > >> which is correct. Note that TS is not even called in the sample app. > >> Simply placing TS in the plugins folder causes the problem. > > >> Does anyone have any ideas as to the cause of this issue? I think the > >> issue is related to the class loading by TS. I would appreciate your > >> advice. > > >> Thanks! > > >> DrMark > > >> PS. Pat, your copy of not-a-mock doesn't build unless you set the gem > >> version of Rails to 2.2.2 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Thinking Sphinx" 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/thinking-sphinx?hl=en -~----------~----~----~----~------~----~------~--~---
