Skip to content

Instantly share code, notes, and snippets.

@no-dashes
Created December 20, 2011 19:57
Show Gist options
  • Save no-dashes/1502996 to your computer and use it in GitHub Desktop.
Save no-dashes/1502996 to your computer and use it in GitHub Desktop.
localization games
# First, I put this into the application helper
module ApplicationHelper
class T
instance_methods.each { |m| undef_method m unless m =~ /^((object_id$)|(__))/ }
def method_missing(sym, *args, &block)
@str = @str ? "#{@str}.#{sym}" : sym.to_s
self
end
def to_s() I18n.translate(@str) end
end
def tt() T.new end
# ... further stuff
end
#-------------------------------
# and then, in the views
# we get
<%= tt.activerecord.attributes.customer.firstname %>
Vorname
<% t2 = tt.activerecord.attributes.customer %>
<%= t2.firstname %>
<%= t2.lastname %>
Vorname
Nachname
<%= tt.foo.bar.firstname %>
translation missing: de.foo.bar.firstname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment