I'm also new to i18n and in the early stages of implementing a partial localization of my app to 5 languages. I haven't gotten this far yet, but I anticipated this issue after reading the usual blog posts. Just bumping the thread in case someone has something to add, I'll be back soon...
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 -~----------~----~----~----~------~----~------~--~---
