<commit_before>require 'net/https'

class I18nLocaleGenerator < Rails::Generators::NamedBase
  def main
    unless file_name =~ /^[a-zA-Z]{2}([-_][a-zA-Z]+)?$/
      log 'ERROR: Wrong locale format. Please input in ?? or ??-?? format.'
      exit
    end
    generate_configuration
    fetch_from_rails_i18n_repository
  end

  private
  def generate_configuration
    return if I18n.default_locale.to_s == locale_name
    log 'updating application.rb...'
#     environment "config.i18n.default_locale = :#{locale_name}"
    config = add_locale_config File.read(File.join(Rails.root, 'config/application.rb'))
    create_file 'config/application.rb', config
  end

  def add_locale_config(config_contents)
    new_line = "    config.i18n.default_locale = '#{locale_name}'"
    if config_contents =~ /\n *config\.i18n\.default_locale *=/
      config_contents.sub(/ *config\.i18n\.default_locale *=.*/, new_line)
    elsif config_contents =~ /\n *#? *config\.i18n\.default_locale *=/<commit_msg>Let generated i18n.default_locale be a Symbol<commit_after>require 'net/https'

class I18nLocaleGenerator < Rails::Generators::NamedBase
  def main
    unless file_name =~ /^[a-zA-Z]{2}([-_][a-zA-Z]+)?$/
      log 'ERROR: Wrong locale format. Please input in ?? or ??-?? format.'
      exit
    end
    generate_configuration
    fetch_from_rails_i18n_repository
  end

  private
  def generate_configuration
    return if I18n.default_locale.to_s == locale_name
    log 'updating application.rb...'
#     environment "config.i18n.default_locale = :#{locale_name}"
    config = add_locale_config File.read(File.join(Rails.root, 'config/application.rb'))
    create_file 'config/application.rb', config
  end

  def add_locale_config(config_contents)
    new_line = "    config.i18n.default_locale = :#{locale_name}"
    if config_contents =~ /\n *config\.i18n\.default_locale *=/
      config_contents.sub(/ *config\.i18n\.default_locale *=.*/, new_line)
    elsif config_contents =~ /\n *#? *config\.i18n\.default_locale *=/
{'fraction_non_alphanumeric': 0.13769192669638436, 'fraction_numerical': 0.017830609212481426, 'mean_word_length': 3.6867749419953597, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4549691', 'n_tokens_mistral': 714, 'n_tokens_neox': 663, 'n_words': 129}