Created
December 20, 2011 19:57
-
-
Save no-dashes/1502996 to your computer and use it in GitHub Desktop.
localization games
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
# 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