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

Popular Pragmatic Bookshelf topics Top

kuroneko
Whilst the author has been careful to provide exact results for the tests elsewhere in the book (such as surds with the transformation te...
New
telemachus
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks” While running the smoke tests in Chapter 2, I get these...
New
jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
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
Chrichton
Dear Sophie. I tried to do the “Authorization” exercise and have two questions: When trying to plug in an email-service, I found the ...
New
AndyDavis3416
@noelrappin Running the webpack dev server, I receive the following warning: ERROR in tsconfig.json TS18003: No inputs were found in c...
New
New
New
Henrai
Hi, I’m working on the Chapter 8 of the book. After I add add the point_offset, I’m still able to see acne: In the image above, I re...
New
mcpierce
@mfazio23 I’ve applied the changes from Chapter 5 of the book and everything builds correctly and runs. But, when I try to start a game,...
New

Other popular topics Top

wolf4earth
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. https://f...
New
AstonJ
I’ve been hearing quite a lot of comments relating to the sound of a keyboard, with one of the most desirable of these called ‘thock’, he...
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...
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
PragmaticBookshelf
Author Spotlight Mike Riley @mriley This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
PragmaticBookshelf
Author Spotlight: Bruce Tate @redrapids Programming languages always emerge out of need, and if that’s not always true, they’re defin...
New

Latest in PragProg Customers

View all threads ❯