Normally, it's pretty easy in Rails to take advantage of the simple i18n tools provided. You just write I18n.t("some_key") and it'll translate that into whichever language.
Today, however, I discovered what seems like a problem. If you do I18n.t(""), it returns a hash of all possible translations! And if you give it a nil, it returns an error because that's not a key in the DB.
The first behavior doesn't sound correct at all, and the second seems dubious as well. I'm thinking about fixing it like so:
def translate(key, options = {}) return nil if key.nil? return "" if key == "" locale = options.delete(:locale) || I18n.locale backend.translate(locale, key, options) rescue I18n::ArgumentError => e raise e if options[:raise] send(@@exception_handler, e, locale, key, options) end
Is there any reason not to do this?