diff --git a/config/application.rb b/config/application.rb index c4cbe173642..f899203330b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -43,7 +43,7 @@ class Application < Rails::Application config.asset_sources = AssetSources.new( manifest_path: Rails.public_path.join('packs', 'manifest.json'), cache_manifest: Rails.env.production? || Rails.env.test?, - i18n_locales: Idp::Constants::AVAILABLE_LOCALES, + i18n_locales: IdentityConfig.store.available_locales, ) console do @@ -113,7 +113,7 @@ class Application < Rails::Application config.time_zone = 'UTC' config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{yml}')] - config.i18n.available_locales = Idp::Constants::AVAILABLE_LOCALES + config.i18n.available_locales = IdentityConfig.store.available_locales config.i18n.default_locale = :en config.action_controller.per_form_csrf_tokens = true diff --git a/config/application.yml.default b/config/application.yml.default index 8c2cdf0de5f..4327fc3af62 100644 --- a/config/application.yml.default +++ b/config/application.yml.default @@ -23,6 +23,7 @@ aamva_verification_url: https://example.org:12345/verification/url all_redirect_uris_cache_duration_minutes: 2 allowed_ialmax_providers: '[]' allowed_verified_within_providers: '[]' +available_locales: 'en,es,fr' account_reset_token_valid_for_days: 1 account_reset_fraud_user_wait_period_days: account_reset_wait_period_days: 1 diff --git a/config/initializers/rack_timeout.rb b/config/initializers/rack_timeout.rb index 4c76e637430..201e24f311a 100644 --- a/config/initializers/rack_timeout.rb +++ b/config/initializers/rack_timeout.rb @@ -10,7 +10,7 @@ class Timeout '/verify/document_capture', '/verify/link_sent', ].flat_map do |path| - [path] + Idp::Constants::AVAILABLE_LOCALES.map { |locale| "/#{locale}#{path}" } + [path] + IdentityConfig.store.available_locales.map { |locale| "/#{locale}#{path}" } end + ['/api/verify/images']).freeze def call_with_excludes(env) diff --git a/lib/identity_config.rb b/lib/identity_config.rb index 9b4c2e42c00..841c6dd6e6f 100644 --- a/lib/identity_config.rb +++ b/lib/identity_config.rb @@ -136,6 +136,7 @@ def self.build_store(config_map) config.add(:async_wait_timeout_seconds, type: :integer) config.add(:attribute_encryption_key, type: :string) config.add(:attribute_encryption_key_queue, type: :json) + config.add(:available_locales, type: :comma_separated_string_list) config.add(:aws_http_retry_limit, type: :integer) config.add(:aws_http_retry_max_delay, type: :integer) config.add(:aws_http_timeout, type: :integer) diff --git a/lib/idp/constants.rb b/lib/idp/constants.rb index 7c56c623e06..2090c4b420b 100644 --- a/lib/idp/constants.rb +++ b/lib/idp/constants.rb @@ -2,7 +2,6 @@ module Idp module Constants - AVAILABLE_LOCALES = %w[en es fr].freeze UUID_REGEX = /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/ KMS_LOG_FILENAME = 'kms.log' diff --git a/lib/telephony/pinpoint/voice_sender.rb b/lib/telephony/pinpoint/voice_sender.rb index 0a371936616..8cefe338429 100644 --- a/lib/telephony/pinpoint/voice_sender.rb +++ b/lib/telephony/pinpoint/voice_sender.rb @@ -5,6 +5,12 @@ module Telephony module Pinpoint class VoiceSender + DEFAULT_VOICE_ID = ['en-US', 'Joey'].freeze + LANGUAGE_CODE_TO_VOICE_ID = { + en: DEFAULT_VOICE_ID, + fr: ['fr-FR', 'Mathieu'], + es: ['es-US', 'Miguel'], + }.freeze # One connection pool per config (aka per-region) # rubocop:disable Style/MutableConstant CLIENT_POOL = Hash.new do |h, voice_config| @@ -98,16 +104,7 @@ def handle_pinpoint_error(err) end def language_code_and_voice_id - case I18n.locale.to_sym - when :en - ['en-US', 'Joey'] - when :fr - ['fr-FR', 'Mathieu'] - when :es - ['es-US', 'Miguel'] - else - ['en-US', 'Joey'] - end + LANGUAGE_CODE_TO_VOICE_ID.fetch(I18n.locale.to_sym, DEFAULT_VOICE_ID) end end end diff --git a/spec/lib/telephony/pinpoint/voice_sender_spec.rb b/spec/lib/telephony/pinpoint/voice_sender_spec.rb index d0961f64296..f82bfc378cd 100644 --- a/spec/lib/telephony/pinpoint/voice_sender_spec.rb +++ b/spec/lib/telephony/pinpoint/voice_sender_spec.rb @@ -26,6 +26,13 @@ def mock_build_clients(client: pinpoint_client, backup_client: backup_pinpoint_c ) end + describe 'LANGUAGE_CODE_TO_VOICE_ID' do + it 'contains a key for every available locale' do + expect( + Telephony::Pinpoint::VoiceSender::LANGUAGE_CODE_TO_VOICE_ID.keys.sort, + ).to eq I18n.available_locales.sort + end + end describe '#deliver' do let(:pinpoint_response) do double(message_id: 'fake-message-id')