diff --git a/lib/i18n/tasks/scanners/prism_scanners/nodes.rb b/lib/i18n/tasks/scanners/prism_scanners/nodes.rb index bca14063..1ecd1f64 100644 --- a/lib/i18n/tasks/scanners/prism_scanners/nodes.rb +++ b/lib/i18n/tasks/scanners/prism_scanners/nodes.rb @@ -140,9 +140,9 @@ def scope return nil if @options.nil? return nil unless @options["scope"] - fail(ScopeError, "Could not process scope") if @options.key?("scope") && Array(@options["scope"]).empty? + fail(ScopeError, "Could not process scope") if @options.key?("scope") && (Array(@options["scope"]).empty? || !Array(@options["scope"]).all? { |s| s.is_a?(String) || s.is_a?(Symbol) }) - Array(@options["scope"]).compact.map(&:to_s).join(".") + Array(@options["scope"]).join(".") end def occurrence(file_path) diff --git a/spec/prism_scanner_spec.rb b/spec/prism_scanner_spec.rb index ea659397..086fdd2a 100644 --- a/spec/prism_scanner_spec.rb +++ b/spec/prism_scanner_spec.rb @@ -594,18 +594,28 @@ def what it "handles scope" do source = <<~RUBY scope = 'special.events' + # These should be detected t('scope_string', scope: 'events.descriptions') I18n.t('scope_array', scope: ['events', 'titles']) - I18n.t(model.key, **translation_options(model)) - I18n.t("success", scope: scope) I18n.t("scope_array_symbol", scope: %i[events descriptions]) I18n.t("scope_array_words", scope: %w[events descriptions]) + + # Cannot handle, should ignore + I18n.t("scope_with_known_variable", scope: ["this", "that", scope]) + I18n.t("scope_with_unknown", scope: ["this", "that", unknown, "other"]) + I18n.t(model.key, **translation_options(model)) + I18n.t("success", scope: scope) RUBY occurrences = process_string("scope.rb", source) expect(occurrences.map(&:first).uniq).to match_array( - %w[events.descriptions.scope_string events.titles.scope_array events.descriptions.scope_array_symbol events.descriptions.scope_array_words] + %w[ + events.descriptions.scope_string + events.titles.scope_array + events.descriptions.scope_array_symbol + events.descriptions.scope_array_words + ] ) end end