Skip to content

Instantly share code, notes, and snippets.

@jpowell
Created January 3, 2012 21:57
Show Gist options
  • Save jpowell/1557158 to your computer and use it in GitHub Desktop.
Save jpowell/1557158 to your computer and use it in GitHub Desktop.
I18n scoped wrapper for rails & ActiveRecord
class TranslationUtility
attr_accessor :options
def initialize scope_or_object, opts={}
@options = {
:scope => get_scope(scope_or_object),
:raise => true
}.merge(opts)
end
def method_missing *args
translate args.first
end
def translate key
I18n.translate key, options
end
alias_method :t, :translate
protected
def get_scope arg
arg.kind_of?(ActiveRecord::Base) ? arg.class : arg
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment