Skip to content

Instantly share code, notes, and snippets.

@moretea
Created October 11, 2012 09:55
Show Gist options
  • Save moretea/3871345 to your computer and use it in GitHub Desktop.
Save moretea/3871345 to your computer and use it in GitHub Desktop.
Idea about I18n edit in websites
class I18n
method_alias_chain :translate, :helper
DEFAULTMEHOPTIONS= {helper: true}
def translate_with_helper key, options
options = DEFAULTMEHOPTIONS.merge(options)
txt = translate_without_helper key, options
if not session[:translating]
txt
else
if options[:helper]
"<span class='translateable' data-key='#{key}'>#{txt}</span>"
else
txt += " (#{key})"
end
end
txt
end
end
button_tag t(".is_it_nice", helper: false) #=> <button>It is nice (path.to.scope.it_is_nice)</button>
link_to t(".home") #=> <a> <span class='translateable' data-key='path.to.scope.home'>Home</span></a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment