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 Prag Prog topics Top

jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
New
jdufour
Hello! On page xix of the preface, it says there is a community forum "… for help if your’re stuck on one of the exercises in this book… ...
New
Mmm
Hi, build fails on: bracket-lib = “~0.8.1” when running on Mac Mini M1 Rust version 1.5.0: Compiling winit v0.22.2 error[E0308]: mi...
New
conradwt
First, the code resources: Page 237: rumbl_umbrella/apps/rumbl/mix.exs Note: That this file is missing. Page 238: rumbl_umbrella/app...
New
adamwoolhether
When trying to generate the protobuf .go file, I receive this error: Unknown flag: --go_opt libprotoc 3.12.3 MacOS 11.3.1 Googling ...
New
jskubick
I’m running Android Studio “Arctic Fox” 2020.3.1 Patch 2, and I’m embarrassed to admit that I only made it to page 8 before running into ...
New
digitalbias
Title: Build a Weather Station with Elixir and Nerves: Problem connecting to Postgres with Grafana on (page 64) If you follow the defau...
New
brunogirin
When trying to run tox in parallel as explained on page 151, I got the following error: tox: error: argument -p/–parallel: expected one...
New
Keton
When running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New

Other popular topics Top

AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
OvermindDL1
Woooooooo! This is such a huge release for it, and 2 years incoming! In short, the library is now using an updated hyper backend (not j...
New
PragmaticBookshelf
Author Spotlight Erin Dees @undees Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
New
PragmaticBookshelf
Author Spotlight: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New

Latest in PragProg

View all threads ❯