Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first working attempt to extend I18n module

  • Loading branch information...
commit 95f60861831b55790e42e70bba371669ded19ee6 1 parent 10971f6
@gnagno authored
View
22 lib/lost-i18n-translation/i18n_ext.rb
@@ -1,19 +1,31 @@
+module I18n
+ class << self
+ alias :old_translate :translate
+ end
+end
+
module ActionView::Helpers::TranslationHelper
alias :t_old :t
def add_span str
#TODO: add the title part, this will be used to identify the string
- "<span class=\"translation_present\">#{str}</span>".html_safe
+ "<span class=\"translation_present\" title=\"translation present:\">#{str}</span>".html_safe
+ end
+
+ class String
+ def add_span
+ "<span class=\"translation_present\">#{str}</span>".html_safe
+ end
end
def t(*args)
r = /<span class="translation_missing" title="translation missing:/
- str = t_old(args)
+ translation = t_old(args)
- if str =~ r
- return str
+ if translation =~ r
+ return translation
else
- add_span str
+ add_span translation.first
end
end
end
View
3  spec/dummy/app/views/home/index.html.erb
@@ -1,6 +1,7 @@
<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>
-<%= t 'test' %><br />
+<%= t "prova.test" %><br />
+<%= t "blog.post.title" %><br />
<%= t 'hello' %>
<% 6.times do -%>
<%= render 'lorem' %>
Please sign in to comment.
Something went wrong with that request. Please try again.