Iteration K2: Translating the Storefront

Now it’s time to begin providing the translated text. Let’s start with the layout, because it’s pretty visible. We replace any text that needs to be translated with calls to I18n.translate. Not only is this method conveniently aliased as I18n.t, but a helper named t is provided.

The parameter to the translate function is a unique dot-qualified name. We can choose any name we like, but if we use the t helper function provided, names that start with a dot will first be expanded using the name of the template. So, let’s do that:

  <nav class=​"side_nav"​>
 
  <div id=​"cart"​ class=​"carts"​>
 
 <%=​ render_if @cart && @cart.line_items.any?, @cart ...

Get Agile Web Development with Rails 5.1 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.