<commit_before>require "translation_engine/version"
require 'translation_engine/action_view_extensions'

#refactor these includes at some point, if possible
require 'tasks/load_locales'
require 'tasks/database_tasks'

module TranslationEngine

  class Engine < ::Rails::Engine

    engine_name 'translation_engine'
    
  end

  def self.translate_text(key_param)
  	begin
      return "[" + key_param.to_s + "]" if I18n.locale == :tags
	    translation_key_id = TranslationKey.where("name = ?",key_param).first.id
	    locale_id = Locale.where("name = ?",I18n.locale).first.id
	    translation_records = Translation.where("translation_key_id = ? AND locale_id = ?", translation_key_id, locale_id)
	    #should add a Honeybadger call if multiple records returned.
	    translation_records.count > 0 ? translation_text = translation_records[0].value : translation_text = "Translation not found: key = #{key_param}"
      translation_text.sub! '%{age}', '65'
	    return translation_text
    rescue => e
      return "Translation not found: key = #{key_param}"
    end
  end

  def self.show_translation_item?(key_param)
    begin
      translation_key_id = TranslationKey.where("name = ?",key_param).first.id<commit_msg>remove load locale reference<commit_after>require "translation_engine/version"
require 'translation_engine/action_view_extensions'

#refactor these includes at some point, if possible
require 'tasks/database_tasks'

module TranslationEngine

  class Engine < ::Rails::Engine

    engine_name 'translation_engine'
    
  end

  def self.translate_text(key_param)
  	begin
      return "[" + key_param.to_s + "]" if I18n.locale == :tags
	    translation_key_id = TranslationKey.where("name = ?",key_param).first.id
	    locale_id = Locale.where("name = ?",I18n.locale).first.id
	    translation_records = Translation.where("translation_key_id = ? AND locale_id = ?", translation_key_id, locale_id)
	    #should add a Honeybadger call if multiple records returned.
	    translation_records.count > 0 ? translation_text = translation_records[0].value : translation_text = "Translation not found: key = #{key_param}"
      translation_text.sub! '%{age}', '65'
	    return translation_text
    rescue => e
      return "Translation not found: key = #{key_param}"
    end
  end

  def self.show_translation_item?(key_param)
    begin
      translation_key_id = TranslationKey.where("name = ?",key_param).first.id
{'fraction_non_alphanumeric': 0.10354785478547855, 'fraction_numerical': 0.006600660066006601, 'mean_word_length': 4.376940133037694, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3711489', 'n_tokens_mistral': 748, 'n_tokens_neox': 713, 'n_words': 168}