From 0912a9f408b41737eb34191bbc54340a6087a95e Mon Sep 17 00:00:00 2001 From: sto Date: Sun, 6 Sep 2026 16:34:21 +0200 Subject: [PATCH] Worlds: language switch --- app/controllers/worlds_controller.rb | 18 ++++++++++++------ app/views/application/_worlds_nav.html.slim | 8 ++++---- app/views/layouts/authenticated.html.slim | 6 ++++++ app/views/worlds/collab.html.slim | 14 +++++++------- app/views/worlds/main.html.slim | 4 ++-- app/views/worlds/new.html.slim | 2 +- config/routes.rb | 16 ++++++++-------- 7 files changed, 40 insertions(+), 28 deletions(-) diff --git a/app/controllers/worlds_controller.rb b/app/controllers/worlds_controller.rb index e5dba40..b7b0a5d 100644 --- a/app/controllers/worlds_controller.rb +++ b/app/controllers/worlds_controller.rb @@ -1,16 +1,22 @@ class WorldsController < ApplicationController allow_unauthenticated_access + before_action :set_w_lang before_action :set_title - before_action :set_fr_lang def set_title @title = I18n.t("worlds.title") @nonav = true end - def set_fr_lang - I18n.locale = "fr" + def set_w_lang + if params.has_key?(:lang) && params[:lang] == "en" + I18n.locale = "en" + @lang = "en" + else + I18n.locale = "fr" + @lang = "fr" + end end def main @@ -90,7 +96,7 @@ class WorldsController < ApplicationController end if w_set.length == 10 && f_set.length == 10 && @world_bet.save - redirect_to "/wjpc_bets/main", notice: t("worlds.new.notice") + redirect_to "/wjpc_bets/#{@lang}/main", notice: t("worlds.new.notice") else @world_participants = WorldParticipant.all.sort_by { |p| p.name } france = WorldCountry.where(code: "FR").first @@ -117,9 +123,9 @@ class WorldsController < ApplicationController b.save end end - redirect_back(fallback_location: root_path, notice: t("worlds.collab.notice")) + redirect_back(fallback_location: "/wjpc_bets/#{@lang}/main", notice: t("worlds.collab.notice")) else - redirect_to "/wjpc_bets/collab", notice: t("worlds.collab.error") + redirect_to "/wjpc_bets/#{@lang}/collab", notice: t("worlds.collab.error") end end diff --git a/app/views/application/_worlds_nav.html.slim b/app/views/application/_worlds_nav.html.slim index 357d496..6bf9e10 100644 --- a/app/views/application/_worlds_nav.html.slim +++ b/app/views/application/_worlds_nav.html.slim @@ -2,14 +2,14 @@ .col ul.nav.nav-tabs.mb-4 li.nav-item - a.nav-link class=active_page("/wjpc_bets/main") href="/wjpc_bets/main" + a.nav-link class=active_page("/wjpc_bets/#{@lang}/main") href="/wjpc_bets/#{@lang}/main" = t("worlds.main.tab") li.nav-item - a.nav-link class=active_page("/wjpc_bets/about") href="/wjpc_bets/about" + a.nav-link class=active_page("/wjpc_bets/#{@lang}/about") href="/wjpc_bets/#{@lang}/about" = t("worlds.about.tab") li.nav-item - a.nav-link class=active_page("/wjpc_bets/collaborative_filling") href="/wjpc_bets/collaborative_filling" + a.nav-link class=active_page("/wjpc_bets/#{@lang}/collaborative_filling") href="/wjpc_bets/#{@lang}/collaborative_filling" = t("worlds.collab.tab") li.nav-item - a.nav-link class=active_page("/wjpc_bets/new") href="/wjpc_bets/new" + a.nav-link class=active_page("/wjpc_bets/#{@lang}/new") href="/wjpc_bets/#{@lang}/new" = t("worlds.new.tab") \ No newline at end of file diff --git a/app/views/layouts/authenticated.html.slim b/app/views/layouts/authenticated.html.slim index f2d3dd7..17459f2 100644 --- a/app/views/layouts/authenticated.html.slim +++ b/app/views/layouts/authenticated.html.slim @@ -15,6 +15,12 @@ html a.navbar-brand href=user_path(@current_user) class="btn btn-light" = t("nav.settings") = button_to t("nav.log_out"), session_path, method: :delete, class: "btn btn-danger" + - if active_page("/wjpc_bets") + .float-end + a.navbar-brand href="/wjpc_bets/en/main" class="btn btn-light" style="margin-right: 0" + = Flags.get_flag("GB") + a.navbar-brand href="/wjpc_bets/fr/main" class="btn btn-light" style="margin-right: 0" + = Flags.get_flag("FR") css: .toast { diff --git a/app/views/worlds/collab.html.slim b/app/views/worlds/collab.html.slim index d5b2407..2ee456d 100644 --- a/app/views/worlds/collab.html.slim +++ b/app/views/worlds/collab.html.slim @@ -14,7 +14,7 @@ h4.mt-4 Round A - if p.round == 'a' .row.mt-3 .col - = form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form| + = form_with model: WorldParticipant, url: "/wjpc_bets/#{@lang}/update/#{p.id}", method: :patch do |form| .input-group .input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name} .input-group-text = t("worlds.main.rank") @@ -55,7 +55,7 @@ h4.mt-5 Round B - if p.round == 'b' .row.mt-3 .col - = form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form| + = form_with model: WorldParticipant, url: "/wjpc_bets/#{@lang}/update/#{p.id}", method: :patch do |form| .input-group .input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name} .input-group-text = t("worlds.main.rank") @@ -70,7 +70,7 @@ h4.mt-5 Round C - if p.round == 'c' .row.mt-3 .col - = form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form| + = form_with model: WorldParticipant, url: "/wjpc_bets/#{@lang}/update/#{p.id}", method: :patch do |form| .input-group .input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name} .input-group-text = t("worlds.main.rank") @@ -85,7 +85,7 @@ h4.mt-5 Round D - if p.round == 'd' .row.mt-3 .col - = form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form| + = form_with model: WorldParticipant, url: "/wjpc_bets/#{@lang}/update/#{p.id}", method: :patch do |form| .input-group .input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name} .input-group-text = t("worlds.main.rank") @@ -100,7 +100,7 @@ h4.mt-5 = "#{t("worlds.collab.semifinal")} 1" - if p.round == 'a' || p.round == 'b' .row.mt-3 .col - = form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form| + = form_with model: WorldParticipant, url: "/wjpc_bets/#{@lang}/update/#{p.id}", method: :patch do |form| .input-group .input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name} .input-group-text = t("worlds.main.rank") @@ -115,7 +115,7 @@ h4.mt-5 = "#{t("worlds.collab.semifinal")} 2" - if p.round == 'c' || p.round == 'd' .row.mt-3 .col - = form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form| + = form_with model: WorldParticipant, url: "/wjpc_bets/#{@lang}/update/#{p.id}", method: :patch do |form| .input-group .input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name} .input-group-text = t("worlds.main.rank") @@ -129,7 +129,7 @@ h4.mt-5 = "#{t("worlds.collab.final")}" - @participants.each do |p| .row.mt-3 .col - = form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form| + = form_with model: WorldParticipant, url: "/wjpc_bets/#{@lang}/update/#{p.id}", method: :patch do |form| .input-group .input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name} .input-group-text = t("worlds.main.rank") diff --git a/app/views/worlds/main.html.slim b/app/views/worlds/main.html.slim index e172501..5f84c2a 100644 --- a/app/views/worlds/main.html.slim +++ b/app/views/worlds/main.html.slim @@ -23,7 +23,7 @@ td #{b.name} td #{b.world_score} td - a.btn.btn-sm.btn-secondary href="/wjpc_bets/view/#{b.id}" + a.btn.btn-sm.btn-secondary href="/wjpc_bets/#{@lang}/view/#{b.id}" = t("worlds.main.view_bet") .row.mt-3 @@ -49,5 +49,5 @@ td #{b.name} td #{b.french_score} td - a.btn.btn-sm.btn-secondary href="/wjpc_bets/view/#{b.id}" + a.btn.btn-sm.btn-secondary href="/wjpc_bets/#{@lang}/view/#{b.id}" = t("worlds.main.view_bet") \ No newline at end of file diff --git a/app/views/worlds/new.html.slim b/app/views/worlds/new.html.slim index 581d06d..c7a9269 100644 --- a/app/views/worlds/new.html.slim +++ b/app/views/worlds/new.html.slim @@ -1,6 +1,6 @@ = render "worlds_nav" -= form_with model: @world_bet, url: "/wjpc_bets/new", method: :post do |form| += form_with model: @world_bet, url: "/wjpc_bets/#{@lang}/new", method: :post do |form| .alert.alert-primary role="alert" = t("worlds.new.message") diff --git a/config/routes.rb b/config/routes.rb index 3e416d2..70ca27c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -83,12 +83,12 @@ Rails.application.routes.draw do "/public/#{contest.friendly_id}/offline/#{offline.generate_token_for(:token)}/completed" end - get "wjpc_bets", to: redirect("/wjpc_bets/main") - get "wjpc_bets/main", to: "worlds#main" - get "wjpc_bets/about", to: "worlds#about" - get "wjpc_bets/collaborative_filling", to: "worlds#collab" - get "wjpc_bets/new", to: "worlds#new" - post "wjpc_bets/new", to: "worlds#create" - patch "wjpc_bets/update/:participant_id", to: "worlds#update" - get "wjpc_bets/view/:bet_id", to: "worlds#view" + get "wjpc_bets", to: redirect("/wjpc_bets/fr/main") + get "wjpc_bets/:lang/main", to: "worlds#main" + get "wjpc_bets/:lang/about", to: "worlds#about" + get "wjpc_bets/:lang/collaborative_filling", to: "worlds#collab" + get "wjpc_bets/:lang/new", to: "worlds#new" + post "wjpc_bets/:lang/new", to: "worlds#create" + patch "wjpc_bets/:lang/update/:participant_id", to: "worlds#update" + get "wjpc_bets/:lang/view/:bet_id", to: "worlds#view" end