This project is archived and is in readonly mode.
Customize I18n::MissingTranslationData
-
James Conroy-Finn
A custom exception handler needs to be defined on
I18nitself. The code in the guide is wrong.module I18n def self.custom_handler(exception, key, locale, options) # custom error handling logic end end I18n.exception_handler = :custom_handler…should do the trick.
-
James Conroy-Finn
By the way, if you use the
translateorthelper in any of your views your custom error handling will be bypassed because Rails specifies:raise => trueas an option when callingI18n.translate.The result of this option is that an exception is raised before your custom error handling method is called. Hopefully this is something that will change in Rails soon.
-
James Conroy-Finn
Really wish I could edit updates! I didn't read the last couple of paragraphs in you OP. Apologies.
-
Aditya Sanghi
- Assigned user set to José Valim
- Importance changed from to Low
@james, yes there are a few limitations on Lighthouse but apparently ENTP are working on a major update.
I know what you mean, with rails hardcoding a :raise => true preventing user handling of lookup errors.
Assigning to Jose for his input on this.
Ideally you could submit a patch with tests which could help speed up the process.
-
José Valim
James, do you think you can provide a patch to solve this issue?
-
Jérémie Horhant (Titinux)
I continued my investigation and I found a puzzling behavior of the translate/t methods.
- If you are in a controller calling translate/t will use "http://github.com/rails/rails/blob/master/actionpack/lib/abstract_c..." definition.
- If you are in a view calling translate/t will use "http://github.com/rails/rails/blob/master/actionpack/lib/action_vie..." definition.
- And if you call I18n.translate instead of translate it will use this one : "http://github.com/mattetti/i18n/blob/master/lib/i18n.rb"
These three implementations have different behaviors this is puzzling. The first one is just calling the third one but the second is doing a lot of work. The second is not perfect (not customizable and restrictive, cf the beginning of this ticket) but it doing some cool things (translation naming convention ending with _html or .html is really a good idea).
I know that I am just complaining but I'm new to rails and I'm afraid of not being able to produce a clean patch with tests. Eventually I could fix the documentation when changes have been made.
-
José Valim
- State changed from new to resolved
- Milestone set to 3.1
This has been changed and fixed in Rails master using the new I18n 0.5.0 API.