Skip to content

Commit 72bcc71

Browse files
authored
Merge pull request #140 from nutcas3/main
Complete Internationalization Implementation for ARC Platform
2 parents db21622 + 2eef882 commit 72bcc71

File tree

6 files changed

+315
-3
lines changed

6 files changed

+315
-3
lines changed

app/controllers/application_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class ApplicationController < ActionController::Base
44
include Pagy::Backend
5+
include LocaleSwitcher
56

67
before_action :authenticate_user! # All users should be authenticated in all controllers by default
78
before_action :configure_permitted_parameters, if: :devise_controller?
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
module LocaleSwitcher
4+
extend ActiveSupport::Concern
5+
6+
included do
7+
around_action :switch_locale
8+
end
9+
10+
private
11+
12+
def switch_locale(&)
13+
locale = locale_from_params || locale_from_session || locale_from_header || I18n.default_locale
14+
I18n.with_locale(locale, &)
15+
end
16+
17+
def locale_from_params
18+
locale = params[:locale]
19+
return locale if locale.present? && I18n.available_locales.include?(locale.to_sym)
20+
21+
nil
22+
end
23+
24+
def locale_from_session
25+
locale = session[:locale]
26+
return locale if locale.present? && I18n.available_locales.include?(locale.to_sym)
27+
28+
nil
29+
end
30+
31+
def locale_from_header
32+
return nil unless request.env['HTTP_ACCEPT_LANGUAGE']
33+
34+
# Parse Accept-Language header and find the first available locale
35+
accepted_locales = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/[a-z]{2}/)
36+
accepted_locales.find { |locale| I18n.available_locales.include?(locale.to_sym) }
37+
end
38+
39+
def default_url_options
40+
I18n.locale == I18n.default_locale ? {} : { locale: I18n.locale }
41+
end
42+
end

config/application.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,14 @@ class Application < Rails::Application
2323
#
2424
# config.time_zone = "Central Time (US & Canada)"
2525
# config.eager_load_paths << Rails.root.join("extras")
26+
27+
# Set default locale to English
28+
config.i18n.default_locale = :en
29+
30+
# Available locales for the application
31+
config.i18n.available_locales = [:en, :sw, :fr]
32+
33+
# Load all locale files in config/locales/
34+
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
2635
end
2736
end

config/locales/en.yml

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,53 @@
1-
# To learn more, please read the Rails Internationalization guide
2-
# available at https://guides.rubyonrails.org/i18n.html.
1+
# English translations for Arc Platform
2+
# To learn more, please read the Rails Internationalization guide:
3+
# https://guides.rubyonrails.org/i18n.html
34

45
en:
6+
# Common translations
7+
common:
8+
actions:
9+
save: 'Save'
10+
cancel: 'Cancel'
11+
edit: 'Edit'
12+
delete: 'Delete'
13+
back: 'Back'
14+
submit: 'Submit'
15+
confirm: 'Are you sure?'
16+
messages:
17+
success: 'Operation completed successfully'
18+
error: 'An error occurred'
19+
not_found: 'Record not found'
20+
unauthorized: 'You are not authorized to perform this action'
21+
22+
# Authentication and authorization
523
unauthorized:
624
sign_in: 'Please sign in to perform the action'
7-
25+
26+
# Flash messages
27+
flash:
28+
notice: 'Notice'
29+
alert: 'Alert'
30+
success: 'Success'
31+
error: 'Error'
32+
33+
# Models
34+
activerecord:
35+
models:
36+
chapter: 'Chapter'
37+
project: 'Project'
38+
country: 'Country'
39+
attributes:
40+
chapter:
41+
title: 'Title'
42+
description: 'Description'
43+
project:
44+
name: 'Name'
45+
description: 'Description'
46+
country:
47+
name: 'Name'
48+
code: 'Code'
49+
50+
# Controllers
851
chapters:
952
create:
1053
success: 'Chapter was successfully created.'
@@ -29,10 +72,12 @@ en:
2972
destroy:
3073
success: 'Project was successfully destroyed.'
3174

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

