Skip to content
svenfuchs edited this page Sep 13, 2010 · 3 revisions

Ideas

1. Spice up the #translate helper by passing results to arbitrary helpers:


# setup
Globalize.format_view_translations do |translation|
  c = ["translation", "locale-#{translation.locale}"]
  c += ["fallback", "requested_locale-#{translation.requested_locale}"] if translation.fallback?
  content_tag 'span', translation, :class => c.join(' ')
end

# use
<%= t :foo %>

# output
<span class="translation locale-en fallback requested_locale-de-DE">Foo</span>

2. It’s always possible to use activesupport `with_options`:


<% I18n.with_options :scope => [:foo, :bar] |locale| %>
  <%= locale.t :baz %>
<% end %>

But it might be helpful to make this a little shorter:


<% Globalize.with_options :scope => [:foo, :bar] do %>
  <%= t :baz %>
<% end %>
Clone this wiki locally