<commit_before>module FrontendNotifierControllerExtension
  
  def notify_frontend(message, error_type="error")
    unless message.kind_of? String || message.nil?
      if message.errors.empty?  
        message = "Success"
        error_type = "success"
      else
        message = join_model_errors(message) 
      end
    end
    render :json => { :type => error_type, :message => message  }
  end

  private

    def join_model_errors(model, options = { include_field_names: true })
      result = []
      model.errors.each do |k,v|
        if k == :base
          result << v
        else
          if options[:include_field_names]
            result << "#{k} #{v}"
          else
            result << v
          end
        end
      end
      result = result.join("; ")
      dot_at_the_end = (result =~ /[.!?]\Z/) ? "" : "."
      result + dot_at_the_end
    end

end<commit_msg>Fix: #join_model_errors now uses I18n to find model attributes names<commit_after>module FrontendNotifierControllerExtension
  
  def notify_frontend(message, error_type="error")
    unless message.kind_of? String || message.nil?
      if message.errors.empty?  
        message = "Success"
        error_type = "success"
      else
        message = join_model_errors(message) 
      end
    end
    render :json => { :type => error_type, :message => message  }
  end

  private

    def join_model_errors(model, options = { include_field_names: true })
      result = []
      model.errors.each do |k,v|
        if k == :base
          result << v
        else
          if options[:include_field_names]
            attr_translation = t("activerecord.attributes.#{model.class.to_s.underscore}.#{k}")
            attr_translation = k if attr_translation.include?("translation missing")
            result << "#{attr_translation.to_s.mb_chars.capitalize.to_s} #{v}"
          else
            result << v
          end
        end
      end
      result = result.join("; ")
      dot_at_the_end = (result =~ /[.!?]\Z/) ? "" : "."
      result + dot_at_the_end
    end

end
{'fraction_non_alphanumeric': 0.11342704798836646, 'fraction_numerical': 0.0009694619486185168, 'mean_word_length': 2.1272727272727274, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7651893', 'n_tokens_mistral': 630, 'n_tokens_neox': 619, 'n_words': 141}