80+
# Turnstile (CAPTCHA)
3681
turnstile:
3782
warnings:
3883
pass: "Turnstile: PASS secret in use. All checks passed. Use FAIL secret for failure tests or real secret in production."
@@ -42,3 +87,16 @@ en:
4287
errors:
4388
registration_failed: 'Please complete the Turnstile challenge to create an account.'
4489
login_failed: 'Please complete the Turnstile challenge to sign in.'
90+
91+
# Date and time formats
92+
date:
93+
formats:
94+
default: "%Y-%m-%d"
95+
long: "%B %d, %Y"
96+
short: "%b %d"
97+
98+
time:
99+
formats:
100+
default: "%a, %d %b %Y %H:%M:%S %z"
101+
long: "%B %d, %Y %H:%M"
102+
short: "%d %b %H:%M"

config/locales/fr.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# French translations for Arc Platform
2+
# Traductions françaises pour Arc Platform
3+
4+
fr:
5+
# Common translations
6+
common:
7+
actions:
8+
save: 'Enregistrer'
9+
cancel: 'Annuler'
10+
edit: 'Modifier'
11+
delete: 'Supprimer'
12+
back: 'Retour'
13+
submit: 'Soumettre'
14+
confirm: 'Êtes-vous sûr?'
15+
messages:
16+
success: 'Opération réussie'
17+
error: 'Une erreur est survenue'
18+
not_found: 'Enregistrement introuvable'
19+
unauthorized: "Vous n'êtes pas autorisé à effectuer cette action"
20+
21+
# Authentication and authorization
22+
unauthorized:
23+
sign_in: 'Veuillez vous connecter pour effectuer cette action'
24+
25+
# Flash messages
26+
flash:
27+
notice: 'Avis'
28+
alert: 'Alerte'
29+
success: 'Succès'
30+
error: 'Erreur'
31+
32+
# Models
33+
activerecord:
34+
models:
35+
chapter: 'Chapitre'
36+
project: 'Projet'
37+
country: 'Pays'
38+
attributes:
39+
chapter:
40+
title: 'Titre'
41+
description: 'Description'
42+
project:
43+
name: 'Nom'
44+
description: 'Description'
45+
country:
46+
name: 'Nom'
47+
code: 'Code'
48+
49+
# Controllers
50+
chapters:
51+
create:
52+
success: 'Le chapitre a été créé avec succès.'
53+
update:
54+
success: 'Le chapitre a été mis à jour avec succès.'
55+
destroy:
56+
success: 'Le chapitre a été supprimé avec succès.'
57+
58+
countries:
59+
create:
60+
success: 'Le pays a été créé avec succès.'
61+
update:
62+
success: 'Le pays a été mis à jour avec succès.'
63+
destroy:
64+
success: 'Le pays a été supprimé avec succès.'
65+
66+
projects:
67+
create:
68+
success: 'Le projet a été créé avec succès.'
69+
update:
70+
success: 'Le projet a été mis à jour avec succès.'
71+
destroy:
72+
success: 'Le projet a été supprimé avec succès.'
73+
74+
# Devise and authentication
75+
registrations:
76+
bot_detection_failed_alert: "Désolé, nous n'avons pas pu traiter votre demande."
77+
turnstile_forbidden_error: "Nous avons rencontré un problème lors de la création de votre compte."
78+
79+
# Turnstile (CAPTCHA)
80+
turnstile:
81+
warnings:
82+
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."
83+
fail_mismatch: "Turnstile: Clé de site FAIL avec un secret non-FAIL. Cela peut donner des résultats PASS inattendus."
84+
verification_failed: "La vérification Turnstile a échoué: %{errors}"
85+
verification_error: "Erreur de vérification Turnstile (tentative %{attempt}/%{max}): %{error}"
86+
errors:
87+
registration_failed: 'Veuillez compléter le défi Turnstile pour créer un compte.'
88+
login_failed: 'Veuillez compléter le défi Turnstile pour vous connecter.'
89+
90+
# Date and time formats
91+
date:
92+
formats:
93+
default: "%d/%m/%Y"
94+
long: "%d %B %Y"
95+
short: "%d %b"
96+
97+
time:
98+
formats:
99+
default: "%a %d %b %Y %H:%M:%S %z"
100+
long: "%d %B %Y %H:%M"
101+
short: "%d %b %H:%M"

config/locales/sw.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Kiswahili translations for Arc Platform
2+
# Tafsiri za Kiswahili kwa Arc Platform
3+
4+
sw:
5+
# Common translations
6+
common:
7+
actions:
8+
save: 'Hifadhi'
9+
cancel: 'Ghairi'
10+
edit: 'Hariri'
11+
delete: 'Futa'
12+
back: 'Rudi'
13+
submit: 'Wasilisha'
14+
confirm: 'Je, una uhakika?'
15+
messages:
16+
success: 'Operesheni imekamilika kwa mafanikio'
17+
error: 'Hitilafu imetokea'
18+
not_found: 'Rekodi haijapatikana'
19+
unauthorized: 'Huna ruhusa ya kufanya kitendo hiki'
20+
21+
# Authentication and authorization
22+
unauthorized:
23+
sign_in: 'Tafadhali ingia ili kufanya kitendo hiki'
24+
25+
# Flash messages
26+
flash:
27+
notice: 'Taarifa'
28+
alert: 'Tahadhari'
29+
success: 'Mafanikio'
30+
error: 'Hitilafu'
31+
32+
# Models
33+
activerecord:
34+
models:
35+
chapter: 'Sura'
36+
project: 'Mradi'
37+
country: 'Nchi'
38+
attributes:
39+
chapter:
40+
title: 'Kichwa'
41+
description: 'Maelezo'
42+
project:
43+
name: 'Jina'
44+
description: 'Maelezo'
45+
country:
46+
name: 'Jina'
47+
code: 'Msimbo'
48+
49+
# Controllers
50+
chapters:
51+
create:
52+
success: 'Sura imeundwa kwa mafanikio.'
53+
update:
54+
success: 'Sura imesasishwa kwa mafanikio.'
55+
destroy:
56+
success: 'Sura imefutwa kwa mafanikio.'
57+
58+
countries:
59+
create:
60+
success: 'Nchi imeundwa kwa mafanikio.'
61+
update:
62+
success: 'Nchi imesasishwa kwa mafanikio.'
63+
destroy:
64+
success: 'Nchi imefutwa kwa mafanikio.'
65+
66+
projects:
67+
create:
68+
success: 'Mradi umeundwa kwa mafanikio.'
69+
update:
70+
success: 'Mradi umesasishwa kwa mafanikio.'
71+
destroy:
72+
success: 'Mradi umefutwa kwa mafanikio.'
73+
74+
# Devise and authentication
75+
registrations:
76+
bot_detection_failed_alert: "Samahani, hatukuweza kushughulikia ombi lako."
77+
turnstile_forbidden_error: "Tulikuwa na tatizo la kuunda akaunti yako."
78+
79+
# Turnstile (CAPTCHA)
80+
turnstile:
81+
warnings:
82+
pass: "Turnstile: Siri ya PASS inatumika. Ukaguzi wote umepita. Tumia siri ya FAIL kwa majaribio ya kushindwa au siri halisi katika uzalishaji."
83+
fail_mismatch: "Turnstile: Sitekey ya FAIL na siri isiyo ya FAIL. Hii inaweza kutoa matokeo ya PASS yasiyotarajiwa."
84+
verification_failed: "Uthibitisho wa Turnstile umeshindwa: %{errors}"
85+
verification_error: "Hitilafu ya uthibitisho wa Turnstile (jaribio %{attempt}/%{max}): %{error}"
86+
errors:
87+
registration_failed: 'Tafadhali kamilisha changamoto ya Turnstile ili kuunda akaunti.'
88+
login_failed: 'Tafadhali kamilisha changamoto ya Turnstile ili kuingia.'
89+
90+
# Date and time formats
91+
date:
92+
formats:
93+
default: "%Y-%m-%d"
94+
long: "%d %B, %Y"
95+
short: "%d %b"
96+
97+
time:
98+
formats:
99+
default: "%a, %d %b %Y %H:%M:%S %z"
100+
long: "%d %B, %Y %H:%M"
101+
short: "%d %b %H:%M"

0 commit comments

Comments
 (0)