Skip to content

Instantly share code, notes, and snippets.

@josephj
Created January 22, 2014 06:32
Show Gist options
  • Save josephj/8554328 to your computer and use it in GitHub Desktop.
Save josephj/8554328 to your computer and use it in GitHub Desktop.
module TranslationHelper
def trans(key, options = {})
root_path = "#{Dir.pwd}/app/views/"
path = caller.first.sub(root_path, '').split(':')[0]
extension = '.html.erb'
segments = path.sub(extension, '').split('/')
segments.map! do |segment|
(segment.index('_') == 0) ? segment.sub('_', '') : segment
end
translate("#{segments.join('.')}.#{key}", options)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment