alexisszabo

alexisszabo

Agile Web Development with Rails 7: Suggestion to simplify Chapter 15 Task J: Internationalization

@rubys

A few suggestions for Chapter 15, Task J internationalization which will solve a few of the other open errata and simplify things slightly:

  1. Add the following code to application_controller.rb so that the locale is added by default when navigating:
  def default_url_options
    { locale: I18n.locale }
  end

and the corresponding code to test_helper.rb:

module ActionDispatch::Integration
  class Session
    def default_url_options
      { locale: I18n.locale }
    end
  end
end

We could then get rid of the locale: I18n.locale argument on the following pages:
Pg. 234: <%= button_to t('.checkout'), new_order_path(locale: I18n.locale),
Pg. 243: format.html { redirect_to store_index_url(locale: I18n.locale),
Pg. 243: assert_redirected_to store_index_url(locale: 'en')
Pg. 420: line_items_path(product_id: product, locale: I18n.locale),

It would also fix a couple of the open errata’s regarding the missing locale argument on other pages.

  1. Update the home link in the sidebar to be <li><%= link_to t('.home'), store_index_path %></li> so that Rails keeps the selected localization when this link is clicked.

  2. Modify the localization parameter in routes.rb as follows: scope '(:locale)', locale: /en|es/ do so that the other (not yet valid) questions / news / contacts links in the sidebar don’t get interpreted as locales.

  3. In Section J4, add the following CSS to application.css (or suitable file) so the language selector appears in the same spot as in the book’s image:

.locale {
  float: right;
  margin: 1em;
}

Where Next?

Popular Pragmatic Bookshelf topics Top

johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New
ianwillie
Hello Brian, I have some problems with running the code in your book. I like the style of the book very much and I have learnt a lot as...
New
jamis
The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New
mikecargal
Title: Hands-On Rust (Chapter 11: prefab) Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex&gt; product = %Product{} %Pento....
New
swlaschin
The book has the same “Problem space/Solution space” diagram on page 18 as is on page 17. The correct Problem/Solution space diagrams ar...
New
brunogirin
When installing Cards as an editable package, I get the following error: ERROR: File “setup.py” not found. Directory cannot be installe...
New
hazardco
On page 78 the following code appears: &lt;%= link_to ‘Destroy’, product, class: ‘hover:underline’, method: :delete, data: { confirm...
New
ggerico
I got this error when executing the plot files on macOS Ventura 13.0.1 with Python 3.10.8 and matplotlib 3.6.1: programming_ML/code/03_...
New
SlowburnAZ
Getting an error when installing the dependencies at the start of this chapter: could not compile dependency :exla, "mix compile" failed...
New

Other popular topics Top

PragmaticBookshelf
A PragProg Hero’s Journey with Brian P. Hogan @bphogan Have you ever worried that your only legacy will be in the form of legacy...
New
Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1139 25478 754
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New
sir.laksmana_wenk
I’m able to do the “artistic” part of game-development; character designing/modeling, music, environment modeling, etc. However, I don’t...
New
AstonJ
If you’re getting errors like this: psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
New

Latest in Agile Web Development with Rails 7

Agile Web Development with Rails 7 Portal

Sub Categories: