Iteration J2: Translating the Storefront

Now it’s time to begin providing the translated text. Let’s start with the layout since 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:

 <!DOCTYPE html>
 <html>
  <head>
  <title>Pragprog Books Online Store</title>
  <meta name=​"viewport"​ content=​"width=device-width,initial-scale=1" ...

Get Agile Web Development with Rails 7 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.