I've just uploaded a plugin to do something similar to this, located at http://github.com/kipcole9/rails-i18n-translation-inheritance-helper/tree/master in case it helps.
Cheers, --Kip On Jan 13, 5:38 pm, dasil003 <[email protected]> wrote: > Eelco, > > After digging into the system I tend to agree with you. I don't see > why they're deleting :default. But since your approach would require > a core patch either way, I opted to just patch the core functionality > of the simple backend. I forked Sven's repo and applied it there. > > http://github.com/dasil003/i18n/commit/46e04b6a609bed252251694647b3c6... > > Maybe this will be useful to others. I think it would even be cool to > integrate, but I can see how it would have to be optional for those > cases where translations must be complete. What do you think i18n > guys? > > On Jan 3, 11:24 am, Eelco Lempsink <[email protected]> wrote: > > > Hi there, > > > I'm new to this group and new to i18n as well. When confronted with > > 'no translation found' messages after adding a couple of translations, > > I thought it would be nice to fall back to the :en locale when no > > message is found, at least in production. The messages are returned > > from the default exception handler, so I thought it would be easy > > enough to make an extension there and implement my own exception > > handler. > > > > def I18n.fallback(exception, locale, key, options) > > > if MissingTranslationData === exception > > > if not locale == :en > > > return I18n.translate(key, options.merge(:locale => :en)) > > > else > > > return exception.message > > > end > > > end > > > # else > > > raise exception > > > end > > > Unfortunately, this won't work for active record messages, since they > > rely on defaults being passed with the options and translate > > deletes :default from the options before it is passed to the generated > > exception (from i18n/backend/simple.rb): > > > > def translate(locale, key, options = {}) > > > ... > > > options.delete(:default) > > > ... > > > if entry.nil? > > > entry = default(locale, default, options) > > > if entry.nil? > > > raise(I18n::MissingTranslationData.new(locale, key, > > > options)) > > > end > > > end > > > ... > > > end > > > I think this is a bug, and the original options should be passed to > > the exception, including :default. But, maybe I'm just overlooking > > another easy way to solve this, or maybe there is a good > > reason :default is being deleted? > > > (By the way, I'm aware of Globalize2 offering a fallback option and I > > looked into the code, but it works by extending the backend and I > > would rather keep it as simple as possible and don't need Globalize2 > > for anything else (at the moment).) > > > I managed to work around it for now, but any hints for a clean and > > simple solution are more than welcome :) > > > -- > > Regards, > > > Eelco Lempsink > > > PGP.sig > > < 1KViewDownload --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
