i18n_backend_database icon indicating copy to clipboard operation
i18n_backend_database copied to clipboard

rake i18n:populate:all causes interpolation argument errors missing in "Validation failed: {{errors}}"

Open jduff opened this issue 15 years ago • 5 comments

We're running Rails 2.3.5, not sure if something changed in there. The problem has to do with some of the stuff in this commit http://github.com/dylanz/i18n_backend_database/commit/e1faa3f384daf26b2809aadfdb4f86569615497f

What I was seeing is the object that was being scanned for interpolation arguments looking something like this: "'activerecord.errors.messages.record_invalid', :errors=>errors"

and not being able to parse out the fact that it needs an errors option. My regex_fu is limited so I haven't been able to come up with something better.

jduff avatar Dec 02 '09 20:12 jduff

Hello Jay! Could you show me a way to reproduce? I just created a blank 2.3.5 application, ran the tasks, created a model, and wasn't able to find any issues.

id: 93, raw_key: activerecord.errors.template.body, value: There were problems with the following fields: id: 94, raw_key: activerecord.errors.template.header, value: 1 error prohibited this {{model}} from being saved id: 95, raw_key: activerecord.errors.template.header, value: {{count}} errors prohibited this {{model}} from being saved

It seems like it grabbed those correctly. Shoot me an example, maybe console output if you can, and I'll be happy to help!

dylanz avatar Dec 04 '09 04:12 dylanz

If you add a call to the translate method that looks something like this: I18n.t('activerecord.errors.messages.record_invalid', :errors => errors) The rake task fails.

This could be a bit of an edge case, I'm not really sure.

jduff avatar Dec 07 '09 03:12 jduff

I just ran this command in console, and it worked fine:

I18n.t('activerecord.errors.messages.record_invalid', :errors => "test test test") => "Validation failed: test test test"

Then, I ran the "rake i18n:populate:all", and it ran without any errors.

Are there any more details you can provide? Can you show me what you database records look like?

dylanz avatar Dec 08 '09 18:12 dylanz

Doing that in the console and then running the rake task will do nothing since the task parses the application files to look for those calls. Drop that call into your app anywhere (view, controller, model) then running the rake task will fail.

Personally I don't really like the rake tasks and think it would be better to have a hook in the actual I18n.t call, if no translation is found it puts it into the database instead of parsing the files. Does that make sense?

jduff avatar Dec 08 '09 19:12 jduff

Perfect, I was able to replicate. The regular expression within the actual rake task is not pulling in the interpolation arguments it seems, which is a problem.

In regard to the rake tasks, you don't need to run them, and by default, if a translation does not exist for a given key, it is created. The rake tasks act as a way to bootstrap existing applications. For example, the application this was created for has many views that can be in many states, so manually triggering each translation was not an option. Using the tasks, we were able to auto-create about 10k+ translations that the translators could start working on immediately.

Thanks again for the heads up on this!

dylanz avatar Dec 08 '09 19:12 dylanz