Created
January 3, 2012 21:57
-
-
Save jpowell/1557158 to your computer and use it in GitHub Desktop.
I18n scoped wrapper for rails & ActiveRecord
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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