Skip to content

Instantly share code, notes, and snippets.

@ak-is-ok
Created April 25, 2014 09:43
Show Gist options
  • Save ak-is-ok/11283890 to your computer and use it in GitHub Desktop.
Save ak-is-ok/11283890 to your computer and use it in GitHub Desktop.
I18n lazy lookup in draper decorators
class ApplicationDecorator < Draper::Decorator
delegate_all
private
def translate(*args)
key = args.first
if key.is_a?(String) && (key[0] == '.')
underscored_scope = self.class.name.gsub('Decorator', '').underscore
args[0] = underscored_scope + key
end
I18n.translate(*args)
end
alias :t :translate
def localize(*args)
I18n.localize(*args)
end
alias :l :localize
end
MemberDecorator < ApplicationDecorator
def friends
t(".friends_gender") # key scope: 'member.friends_gender'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment