From 7ac119d4cf144a2fd0cc19896159ca70ba91b09a Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 12 May 2021 16:58:39 +0200 Subject: [PATCH] [bug] invoices are not generated in test/development if the configured locale is composed Eg. If locale is fr-CA, it was crashing. If locale was only fr, is was working. Now, composed locales print the watermark using the base locale and hour_minute format is fetched from the base locale --- CHANGELOG.md | 1 + app/controllers/api/translations_controller.rb | 3 ++- app/pdfs/pdf/invoice.rb | 2 +- app/pdfs/pdf/payment_schedule.rb | 2 +- .../_notify_admin_user_wallet_is_credited.json.jbuilder | 8 +++++--- config/initializers/locale.rb | 4 ++-- config/locales/base.de.yml | 5 +++++ doc/translation_readme.md | 3 +++ 8 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 config/locales/base.de.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a4b33242..de30d2dac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - 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 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/api/translations_controller.rb b/app/controllers/api/translations_controller.rb index 31d1a4302..cca3f47e4 100644 --- a/app/controllers/api/translations_controller.rb +++ b/app/controllers/api/translations_controller.rb @@ -4,7 +4,6 @@ class API::TranslationsController < API::ApiController before_action :set_locale - def show translations = I18n.t params[:state] if translations.class.name == String.name && translations.start_with?('translation missing') @@ -16,6 +15,8 @@ class API::TranslationsController < API::ApiController end end + private + def set_locale I18n.locale = params[:locale] || I18n.default_locale end diff --git a/app/pdfs/pdf/invoice.rb b/app/pdfs/pdf/invoice.rb index b96e45e53..d92c94d5b 100644 --- a/app/pdfs/pdf/invoice.rb +++ b/app/pdfs/pdf/invoice.rb @@ -353,7 +353,7 @@ class PDF::Invoice < Prawn::Document transparent(0.1) do rotate(45, origin: [0, 0]) do - image "#{Rails.root}/app/pdfs/data/watermark-#{I18n.locale}.png", at: [90, 150] + image "#{Rails.root}/app/pdfs/data/watermark-#{I18n.default_locale}.png", at: [90, 150] end end end diff --git a/app/pdfs/pdf/payment_schedule.rb b/app/pdfs/pdf/payment_schedule.rb index dbe41a566..42f011606 100644 --- a/app/pdfs/pdf/payment_schedule.rb +++ b/app/pdfs/pdf/payment_schedule.rb @@ -126,7 +126,7 @@ class PDF::PaymentSchedule < Prawn::Document transparent(0.1) do rotate(45, origin: [0, 0]) do - image "#{Rails.root}/app/pdfs/data/watermark-#{I18n.locale}.png", at: [90, 150] + image "#{Rails.root}/app/pdfs/data/watermark-#{I18n.default_locale}.png", at: [90, 150] end end end diff --git a/app/views/api/notifications/_notify_admin_user_wallet_is_credited.json.jbuilder b/app/views/api/notifications/_notify_admin_user_wallet_is_credited.json.jbuilder index c79d7afdc..90c8576a4 100644 --- a/app/views/api/notifications/_notify_admin_user_wallet_is_credited.json.jbuilder +++ b/app/views/api/notifications/_notify_admin_user_wallet_is_credited.json.jbuilder @@ -1,7 +1,9 @@ +# frozen_string_literal: true + json.title notification.notification_type amount = notification.attached_object.amount json.description t('.wallet_is_credited', - AMOUNT: number_to_currency(amount), - USER: notification.attached_object.wallet.user&.profile&.full_name || t('api.notifications.deleted_user'), - ADMIN: notification.attached_object.user&.profile&.full_name || t('api.notifications.deleted_user')) + AMOUNT: number_to_currency(amount), + USER: notification.attached_object.wallet.user&.profile&.full_name || t('api.notifications.deleted_user'), + ADMIN: notification.attached_object.user&.profile&.full_name || t('api.notifications.deleted_user')) diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb index 35a4ee128..07b6b4f88 100644 --- a/config/initializers/locale.rb +++ b/config/initializers/locale.rb @@ -2,7 +2,7 @@ # List of all allowed values for RAILS_LOCALE I18n.config.available_locales += %i[de de-AT de-CH de-DE - en en-AU-CA en-GB en-IE en-IN en-NZ en-US en-ZA + en en-AU en-CA en-GB en-IE en-IN en-NZ en-US en-ZA fr fa-CA fr-CH fr-CM fr-FR es es-419 es-AR es-CL es-CO es-CR es-DO es-EC es-ES es-MX es-PA es-PE es-US es-VE pt pt-BR @@ -14,5 +14,5 @@ I18n.config.available_locales += %i[de de-AT de-CH de-DE # # /!\ ALL locales SHOULD be configured accordingly with the default_locale. /!\ # -I18n.config.default_locale = Rails.application.secrets.rails_locale +I18n.config.default_locale = Rails.application.secrets.rails_locale.to_s.split('-')[0] I18n.config.locale = Rails.application.secrets.rails_locale diff --git a/config/locales/base.de.yml b/config/locales/base.de.yml new file mode 100644 index 000000000..53217f414 --- /dev/null +++ b/config/locales/base.de.yml @@ -0,0 +1,5 @@ +de: + time: + formats: + # See http://apidock.com/ruby/DateTime/strftime for a list of available directives + hour_minute: "%I:%M %p" diff --git a/doc/translation_readme.md b/doc/translation_readme.md index dc529fdd0..8a8c98d92 100644 --- a/doc/translation_readme.md +++ b/doc/translation_readme.md @@ -77,6 +77,9 @@ You will also need to translate the invoice watermark, located in `app/pdfs/data You'll find there the [GIMP source of the image](app/pdfs/data/watermark.xcf), which is using [Rubik Mono One](https://fonts.google.com/specimen/Rubik+Mono+One) as font. Use it to generate a similar localised PNG image which keep the default image size, as PDF are not responsive. +Also, please create a [base.LOCALE.yml](../config/locales/base.en.yml) and fill it with the time-only format in use in your locale. + +Finally, add your new locale and its derivatives to the `available_locales` array in [initializers/locale.rb](../config/initializers/locale.rb) to make it available in Fab-manager. ## Configuration