Skip to content

Instantly share code, notes, and snippets.

@sdsantos
Created February 22, 2016 14:57
Show Gist options
  • Save sdsantos/aaf4c9ef33dab796530e to your computer and use it in GitHub Desktop.
Save sdsantos/aaf4c9ef33dab796530e to your computer and use it in GitHub Desktop.
Model translations helper
module ActiveRecord
class Base
def self.tp(attribute = nil)
if attribute
t(attribute).pluralize(I18n.locale)
else
t.pluralize(I18n.locale)
end
end
def self.t(attribute = nil)
if attribute
human_attribute_name(attribute)
else
model_name.human
end
end
end
end
@sdsantos
Copy link
Author

Helper for quick access of Model related translations.

Usage:

Post.t            // Artigo
Post.tp           // Artigos

Post.t  :title    // Título
Post.tp :title    // Títulos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment