diff --git a/lib/i18n/tasks/data/router/isolating_router.rb b/lib/i18n/tasks/data/router/isolating_router.rb index f2ca2e5b..be55aaa3 100644 --- a/lib/i18n/tasks/data/router/isolating_router.rb +++ b/lib/i18n/tasks/data/router/isolating_router.rb @@ -9,11 +9,12 @@ module Data::Router class IsolatingRouter include ::I18n::Tasks::KeyPatternMatching - attr_reader :config_read_patterns, :base_locale + attr_reader :config_read_patterns, :base_locale, :locales def initialize(_adapter, data_config) @base_locale = data_config[:base_locale] @config_read_patterns = Array.wrap(data_config[:read]) + @locales = Array.wrap(data_config[:locales] || @base_locale) end # Route keys to destinations @@ -51,8 +52,9 @@ def route(locale, forest, &block) def alternate_path_for(source_path, locale) source_path = source_path.dup + locale_pattern = "{#{locales.join(',')}}" config_read_patterns.each do |pattern| - regexp = Glob.new(format(pattern, locale: '(*)')).to_regexp + regexp = Glob.new(format(pattern, locale: locale_pattern)).to_regexp next unless source_path.match?(regexp) source_path.match(regexp) do |match_data| diff --git a/spec/isolating_router_spec.rb b/spec/isolating_router_spec.rb index 42bcf15d..3a10c097 100644 --- a/spec/isolating_router_spec.rb +++ b/spec/isolating_router_spec.rb @@ -28,6 +28,7 @@ I18n::Tasks::Data::FileSystem.new( router: 'isolating_router', base_locale: 'en', + locales: %w[en fr], read: ['app/components/*.%{locale}.yml'] ) end @@ -56,7 +57,8 @@ describe 'alternate_path_for(source_path, locale)' do let(:read_config_patterns) { ['config/locales/**/*.%{locale}.yml'] } - let(:router) { I18n::Tasks::Data::Router::IsolatingRouter.new(nil, { read: read_config_patterns }) } + let(:base_locale) { :en } + let(:router) { I18n::Tasks::Data::Router::IsolatingRouter.new(nil, { base_locale: base_locale, read: read_config_patterns }) } context 'when `source_path` matches a pattern of the `read` configuration' do it 'changes only the `%{locale}` part of `source_path`' do