<commit_before>module TranslationCenter

  class TranslationKey < ActiveRecord::Base
    attr_accessible :name, :last_accessed, :category_id
    belongs_to :category
    has_many :translations, dependent: :destroy

    # validations
    validates :name, uniqueness: true
    validates :category, :name, presence: true

    # called after key is created or updated
    before_save :add_category

    PER_PAGE = 7

    # add a category of this translation key
    def add_category
      category_name = self.name.to_s.split('.').first
      # if one word then add to general category
      category_name = 'general' if self.name.to_s.split('.').size == 1
      category = Category.find_or_initialize_by_name(category_name)
      category.save if category.new_record?
      self.category_id = category.id
      self.last_accessed = Time.now
    end

    # returns true if the key has an accepted translation in this lang
    def accepted_in?(lang)
      !self.accepted_translation_in(lang).blank?
    end
    alias_method :translated_in?, :accepted_in?

    # returns the accepted translation in certain language
    def accepted_translation_in(lang)
      self.translations.accepted.in(lang).first
    end

    # returns true if the translation key has no translations in the language
    def no_translations_in?(lang)
      self.translations.in(lang).empty?<commit_msg>no need to validate category presense as it is added in the before save<commit_after>module TranslationCenter

  class TranslationKey < ActiveRecord::Base
    attr_accessible :name, :last_accessed, :category_id
    belongs_to :category
    has_many :translations, dependent: :destroy

    # validations
    validates :name, uniqueness: true
    validates :name, presence: true

    # called after key is created or updated
    before_save :add_category

    PER_PAGE = 7

    # add a category of this translation key
    def add_category

      category_name = self.name.to_s.split('.').first

      # if one word then add to general category
      category_name = self.name.to_s.split('.').size == 1 ? 'general' : self.name.to_s.split('.').first
      self.category = Category.find_or_create_by_name(category_name)
      self.last_accessed = Time.now
    end

    # returns true if the key has an accepted translation in this lang
    def accepted_in?(lang)
      !self.accepted_translation_in(lang).blank?
    end
    alias_method :translated_in?, :accepted_in?

    # returns the accepted translation in certain language
    def accepted_translation_in(lang)
      self.translations.accepted.in(lang).first
    end

    # returns true if the translation key has no translations in the language
    def no_translations_in?(lang)
      self.translations.in(lang).empty?
{'fraction_non_alphanumeric': 0.07523739956172389, 'fraction_numerical': 0.0014609203798392988, 'mean_word_length': 3.4248788368336025, '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': '3218785', 'n_tokens_mistral': 799, 'n_tokens_neox': 770, 'n_words': 236}