Skip to content

Commit

Permalink
Initial support for i18n (#54)
Browse files Browse the repository at this point in the history
---------
Co-authored-by: BGMP <jose@bgm.cl>
  • Loading branch information
nickskyline committed Feb 29, 2024
1 parent a410e40 commit a15d35e
Show file tree
Hide file tree
Showing 60 changed files with 5,269 additions and 416 deletions.
Binary file added app/assets/images/i18n/en.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/i18n/en_gb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/i18n/es.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/i18n/es_ar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/i18n/es_bo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/i18n/es_cl.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/i18n/it.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/i18n/ko.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/i18n/lol.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/i18n/pt_br.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/assets/stylesheets/nav.scss
Expand Up @@ -138,3 +138,8 @@ nav {
background-color: #fff !important;
color: #000 !important;
}

.locale-flag {
height: 29px;
width: 29px;
}
37 changes: 23 additions & 14 deletions app/controllers/application_controller.rb
Expand Up @@ -2,24 +2,33 @@ class ApplicationController < ActionController::Base
include ApplicationHelper
include RankingsHelper

before_action :set_locale
before_action :build_navigation

def set_locale
I18n.locale = if user_signed_in?
current_user.locale
else
I18n.default_locale
end
end

def build_navigation
return unless user_signed_in?

@admin_nav = [
{ :name => 'Upload Session', :path => new_session_path },
{ :name => 'Create Season', :path => new_season_path },
{ :name => 'Import Tracks', :path => new_track_path },
{ :name => 'Import Cars', :path => new_car_path },
# { :name => 'New Team', :path => new_team_path },
# { :name => 'New Tournament', :path => new_tournament_path },
{ :name => 'Import Users', :path => users_new_path }
{ :name => t('nav.user.admin.upload-session'), :path => new_session_path },
{ :name => t('nav.user.admin.create-season'), :path => new_season_path },
{ :name => t('nav.user.admin.import-tracks'), :path => new_track_path },
{ :name => t('nav.user.admin.import-cars'), :path => new_car_path },
# { :name => t('nav.user.admin.new-team'), :path => new_team_path },
# { :name => t('nav.user.admin.new-tournament'), :path => new_tournament_path },
{ :name => t('nav.user.admin.import-users'), :path => users_new_path }
]
@nav = [
{ :name => 'Admin', :path => '', :sub => @admin_nav, :admin => true },
{ :name => 'My Profile', :path => user_path(current_user.username) },
{ :name => 'Settings', :path => main_app.edit_user_registration_path }
{ :name => t('nav.user.admin.title'), :path => '', :sub => @admin_nav, :admin => true },
{ :name => t('nav.user.my-profile'), :path => user_path(current_user.username) },
{ :name => t('nav.user.settings'), :path => main_app.edit_user_registration_path }
]
end

Expand Down Expand Up @@ -75,18 +84,18 @@ def index
end

def authenticate_admin
redirect_to root_path, :notice => 'You do not have permission' unless user_is_admin?
redirect_to root_path, :notice => t('alerts.no-permission') unless user_is_admin?
end

def authenticate_mod
redirect_to root_path, :notice => 'You do not have permission' unless user_is_mod?
redirect_to root_path, :notice => t('alerts.no-permission') unless user_is_mod?
end

def authenticate_organizer
redirect_to root_path, :notice => 'You do not have permission' unless user_is_organizer?
redirect_to root_path, :notice => t('alerts.no-permission') unless user_is_organizer?
end

def authenticate_staff
redirect_to root_path, :notice => 'You do not have permission' unless user_is_staff?
redirect_to root_path, :notice => t('alerts.no-permission') unless user_is_staff?
end
end
15 changes: 15 additions & 0 deletions app/controllers/users_controller.rb
Expand Up @@ -82,6 +82,21 @@ def edit
end
end

def update_locale
return if !user_signed_in? || params[:locale].nil?

current_user.locale = params[:locale]
current_user.update!

respond_to do |format|
if current_user.update!
format.html { redirect_back fallback_location: root_path, :notice => "Language set to #{SYS::LOCALES_MAP.key(params[:locale].to_sym)}" }
else
format.html { redirect_to root_path, :status => :unprocessable_entity }
end
end
end

def new
@user = User.new
@user.build_profile
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Expand Up @@ -62,7 +62,7 @@ class User
field :admin, :type => Boolean, :default => false
field :mod, :type => Boolean, :default => false
field :organizer, :type => Boolean, :default => false
field :locale, :type => String, :default => 'en_us'
field :locale, :type => String, :default => :en
field :country, :type => String

def has_team?
Expand Down
4 changes: 2 additions & 2 deletions app/views/application/_footer.haml
Expand Up @@ -14,9 +14,9 @@
%div.col-xl-3.col-lg-3.col-md-3.col-sm-6.col-xs-6.col-6
%ul.list-unstyled
%li.heading
Organization
= t('footer.organization.title')
%li
= link_to "Staff Listing", staff_path
= link_to t("footer.organization.staff"), staff_path
%li
= link_to t('footer.organization.logs'), web_repo_or_first
%li
Expand Down
30 changes: 20 additions & 10 deletions app/views/application/_nav.haml
Expand Up @@ -15,26 +15,26 @@
%li.nav-item
%a.nav-link{:href => tracks_path}
%i.fa.fa-map{:"aria-hidden" => "true"}
= "Tracks"
= t("nav.tracks")
%li.nav-item
%a.nav-link{:href => cars_path}
%i.fa.fa-car{:"aria-hidden" => "true"}
= "Cars"
= t("nav.cars")
%li.nav-item
%a.nav-link{:href => seasons_path}
%i.fa.fa-calendar
= "Seasons"
= t("nav.seasons")
%li.nav-item.dropdown
%a.nav-link.dropdown-toggle{:href => "", :"data-toggle" => "dropdown", :"aria-haspopup" => "true", :"aria-expanded" => "false"}
%i.fa.fa-trophy{:"aria-hidden" => true}
= "League"
= t("nav.league.title")
%div.dropdown-menu{:"aria-labelledby" => "dropdown01"}
%a.dropdown-item{:href => stats_path}
%i.fa.fa-line-chart{:"aria-hidden" => "true"}
= "Leaderboard"
= t("nav.league.leaderboard")
%a.dropdown-item{:href => points_path}
%i.fa.fa-list-ol{:"aria-hidden" => "true"}
= t('nav.rva.points')
= t('nav.league.point-system')
%a.dropdown-item{:href => teams_path}
%i.fa.fa-users
= t('nav.league.teams')
Expand All @@ -47,8 +47,18 @@
= t('nav.downloads')
%li.nav-item
%ul.navbar-nav
- if user_signed_in?
%li.dropdown
%a.nav-link.dropdown-toggle{:href => "", :"data-toggle" => "dropdown", :"aria-haspopup" => true, :"aria-expanded" => false}
= image_tag "i18n/#{I18n.locale}.png", :class => "locale-flag"
%ul.dropdown-menu.dropdown-menu-right{:"aria-labelledby" => "dropdown02"}
- I18n.available_locales.each do |l|
%a.dropdown-item{:"data-turbo" => "true", :"data-turbo-method" => "put", :href => users_locale_path(:locale => l)}
= image_tag "i18n/#{l}.png", :class => "locale-flag"
= SYS::LOCALES_MAP.key(l)

%li.dropdown
%a.nav-link.dropdown-toggle{:id => "access-toggle", :style => "outline: none; #{user_signed_in? ? 'line-height: 0px' : ''};", :"data-toggle" => "dropdown", :href => "#"}
%a.nav-link.dropdown-toggle{:id => "access-toggle", :"data-toggle" => "dropdown", :href => "#"}
- if user_signed_in?
%span.current-username
= current_user.username
Expand All @@ -60,9 +70,9 @@
- @nav.each do |item|
= render_navigation(item)
%li
= link_to "Log out", destroy_user_session_path, :class => "dropdown-item", data: { turbo: true, turbo_method: :delete }
= link_to t("nav.user.log-out"), destroy_user_session_path, :class => "dropdown-item", data: { turbo: true, turbo_method: :delete }
- else
%li
= link_to "Login", new_user_session_path, :class => "dropdown-item"
= link_to t("nav.user.login"), new_user_session_path, :class => "dropdown-item"
%li
= link_to "Register", new_user_registration_path, :class => "dropdown-item"
= link_to t("nav.user.register"), new_user_registration_path, :class => "dropdown-item"
9 changes: 5 additions & 4 deletions app/views/application/_splash.haml
Expand Up @@ -4,7 +4,8 @@
%h1
= ORG::NAME
%p
The Website for the American community of Re-Volt, 1999
%br/
Download the game and meet players from all over the Americas!
%a.btn-important{ href: downloads_path } Downloads »
= t("application.splash.description1")
%br
= t("application.splash.description2")
%a.btn-important{ href: downloads_path }
= t("application.splash.download-button")
36 changes: 18 additions & 18 deletions app/views/application/_subnav.haml
Expand Up @@ -7,7 +7,7 @@
/ | Seasons | Tracks | Cars
%li.nav-item
%a.nav-link{:href => seasons_path, :class => "#{current_page?(seasons_path) ? 'active' : ''}"}
= "Seasons #{(defined?(season)) ? "»" : ""}"
= "#{t('sub-nav.seasons')} #{(defined?(season)) ? "»" : ""}"

/ Season »
- if defined?(season) && !season.nil?
Expand All @@ -20,34 +20,34 @@
%li.nav-item.dropdown
%a.nav-link.dropdown-toggle{:href => "", :"data-toggle" => "dropdown", :"aria-haspopup" => "true", :"aria-expanded" => "false", :class => "#{defined?(ranking) && current_page?(ranking_path(ranking)) ? 'active' : ''}"}
- if defined?(ranking)
= "Ranking #{ranking.number}"
= "#{t('sub-nav.ranking')} #{ranking.number}"
- else
= "Rankings"
= t('sub-nav.rankings')
.dropdown-menu{:"aria-labelledby" => "dropdown04"}
- rankings.each do |r|
%a.dropdown-item{:href => ranking_path(r), :class => "#{(defined?(ranking) && ranking == r) ? 'active' : ''}"}
= "Ranking #{r.number}"
= t('sub-nav.ranking-n', :n => r.number)

-# NOTE: Our Session model name conflicts with ActionDispatch::Request::Session, so we have to check if the
-# definition is ours ...
- if defined?(session) && session.is_a?(Session) && !session.nil?
%li.nav-item
%a.nav-link{:href => session_path(session), :class => "#{(current_page?(session_path(session)) || current_page?(edit_session_path(session))) ? 'active' : ''}"}
= "Session #{session.number}"
= t('sub-nav.session-n', :n => session.number)

- if current_page?(tracks_path) || (defined?(track) && !track.nil?)
/ Tracks »
%li.nav-item
%a.nav-link{:href => tracks_path, :class => "#{current_page?(tracks_path) ? 'active' : ''}"}
= "Tracks #{defined?(track) ? "»" : ""}"
= "#{t('sub-nav.tracks')} #{defined?(track) ? "»" : ""}"
- if defined?(track) && !track.nil?
%li.nav-item
%a.nav-link{:href => track_path(track), :class => "#{(current_page?(track_path(track)) || current_page?(edit_track_path(track))) ? 'active' : ''}"}
= track.name
/ Cars »
%li.nav-item
%a.nav-link{:href => cars_path, :class => "#{current_page?(cars_path) ? 'active' : ''}"}
= "Cars #{defined?(category) ? "»" : ""}"
= "#{t('sub-nav.cars')} #{defined?(category) ? "»" : ""}"
- if defined?(category) && !category.nil?
%li.nav-item
%a.nav-link{:href => car_category_path(category), :class => "#{current_page?(car_category_path(category)) ? 'active' : ''}"}
Expand All @@ -60,7 +60,7 @@
/ Cars »
%li.nav-item
%a.nav-link{:href => cars_path, :class => "#{current_page?(cars_path) ? 'active' : ''}"}
= "Cars #{defined?(category) ? "»" : ""}"
= "#{t('sub-nav.cars')} #{defined?(category) ? "»" : ""}"
- if defined?(category) && !category.nil?
%li.nav-item
%a.nav-link{:href => car_category_path(category), :class => "#{current_page?(car_category_path(category)) ? 'active' : ''}"}
Expand All @@ -72,7 +72,7 @@
/ Tracks »
%li.nav-item
%a.nav-link{:href => tracks_path, :class => "#{current_page?(tracks_path) ? 'active' : ''}"}
= "Tracks #{defined?(track) ? "»" : ""}"
= "#{t('sub-nav.tracks')} #{defined?(track) ? "»" : ""}"
- if defined?(track) && !track.nil?
%li.nav-item
%a.nav-link{:href => track_path(track), :class => "#{(current_page?(track_path(track)) || current_page?(edit_track_path(track))) ? 'active' : ''}"}
Expand All @@ -88,7 +88,7 @@
/ | Seasons | Tracks | Cars
%li.nav-item
%a{:href => seasons_path, :class => "#{current_page?(seasons_path) ? 'active' : ''}"}
= "Seasons"
= t('sub-nav.seasons')

/ Season »
- if defined?(season) && !season.nil?
Expand All @@ -101,34 +101,34 @@
%li.nav-item.dropdown
%a.dropdown-toggle{:href => "", :"data-toggle" => "dropdown", :"aria-haspopup" => "true", :"aria-expanded" => "false", :class => "#{defined?(ranking) && current_page?(ranking_path(ranking)) ? 'active' : ''}"}
- if defined?(ranking)
= "Ranking #{ranking.number}"
= t('sub-nav.ranking-n', :n => ranking.number)
- else
= "Rankings"
= t('sub-nav.rankings')
.dropdown-menu{:"aria-labelledby" => "dropdown04"}
- rankings.each do |r|
%a.dropdown-item{:href => ranking_path(r), :class => "#{(defined?(ranking) && ranking == r) ? 'active' : ''}"}
= "Ranking #{r.number}"
= t('sub-nav.ranking-n', :n => r.number)

-# NOTE: Our Session model name conflicts with ActionDispatch::Request::Session, so we have to check if the
-# definition is ours ...
- if defined?(session) && session.is_a?(Session)
%li.nav-item
%a{:href => session_path(session), :class => "#{(current_page?(session_path(session)) || current_page?(edit_session_path(session))) ? 'active' : ''}"}
= "Session #{session.number}"
= t('sub-nav.session-n', :n => session.number)

- if current_page?(tracks_path) || defined?(track)
/ Tracks »
%li.nav-item
%a{:href => tracks_path, :class => "#{current_page?(tracks_path) ? 'active' : ''}"}
= "Tracks"
= t('sub-nav.tracks')
- if defined?(track) && !track.nil?
%li.nav-item
%a{:href => track_path(track), :class => "#{(current_page?(track_path(track)) || current_page?(edit_track_path(track))) ? 'active' : ''}"}
= track.name
/ Cars »
%li.nav-item
%a{:href => cars_path, :class => "#{current_page?(cars_path) ? 'active' : ''}"}
= "Cars"
= t('sub-nav.cars')
- if defined?(category) && !category.nil?
%li.nav-item
%a{:href => car_category_path(category), :class => "#{current_page?(car_category_path(category)) ? 'active' : ''}"}
Expand All @@ -141,7 +141,7 @@
/ Cars »
%li.nav-item
%a{:href => cars_path, :class => "#{current_page?(cars_path) ? 'active' : ''}"}
= "Cars"
= t('sub-nav.cars')
- if defined?(category) && !category.nil?
%li.nav-item
%a{:href => car_category_path(category), :class => "#{current_page?(car_category_path(category)) ? 'active' : ''}"}
Expand All @@ -153,7 +153,7 @@
/ Tracks »
%li.nav-item
%a{:href => tracks_path, :class => "#{current_page?(tracks_path) ? 'active' : ''}"}
= "Tracks"
= t('sub-nav.tracks')
- if defined?(track) && !track.nil?
%li.nav-item
%a{:href => track_path(track), :class => "#{(current_page?(track_path(track)) || current_page?(edit_track_path(track))) ? 'active' : ''}"}
Expand Down
4 changes: 3 additions & 1 deletion app/views/application/about.haml
@@ -1,7 +1,9 @@
#about
%section.jumbotron.text-center
.container
%h1 About Re-Volt America
%h1
= t('application.about.title')
= t('application.about.description')
%p.lead
The largest Re-Volt community you'll find in the American Continent.
Join our racing sessions, compete in our seasons and meet other Re-Volt players from around the world!
Expand Down
23 changes: 14 additions & 9 deletions app/views/application/index.haml
Expand Up @@ -6,27 +6,32 @@
.col-lg-4
= image_tag "index/community.png", :class => "img-fluid"
%h2
= t("application.index.community")
%p We are an amazing Re-Volt community mainly made up of South American players, but you will also find people from all over the world playing online with us.
= t("application.index.community.title")
%p
= t("application.index.community.description")
%p
%a.btn-important{ href: play_path, role: "button" } Play »
.col-lg-4
= image_tag "index/competition.png", :class => "img-fluid"
%h2 Competition
%p In Re-Volt America we race in a seasonal format. Throughout each season, you will be able to race online daily and score points for every race you participate in!
%h2
= t("application.index.competition.title")
%p
= t("application.index.competition.description")
%p
%a.btn-important{ href: seasons_path, role: "button" } Seasons »
.col-lg-4
= image_tag "index/reliability.png", :class => "img-fluid"
%h2 Reliability
%p Re-Volt America has been designed with sustainability and scalability in mind. Most of the features you see here you will not find in any other Re-Volt community.
%h2
= t("application.index.reliability.title")
%p
= t("application.index.reliability.description")
%p
%a.btn-important{ href: about_path, role: "button" } About Us »

#recent.mt-5
- if @recent_sessions&.any?
%h6.pb-2.mb-0
= "Recent Sessions"
= t("application.index.recent.title")
.media-group
- @recent_sessions.each do |session|
%a.media.text-muted.pt-3{:href => session_path(session) }
Expand All @@ -37,8 +42,8 @@
.media-body.pb-3.mb-0.small.lh-125
.d-flex.justify-content-between.align-items-center.w-100
%strong.text-gray-dark
= "#{session_category_name(session)} Races"
= t("application.index.recent.races", category: session_category_name(session))
.session-date
= pretty_datetime(session.date)
%span.d-block.session-host
= "Hosted by #{session.host}"
= t("application.index.recent.hosted-by", host: session.host)

0 comments on commit a15d35e

Please sign in to comment.