<commit_before>module I18nDocs

  class CsvToYaml

    attr_reader :input_file, :output_file, :locales, :translations

    def initialize(input_file, output_file, locales = [])
      @input_file = input_file
      @output_file = File.basename(output_file)
      @locales = locales.map(&:to_s)

      # init translation hash
      @translations = {}
      @locales.each do |locale|
        @translations[locale] = {}
      end
    end


    def write_files
      @locales.each do |locale|
        if defined?(Rails)
          output_file_path = Rails.root.join('config', 'locales', locale, @output_file)
          FileUtils.mkdir_p File.dirname(output_file_path)
        else
          output_file_path = "#{locale}_#{@output_file}"
        end
        File.open(output_file_path, 'w') do |file|
          final_translation_hash = {locale => @translations[locale]}
          file.puts YAML::dump(final_translation_hash)
        end
        puts "File '#{@output_file}' for language '#{locale}' written to disc (#{output_file_path})"
      end
    end


    def process
      CSV.foreach(@input_file, headers: true) do |row|
        process_row(row.to_hash)
      end
    end

    def process_row(row_hash)
      key = row_hash.delete('key')
      return unless key

      key_elements = key.split('.')
      @locales.each do |locale|<commit_msg>tweak for use in kayla<commit_after>module I18nDocs

  class CsvToYaml

    attr_reader :input_file, :output_file, :locales, :translations

    def initialize(input_file, output_file, locales = [])
      @input_file = input_file
      @output_file = File.basename(output_file)
      @locales = locales.map(&:to_s)

      # init translation hash
      @translations = {}
      @locales.each do |locale|
        @translations[locale] = {}
      end
    end


    def write_files
      @locales.each do |locale|
        if defined?(Rails)
          output_file_path = Rails.root.join('config', 'locales', locale, @output_file)
          FileUtils.mkdir_p File.dirname(output_file_path)
        else
          output_file_path = "#{locale}_#{@output_file}"
        end
        File.open(output_file_path, 'w') do |file|
          final_translation_hash = {locale => @translations[locale]}
          file.puts YAML::dump(final_translation_hash)
        end
        puts "File '#{@output_file}' for language '#{locale}' written to disc (#{output_file_path})"
      end
    end


    def process
      CSV.foreach(@input_file, headers: true) do |row|
        process_row(row.to_hash)
      end
    end

    def process_row(row_hash)
      key = row_hash.delete('json_id')
      return unless key

      key_elements = key.split('.')
      @locales.each do |locale|
{'fraction_non_alphanumeric': 0.11032950758978156, 'fraction_numerical': 0.001480932987782303, 'mean_word_length': 2.6268456375838927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2617813', 'n_tokens_mistral': 880, 'n_tokens_neox': 857, 'n_words': 185}