From 82260d8c62704fd8d613a5801abc56319e8b0907 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Fri, 14 May 2021 11:57:52 +0200 Subject: [PATCH] [bug] invalid currency in notifications for locales with region --- CHANGELOG.md | 3 ++- app/controllers/application_controller.rb | 8 ++++++++ config/application.rb | 7 ++++--- config/environments/production.rb | 4 ---- config/environments/staging.rb | 4 ---- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de30d2dac..f4d768d4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,12 @@ - Prevent the worker from crashing if OpenLab is not reachable in dev - Allow setting multiple themes for a single event - Increased the width of the input field for the prices of the events +- Fix a bug: invalid currency in notifications for locales with region (eg. fr-CM) - Fix a bug: the notification sent to the project author when a collaborator has confirmed his participation is not sent - Fix a bug: the event themes are not kept when editing the event again - Fix a bug: the count of successfully updated events was not correct - Fix a bug: german watermark was missing -- Fix a bug: invoices are not generated in test/development if the configured locale is composed (eg. fr-CA) +- Fix a bug: invoices are not generated in test/development for locale with region (eg. fr-CA) - Fix a security issue: updated underscore to 1.12.1 to fix [CVE-2021-23358](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-23358) - Fix a security issue: updated lodash to 4.17.21 to fix [CVE-2021-23337](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-23337) - Fix a security issue: updated url-parse to 1.5.1 to fix [CVE-2021-27515](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-27515) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 10b7c224b..2077f304a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base respond_to :html, :json before_action :configure_permitted_parameters, if: :devise_controller? + around_action :switch_locale # Globally rescue Authorization Errors in controller. # Returning 403 Forbidden if permission is denied @@ -61,6 +62,13 @@ class ApplicationController < ActionController::Base head 403 end + # Set the configured locale for each action (API call) + # @see https://guides.rubyonrails.org/i18n.html + def switch_locale(&action) + locale = params[:locale] || Rails.application.secrets.rails_locale + I18n.with_locale(locale, &action) + end + # @return [User] # This is a placeholder for Devise's current_user. # As Devise generate the method at runtime, IDEs autocomplete features will complain about 'method not found' diff --git a/config/application.rb b/config/application.rb index 8f6eafc0c..7e133c12f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -40,9 +40,6 @@ module Fablab # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. config.time_zone = Rails.application.secrets.time_zone - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - config.to_prepare do Devise::Mailer.layout 'notifications_mailer' end @@ -66,6 +63,10 @@ module Fablab # enable the app to find locales in plugins locales directory config.i18n.load_path += Dir["#{Rails.root}/plugins/*/config/locales/*.yml"] + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + # enable the app to find views in plugins views directory Dir["#{Rails.root}/plugins/*/views"].each do |path| Rails.application.config.paths['app/views'] << path diff --git a/config/environments/production.rb b/config/environments/production.rb index 178b5c2d2..3d91fb921 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -86,10 +86,6 @@ Rails.application.configure do # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation cannot be found). - config.i18n.fallbacks = true - # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 5741e847f..5b25c544d 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -57,10 +57,6 @@ Rails.application.configure do # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation cannot be found). - config.i18n.fallbacks = true - # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify