Add I18n support for flash messages and update locale file with new notices

This commit is contained in:
2026-01-30 20:19:12 -05:00
parent 5b31459629
commit e6818958ae
4 changed files with 26 additions and 7 deletions

View File

@@ -69,7 +69,7 @@ class CustomersController < ApplicationController
def create def create
@customer = Customer.new(allowed_params) @customer = Customer.new(allowed_params)
if @customer.save if @customer.save
flash[:notice] = "New Customer Created" flash[:notice] = t :notice_customer_created
redirect_to @customer redirect_to @customer
else else
flash[:error] = @customer.errors.full_messages.to_sentence flash[:error] = @customer.errors.full_messages.to_sentence
@@ -90,6 +90,7 @@ class CustomersController < ApplicationController
@issues.open.each { |i| @hours+= i.total_spent_hours } @issues.open.each { |i| @hours+= i.total_spent_hours }
@closed_issues.each { |i| @closed_hours+= i.total_spent_hours } @closed_issues.each { |i| @closed_hours+= i.total_spent_hours }
rescue rescue
flash[:error] = t :notice_customer_not_found
render_404 render_404
end end
end end
@@ -99,6 +100,7 @@ class CustomersController < ApplicationController
begin begin
@customer = Customer.find_by_id(params[:id]) @customer = Customer.find_by_id(params[:id])
rescue rescue
flash[:error] = t :notice_customer_not_found
render_404 render_404
end end
end end
@@ -108,13 +110,14 @@ class CustomersController < ApplicationController
begin begin
@customer = Customer.find_by_id(params[:id]) @customer = Customer.find_by_id(params[:id])
if @customer.update(allowed_params) if @customer.update(allowed_params)
flash[:notice] = "Customer updated" flash[:notice] = tv :notice_customer_updated
redirect_to @customer redirect_to @customer
else else
redirect_to edit_customer_path redirect_to edit_customer_path
flash[:error] = @customer.errors.full_messages.to_sentence if @customer.errors flash[:error] = @customer.errors.full_messages.to_sentence if @customer.errors
end end
rescue rescue
flash[:error] = t :notice_customer_not_found
render_404 render_404
end end
end end
@@ -123,9 +126,10 @@ class CustomersController < ApplicationController
def destroy def destroy
begin begin
Customer.find_by_id(params[:id]).destroy Customer.find_by_id(params[:id]).destroy
flash[:notice] = "Customer deleted successfully" flash[:notice] = t :notice_customer_deleted
redirect_to action: :index redirect_to action: :index
rescue rescue
flash[:error] = t :notice_customer_not_deleted
render_404 render_404
end end
end end
@@ -143,6 +147,7 @@ class CustomersController < ApplicationController
issue = Issue.find_by_id(params[:id]) issue = Issue.find_by_id(params[:id])
redirect_to view_path issue.share_token.token redirect_to view_path issue.share_token.token
rescue rescue
flash[:error] = t :notice_issue_not_found
render_404 render_404
end end
end end
@@ -178,6 +183,7 @@ class CustomersController < ApplicationController
@time_entry = TimeEntry.new(issue: @issue, project: @issue.project) @time_entry = TimeEntry.new(issue: @issue, project: @issue.project)
@relation = IssueRelation.new @relation = IssueRelation.new
rescue rescue
flash[:error] = t :notice_forbidden
render_403 render_403
end end
end end

View File

@@ -38,7 +38,7 @@ class EstimateController < ApplicationController
begin begin
send_data estimate.pdf, filename: "estimate #{estimate.doc_number}.pdf", disposition: :inline, type: "application/pdf" send_data estimate.pdf, filename: "estimate #{estimate.doc_number}.pdf", disposition: :inline, type: "application/pdf"
rescue rescue
redirect_to :back, flash: { error: "Estimate not found" } redirect_to :back, flash: { error: I18n.t(:notice_estimate_not_found) }
end end
end end
@@ -51,7 +51,7 @@ class EstimateController < ApplicationController
begin begin
send_data estimate.pdf, filename: "estimate #{estimate.doc_number}.pdf", disposition: :inline, type: "application/pdf" send_data estimate.pdf, filename: "estimate #{estimate.doc_number}.pdf", disposition: :inline, type: "application/pdf"
rescue rescue
redirect_to :back, flash: { error: "Estimate not found" } redirect_to :back, flash: { error: I18n.t(:notice_estimate_not_found) }
end end
end end

View File

@@ -48,7 +48,7 @@ class InvoiceController < ApplicationController
send_data @pdf, filename: "invoice #{ref}.pdf", disposition: :inline, type: "application/pdf" send_data @pdf, filename: "invoice #{ref}.pdf", disposition: :inline, type: "application/pdf"
end end
rescue rescue
redirect_to :back, flash: { error: "Invoice not found" } redirect_to :back, flash: { error: I18n.t(:notice_invoice_not_found) }
end end
end end
end end

View File

@@ -86,3 +86,16 @@ en:
label_sandbox: "Sandbox" label_sandbox: "Sandbox"
button_bulk_pdf: "Bulk PDF" button_bulk_pdf: "Bulk PDF"
label_select_all: "Select All" label_select_all: "Select All"
notice_customer_created: "Customer created in Quickbooks"
notice_customer_updated: "Customer updated in Quickbooks"
notice_customer_not_found: "Customer not found in Quickbooks"
notice_customer_not_deleted: "Customer could not be deleted in Quickbooks"
notice_customer_deleted: "Customer deleted in Quickbooks"
notice_estimate_created: "Estimate created in Quickbooks"
notice_estimate_updated: "Estimate updated in Quickbooks"
notice_estimate_not_found: "Estimate not found"
notice_invoice_created: "Invoice created in Quickbooks"
notice_invoice_updated: "Invoice updated in Quickbooks"
notice_invoice_not_found: "Invoice not found"
notice_forbidden: "You do not have permission to access this resource"
notice_issue_not_found: "Issue not found"