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;
}
0 239 0

Where Next?

Popular Pragmatic Bookshelf topics Top

telemachus
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks” While running the smoke tests in Chapter 2, I get these...
5 2075 1
New
jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
8 1923 7
New
GilWright
Working through the steps (checking that the Info,plist matches exactly), run the demo game and what appears is grey but does not fill th...
11 1077 5
New
mikecargal
Title: Hands-on Rust: question about get_component (page 295) (feel free to respond. “You dug you’re own hole… good luck”) I have somet...
1 1160 5
New
adamwoolhether
I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
5 1406 5
New
New
oaklandgit
Hi, I completed chapter 6 but am getting the following error when running: thread 'main' panicked at 'Failed to load texture: IoError(O...
2 1303 3
New
adamwoolhether
Is there any place where we can discuss the solutions to some of the exercises? I can figure most of them out, but am having trouble with...
17 1372 9
New
taguniversalmachine
It seems the second code snippet is missing the code to set the current_user: current_user: Accounts.get_user_by_session_token(session["...
0 1879 8
New
tkhobbes
After some hassle, I was able to finally run bin/setup, now I have started the rails server but I get this error message right when I vis...
0 1460 5
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1033 17470 383
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
177 8632 77
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
166 7775 69
New
AstonJ
Saw this on TikTok of all places! :lol: Anyone heard of them before? Lite:
13 3957 4
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
108 9152 31
New
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
8 3528 3
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
31 3800 16
New
DevotionGeo
I have always used antique keyboards like Cherry MX 1800 or Cherry MX 8100 and almost always have modified the switches in some way, like...
27 2843 9
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
37 3237 14
New

Latest in Agile Web Development with Rails 7

Agile Web Development with Rails 7 Portal

Sub Categories: