<commit_before>module RailsI18nRecord
  module ActiveRecord
    module NonTranslatableMethods
      
      def translatable?
        (defined?(@translatable_atrrs) and @translatable_atrrs.any?)
      end
    
      def attr_translatable(*args)
        unless translatable?     
          send :include, RailsI18nRecord::ActiveRecord::TranslatableMethods
          default_scope :include => :translations
          attr_accessible :translations_attributes
          has_many :translations, :class_name => "#{name}Translation", :autosave => true, :dependent => :destroy    
          accepts_nested_attributes_for :translations                                        
          @translatable_atrrs = []                  
        end
        args.each do |arg|
          @translatable_atrrs << arg
          define_method "#{arg}=" do |value|     
            t = translation_by_locale(current_locale)
            t ? t.send("#{arg}=".to_sym, value) : translations.build(:locale => current_locale, arg.to_sym => value)        
          end        
          define_method "#{arg}" do
            t = translation_by_locale(current_locale)
            t ? t.send("#{arg}".to_sym) : nil             
          end           
          define_method "#{arg}_was" do          
            t = translation_by_locale(current_locale)
            t ? t.send("#{arg}_was".to_sym) : nil     
          end                
        end         
      end       
      
    end    
    module TranslatableMethods
      
      def with_locale(locale)
        @locale = locale
      end
      
      def build_translations
        I18n.available_locales.each do |locale| 
          t = translations.find_by_locale(locale)
          translations.build :locale => locale.to_s unless t
        end
      end      
      
      protected
      
      def current_locale
        defined?(@locale) ? @locale : I18n.locale
      end
      
      def translation_by_locale(locale)
        t = translations.find { |t| t.locale == locale.to_s }
        t ? t : translations.find_by_locale(locale)
      end
      <commit_msg>More readable code and fixes bug building translation with symbol<commit_after>module RailsI18nRecord
  module ActiveRecord
    module NonTranslatableMethods
      
      def translatable?
        not defined?(@translatable_atrrs).nil?
      end
    
      def attr_translatable(*args)
        unless translatable?     
          send :include, RailsI18nRecord::ActiveRecord::TranslatableMethods
          default_scope :include => :translations
          attr_accessible :translations_attributes
          has_many :translations, :class_name => "#{name}Translation", :autosave => true, :dependent => :destroy    
          accepts_nested_attributes_for :translations                                        
          @translatable_atrrs = []                  
        end
        args.each do |arg|
          @translatable_atrrs << arg
          define_method "#{arg}=" do |value|  
            t = translation_by_locale(current_locale)
            t ? t.send("#{arg}=".to_sym, value) : translations.build(:locale => current_locale.to_s, arg.to_sym => value)        
          end        
          define_method "#{arg}" do
            t = translation_by_locale(current_locale)
            t ? t.send("#{arg}".to_sym) : nil
          end           
          define_method "#{arg}_was" do          
            t = translation_by_locale(current_locale)
            t ? t.send("#{arg}_was".to_sym) : nil     
          end                
        end         
      end       
      
    end    
    module TranslatableMethods
      
      def with_locale(locale)
        @locale = locale
      end
      
      def build_translations
        I18n.available_locales.each do |locale| 
          t = translations.find_by_locale(locale)
          translations.build :locale => locale.to_s unless t
        end
      end      
      
      protected
      
      def current_locale
        defined?(@locale).nil? ? I18n.locale.to_s : @locale
      end
      
      def translation_by_locale(locale)
        t = translations.find { |t| t.locale == locale.to_s }
        t ? t : translations.find_by_locale(locale)
      end
      
{'fraction_non_alphanumeric': 0.08169547714894625, 'fraction_numerical': 0.003788775751835188, 'mean_word_length': 1.6599496221662469, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6945167', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1140, 'n_words': 238}