Created
May 4, 2011 13:06
-
-
Save nicolasblanco/955175 to your computer and use it in GitHub Desktop.
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
# Sends the translated version of a given object attribute. | |
# | |
# Example: | |
# Given that locale is :fr | |
# t_attribute(@post, :description) | |
# will return @post.description_fr or fallback to @post.description. | |
def t_attribute(object, attribute) | |
localized_attribute = "#{attribute}_#{I18n.locale}" | |
object.respond_to?(localized_attribute) ? object.send(localized_attribute) : object.send(attribute) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment