Skip to content
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class ApplicationController < ActionController::Base
include Pagy::Backend
include LocaleSwitcher

before_action :authenticate_user! # All users should be authenticated in all controllers by default
before_action :configure_permitted_parameters, if: :devise_controller?
Expand Down
42 changes: 42 additions & 0 deletions app/controllers/concerns/locale_switcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

module LocaleSwitcher
extend ActiveSupport::Concern

included do
around_action :switch_locale
end

private

def switch_locale(&)
locale = locale_from_params || locale_from_session || locale_from_header || I18n.default_locale
I18n.with_locale(locale, &)
end

def locale_from_params
locale = params[:locale]
return locale if locale.present? && I18n.available_locales.include?(locale.to_sym)

nil
end

def locale_from_session
locale = session[:locale]
return locale if locale.present? && I18n.available_locales.include?(locale.to_sym)

nil
end

def locale_from_header
return nil unless request.env['HTTP_ACCEPT_LANGUAGE']

# Parse Accept-Language header and find the first available locale
accepted_locales = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/[a-z]{2}/)
accepted_locales.find { |locale| I18n.available_locales.include?(locale.to_sym) }
end

def default_url_options
I18n.locale == I18n.default_locale ? {} : { locale: I18n.locale }
end
end
9 changes: 9 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@ class Application < Rails::Application
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")

# Set default locale to English
config.i18n.default_locale = :en

# Available locales for the application
config.i18n.available_locales = [:en, :sw, :fr]

# Load all locale files in config/locales/
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
end
end
64 changes: 61 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,53 @@
# To learn more, please read the Rails Internationalization guide
# available at https://guides.rubyonrails.org/i18n.html.
# English translations for Arc Platform
# To learn more, please read the Rails Internationalization guide:
# https://guides.rubyonrails.org/i18n.html

en:
# Common translations
common:
actions:
save: 'Save'
cancel: 'Cancel'
edit: 'Edit'
delete: 'Delete'
back: 'Back'
submit: 'Submit'
confirm: 'Are you sure?'
messages:
success: 'Operation completed successfully'
error: 'An error occurred'
not_found: 'Record not found'
unauthorized: 'You are not authorized to perform this action'

# Authentication and authorization
unauthorized:
sign_in: 'Please sign in to perform the action'


# Flash messages
flash:
notice: 'Notice'
alert: 'Alert'
success: 'Success'
error: 'Error'

# Models
activerecord:
models:
chapter: 'Chapter'
project: 'Project'
country: 'Country'
attributes:
chapter:
title: 'Title'
description: 'Description'
project:
name: 'Name'
description: 'Description'
country:
name: 'Name'
code: 'Code'

# Controllers
chapters:
create:
success: 'Chapter was successfully created.'
Expand All @@ -29,10 +72,12 @@ en:
destroy:
success: 'Project was successfully destroyed.'

# Devise and authentication
registrations:
bot_detection_failed_alert: "Sorry, we couldn't process your request."
turnstile_forbidden_error: "We had a problem creating your account."

# Turnstile (CAPTCHA)
turnstile:
warnings:
pass: "Turnstile: PASS secret in use. All checks passed. Use FAIL secret for failure tests or real secret in production."
Expand All @@ -42,3 +87,16 @@ en:
errors:
registration_failed: 'Please complete the Turnstile challenge to create an account.'
login_failed: 'Please complete the Turnstile challenge to sign in.'

# Date and time formats
date:
formats:
default: "%Y-%m-%d"
long: "%B %d, %Y"
short: "%b %d"

time:
formats:
default: "%a, %d %b %Y %H:%M:%S %z"
long: "%B %d, %Y %H:%M"
short: "%d %b %H:%M"
101 changes: 101 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# French translations for Arc Platform
# Traductions françaises pour Arc Platform

fr:
# Common translations
common:
actions:
save: 'Enregistrer'
cancel: 'Annuler'
edit: 'Modifier'
delete: 'Supprimer'
back: 'Retour'
submit: 'Soumettre'
confirm: 'Êtes-vous sûr?'
messages:
success: 'Opération réussie'
error: 'Une erreur est survenue'
not_found: 'Enregistrement introuvable'
unauthorized: "Vous n'êtes pas autorisé à effectuer cette action"

# Authentication and authorization
unauthorized:
sign_in: 'Veuillez vous connecter pour effectuer cette action'

# Flash messages
flash:
notice: 'Avis'
alert: 'Alerte'
success: 'Succès'
error: 'Erreur'

# Models
activerecord:
models:
chapter: 'Chapitre'
project: 'Projet'
country: 'Pays'
attributes:
chapter:
title: 'Titre'
description: 'Description'
project:
name: 'Nom'
description: 'Description'
country:
name: 'Nom'
code: 'Code'

# Controllers
chapters:
create:
success: 'Le chapitre a été créé avec succès.'
update:
success: 'Le chapitre a été mis à jour avec succès.'
destroy:
success: 'Le chapitre a été supprimé avec succès.'

countries:
create:
success: 'Le pays a été créé avec succès.'
update:
success: 'Le pays a été mis à jour avec succès.'
destroy:
success: 'Le pays a été supprimé avec succès.'

projects:
create:
success: 'Le projet a été créé avec succès.'
update:
success: 'Le projet a été mis à jour avec succès.'
destroy:
success: 'Le projet a été supprimé avec succès.'

# Devise and authentication
registrations:
bot_detection_failed_alert: "Désolé, nous n'avons pas pu traiter votre demande."
turnstile_forbidden_error: "Nous avons rencontré un problème lors de la création de votre compte."

# Turnstile (CAPTCHA)
turnstile:
warnings:
pass: "Turnstile: Secret PASS utilisé. Tous les contrôles sont passés. Utilisez le secret FAIL pour les tests d'échec ou le secret réel en production."
fail_mismatch: "Turnstile: Clé de site FAIL avec un secret non-FAIL. Cela peut donner des résultats PASS inattendus."
verification_failed: "La vérification Turnstile a échoué: %{errors}"
verification_error: "Erreur de vérification Turnstile (tentative %{attempt}/%{max}): %{error}"
errors:
registration_failed: 'Veuillez compléter le défi Turnstile pour créer un compte.'
login_failed: 'Veuillez compléter le défi Turnstile pour vous connecter.'

# Date and time formats
date:
formats:
default: "%d/%m/%Y"
long: "%d %B %Y"
short: "%d %b"

time:
formats:
default: "%a %d %b %Y %H:%M:%S %z"
long: "%d %B %Y %H:%M"
short: "%d %b %H:%M"
101 changes: 101 additions & 0 deletions config/locales/sw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Kiswahili translations for Arc Platform
# Tafsiri za Kiswahili kwa Arc Platform

sw:
# Common translations
common:
actions:
save: 'Hifadhi'
cancel: 'Ghairi'
edit: 'Hariri'
delete: 'Futa'
back: 'Rudi'
submit: 'Wasilisha'
confirm: 'Je, una uhakika?'
messages:
success: 'Operesheni imekamilika kwa mafanikio'
error: 'Hitilafu imetokea'
not_found: 'Rekodi haijapatikana'
unauthorized: 'Huna ruhusa ya kufanya kitendo hiki'

# Authentication and authorization
unauthorized:
sign_in: 'Tafadhali ingia ili kufanya kitendo hiki'

# Flash messages
flash:
notice: 'Taarifa'
alert: 'Tahadhari'
success: 'Mafanikio'
error: 'Hitilafu'

# Models
activerecord:
models:
chapter: 'Sura'
project: 'Mradi'
country: 'Nchi'
attributes:
chapter:
title: 'Kichwa'
description: 'Maelezo'
project:
name: 'Jina'
description: 'Maelezo'
country:
name: 'Jina'
code: 'Msimbo'

# Controllers
chapters:
create:
success: 'Sura imeundwa kwa mafanikio.'
update:
success: 'Sura imesasishwa kwa mafanikio.'
destroy:
success: 'Sura imefutwa kwa mafanikio.'

countries:
create:
success: 'Nchi imeundwa kwa mafanikio.'
update:
success: 'Nchi imesasishwa kwa mafanikio.'
destroy:
success: 'Nchi imefutwa kwa mafanikio.'

projects:
create:
success: 'Mradi umeundwa kwa mafanikio.'
update:
success: 'Mradi umesasishwa kwa mafanikio.'
destroy:
success: 'Mradi umefutwa kwa mafanikio.'

# Devise and authentication
registrations:
bot_detection_failed_alert: "Samahani, hatukuweza kushughulikia ombi lako."
turnstile_forbidden_error: "Tulikuwa na tatizo la kuunda akaunti yako."

# Turnstile (CAPTCHA)
turnstile:
warnings:
pass: "Turnstile: Siri ya PASS inatumika. Ukaguzi wote umepita. Tumia siri ya FAIL kwa majaribio ya kushindwa au siri halisi katika uzalishaji."
fail_mismatch: "Turnstile: Sitekey ya FAIL na siri isiyo ya FAIL. Hii inaweza kutoa matokeo ya PASS yasiyotarajiwa."
verification_failed: "Uthibitisho wa Turnstile umeshindwa: %{errors}"
verification_error: "Hitilafu ya uthibitisho wa Turnstile (jaribio %{attempt}/%{max}): %{error}"
errors:
registration_failed: 'Tafadhali kamilisha changamoto ya Turnstile ili kuunda akaunti.'
login_failed: 'Tafadhali kamilisha changamoto ya Turnstile ili kuingia.'

# Date and time formats
date:
formats:
default: "%Y-%m-%d"
long: "%d %B, %Y"
short: "%d %b"

time:
formats:
default: "%a, %d %b %Y %H:%M:%S %z"
long: "%d %B, %Y %H:%M"
short: "%d %b %H:%M"