def scan_file(path)
      keys = []
      text = read_file(path)
      text.scan(@pattern) do |match|
        src_pos = Regexp.last_match.offset(0).first
        location = occurrence_from_position(path, text, src_pos, raw_key: strip_literal(match[0]))
        next if exclude_line?(location.line, path)
        key = match_to_key(match, path, location)
        next unless key
        key += ':' if key.end_with?('.')
        next unless valid_key?(key)
        keys << [key, location]
      end
      keys
    rescue Exception => e # rubocop:disable Lint/RescueException
      raise ::I18n::Tasks::CommandError.new(e, "Error scanning #{path}: #{e.message}")
    end
def scan_file(path)
      keys = []
      text = read_file(path)
      text.scan(@pattern) do |match|
        src_pos = Regexp.last_match.offset(0).first
        location = occurrence_from_position(path, text, src_pos, raw_key: strip_literal(match[0]))
        next if exclude_line?(location.line, path)
        key = match_to_key(match, path, location)
        next unless key
        key += ':' if key.end_with?('.')
        next unless valid_key?(key)
        keys << [key, location]
      end
      keys
    rescue Exception => e # rubocop:disable Lint/RescueException
      raise ::I18n::Tasks::CommandError.new(e, "Error scanning #{path}: #{e.message}")
    end
Extract i18n keys from file based on the pattern which must capture the key literal.
 @return [Array<[key, Results::Occurrence]>] each occurrence found in the file