Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jduff opened this issue Dec 2, 2009 · 5 comments

Comments

@jduff
Copy link

jduff commented Dec 2, 2009

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.

@dylanz
Copy link
Owner

dylanz commented Dec 4, 2009

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!

@jduff
Copy link
Author

jduff commented Dec 7, 2009

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.

@dylanz
Copy link
Owner

dylanz commented Dec 8, 2009

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?

@jduff
Copy link
Author

jduff commented Dec 8, 2009

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?

@dylanz
Copy link
Owner

dylanz commented Dec 8, 2009

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants