Skip to content

Commit 0e995d7

Browse files
authored
Localize controllers models and views (#975)
## Summary - Replace hard-coded flash messages in membership, invitation, report, and page controllers with i18n lookups. - Move model validation strings into locale files for address, wizard steps, person blocks, and host protection. - Translate metrics report views and error pages, adding corresponding keys to English, Spanish, and French locales. ## Testing - `rubocop` - `brakeman -q -w2` - `bundler-audit --update` - `bin/codex_style_guard` *(fails: Your Ruby version is 3.2.3, but your Gemfile specified 3.4.4)* - `bin/ci` *(fails: bundler: command not found: rails)* ------ https://chatgpt.com/codex/tasks/task_e_689a5049cf108321b1c13fa6c06922d0
2 parents 35485b5 + 29f3b61 commit 0e995d7

File tree

22 files changed

+262
-88
lines changed

22 files changed

+262
-88
lines changed

app/controllers/better_together/metrics/link_click_reports_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
4141

4242
respond_to do |format| # rubocop:todo Metrics/BlockLength
4343
if @link_click_report.persisted?
44-
flash[:notice] = 'Report was successfully created.'
44+
flash[:notice] = t('flash.generic.created', resource: t('resources.report'))
4545
format.html { redirect_to metrics_link_click_reports_path, notice: flash[:notice] }
4646
format.turbo_stream do
4747
render turbo_stream: [
@@ -55,7 +55,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
5555
]
5656
end
5757
else
58-
flash.now[:alert] = 'Error creating report.'
58+
flash.now[:alert] = t('flash.generic.error_create', resource: t('resources.report'))
5959
format.html { render :new, status: :unprocessable_entity }
6060
format.turbo_stream do
6161
render turbo_stream: [

app/controllers/better_together/metrics/page_view_reports_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
3939

4040
respond_to do |format| # rubocop:todo Metrics/BlockLength
4141
if @page_view_report.persisted?
42-
flash[:notice] = 'Report was successfully created.'
42+
flash[:notice] = t('flash.generic.created', resource: t('resources.report'))
4343
format.html { redirect_to metrics_page_view_reports_path, notice: flash[:notice] }
4444
format.turbo_stream do
4545
render turbo_stream: [
@@ -55,7 +55,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
5555
]
5656
end
5757
else
58-
flash.now[:alert] = 'Error creating report.'
58+
flash.now[:alert] = t('flash.generic.error_create', resource: t('resources.report'))
5959
format.html { render :new, status: :unprocessable_entity }
6060
format.turbo_stream do
6161
render turbo_stream: [

app/controllers/better_together/pages_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def create
3737
authorize @page
3838

3939
if @page.save
40-
redirect_to edit_page_path(@page), notice: 'Page was successfully created.'
40+
redirect_to edit_page_path(@page), notice: t('flash.generic.created', resource: t('resources.page'))
4141
else
4242
render :new
4343
end
@@ -53,11 +53,11 @@ def update # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
5353
respond_to do |format|
5454
if @page.update(page_params)
5555
format.html do
56-
flash[:notice] = 'Page was successfully updated.'
57-
redirect_to edit_page_path(@page), notice: 'Page was successfully updated.'
56+
flash[:notice] = t('flash.generic.updated', resource: t('resources.page'))
57+
redirect_to edit_page_path(@page), notice: t('flash.generic.updated', resource: t('resources.page'))
5858
end
5959
format.turbo_stream do
60-
flash.now[:notice] = 'Page was successfully updated.'
60+
flash.now[:notice] = t('flash.generic.updated', resource: t('resources.page'))
6161
render turbo_stream: [
6262
turbo_stream.replace(helpers.dom_id(@page, 'form'), partial: 'form',
6363
locals: { page: @page }),
@@ -77,7 +77,7 @@ def update # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
7777
def destroy
7878
authorize @page
7979
@page.destroy
80-
redirect_to pages_url, notice: 'Page was successfully destroyed.'
80+
redirect_to pages_url, notice: t('flash.generic.destroyed', resource: t('resources.page'))
8181
end
8282

8383
protected

app/controllers/better_together/person_community_memberships_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
1313

1414
respond_to do |format|
1515
if @person_community_membership.save
16-
flash[:notice] = 'Member was successfully added.'
16+
flash[:notice] = t('flash.generic.created', resource: t('resources.member'))
1717
format.html { redirect_to @community, notice: flash[:notice] }
1818
format.turbo_stream do
1919
render turbo_stream: [
@@ -26,7 +26,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
2626
]
2727
end
2828
else
29-
flash.now[:alert] = 'Error adding member.'
29+
flash.now[:alert] = t('flash.generic.error_create', resource: t('resources.member'))
3030
format.html { redirect_to @community, alert: @person_community_membership.errors.full_messages.to_sentence }
3131
format.turbo_stream do
3232
render turbo_stream: [
@@ -44,7 +44,7 @@ def destroy # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
4444
authorize @person_community_membership
4545

4646
if @person_community_membership.destroy
47-
flash.now[:notice] = 'Member was successfully removed.'
47+
flash.now[:notice] = t('flash.generic.removed', resource: t('resources.member'))
4848
respond_to do |format|
4949
format.html { redirect_to @community }
5050
format.turbo_stream do
@@ -56,7 +56,7 @@ def destroy # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
5656
end
5757
end
5858
else
59-
flash.now[:error] = 'Failed to remove member.'
59+
flash.now[:error] = t('flash.generic.error_remove', resource: t('resources.member'))
6060
respond_to do |format|
6161
format.html { redirect_to @community, alert: flash.now[:error] }
6262
format.turbo_stream do

app/controllers/better_together/platform_invitations_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
2121

2222
respond_to do |format|
2323
if @platform_invitation.save
24-
flash[:notice] = 'Invitation was successfully created.'
24+
flash[:notice] = t('flash.generic.created', resource: t('resources.invitation'))
2525
format.html { redirect_to @platform, notice: flash[:notice] }
2626
format.turbo_stream do
2727
render turbo_stream: [
@@ -34,7 +34,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
3434
]
3535
end
3636
else
37-
flash.now[:alert] = 'Error creating platform_invitation.'
37+
flash.now[:alert] = t('flash.generic.error_create', resource: t('resources.invitation'))
3838
format.html { redirect_to @platform, alert: @platform_invitation.errors.full_messages.to_sentence }
3939
format.turbo_stream do
4040
render turbo_stream: [
@@ -52,7 +52,7 @@ def destroy # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
5252
authorize @platform_invitation
5353

5454
if @platform_invitation.destroy
55-
flash.now[:notice] = 'Invitation was successfully removed.'
55+
flash.now[:notice] = t('flash.generic.removed', resource: t('resources.invitation'))
5656
respond_to do |format|
5757
format.html { redirect_to @platform }
5858
format.turbo_stream do
@@ -64,7 +64,7 @@ def destroy # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
6464
end
6565
end
6666
else
67-
flash.now[:error] = 'Failed to remove platform_invitation.'
67+
flash.now[:error] = t('flash.generic.error_remove', resource: t('resources.invitation'))
6868
respond_to do |format|
6969
format.html { redirect_to @platform, alert: flash.now[:error] }
7070
format.turbo_stream do
@@ -82,7 +82,7 @@ def resend # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
8282
authorize @platform_invitation
8383

8484
BetterTogether::PlatformInvitationMailerJob.perform_later(@platform_invitation.id)
85-
flash[:notice] = 'Invitation email has been queued for sending.'
85+
flash[:notice] = t('flash.generic.queued', resource: t('resources.invitation_email'))
8686

8787
respond_to do |format|
8888
format.html { redirect_to @platform, notice: flash[:notice] }

app/models/better_together/address.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def update_buildings
6868
def at_least_one_address_type
6969
return if physical || postal
7070

71-
errors.add(:base, 'Address must be either physical, postal, or both')
71+
errors.add(:base, I18n.t('errors.models.address_missing_type'))
7272
end
7373

7474
def resolve_format(format, included, excluded)

app/models/better_together/person_block.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class PersonBlock < ApplicationRecord
1313
private
1414

1515
def not_self
16-
errors.add(:blocked_id, 'cannot block yourself') if blocker_id == blocked_id
16+
errors.add(:blocked_id, I18n.t('errors.person_block.cannot_block_self')) if blocker_id == blocked_id
1717
end
1818

1919
def blocked_not_platform_manager
2020
return unless blocked&.permitted_to?('manage_platform')
2121

22-
errors.add(:blocked, 'cannot be a platform manager')
22+
errors.add(:blocked, I18n.t('errors.person_block.cannot_block_manager'))
2323
end
2424
end
2525
end

app/models/better_together/wizard_step.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def unique_uncompleted_step_per_person # rubocop:todo Metrics/AbcSize, Metrics/M
4343

4444
# If the number of completed steps is equal to or exceeds the max completions allowed, add an error
4545
if completed_steps_count >= wizard.max_completions
46-
errors.add(:base, 'Maximum number of completions reached for this wizard and step definition.')
46+
errors.add(:base, I18n.t('errors.wizard.max_completions'))
4747
return
4848
end
4949
end
@@ -57,7 +57,7 @@ def unique_uncompleted_step_per_person # rubocop:todo Metrics/AbcSize, Metrics/M
5757

5858
return unless existing_step
5959

60-
errors.add(:base, 'Only one uncompleted step per person is allowed.')
60+
errors.add(:base, I18n.t('errors.wizard.one_uncompleted'))
6161
end
6262
# rubocop:enable Metrics/MethodLength
6363

@@ -68,7 +68,7 @@ def validate_step_completions
6868

6969
return unless completed_steps_count >= wizard.max_completions
7070

71-
errors.add(:base, "Number of completions for this step has reached the wizard's max completions limit.")
71+
errors.add(:base, I18n.t('errors.wizard.step_limit'))
7272
end
7373
end
7474
end

app/models/concerns/better_together/host.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def set_as_host
2929
def single_host_record
3030
return unless host && self.class.where.not(id:).exists?(host: true)
3131

32-
errors.add(:host, 'can only be set for one record')
32+
errors.add(:host, I18n.t('errors.models.host_single'))
3333
end
3434
end
3535
end

app/models/concerns/better_together/protected.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Protected
1010

1111
before_destroy do
1212
if protected?
13-
errors.add(:base, 'This record is protected and cannot be destroyed.')
13+
errors.add(:base, I18n.t('errors.models.protected_destroy'))
1414
throw(:abort)
1515
end
1616
end

0 commit comments

Comments
 (0)