Created
April 25, 2014 09:43
-
-
Save ak-is-ok/11283890 to your computer and use it in GitHub Desktop.
I18n lazy lookup in draper decorators
This file contains 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 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 |
This file contains 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
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