Files
grecia/config/initializers/i18n_translation.rb
Javi Martín 9d627f2db9 Remove redundant I18nContent scope
Since two records cannot have the same key, having a scope that will
always return just one record is the same as using `find_by_key`.
2019-09-24 19:29:46 +02:00

20 lines
563 B
Ruby

require "i18n/exceptions"
require "action_view/helpers/tag_helper"
module ActionView
module Helpers
module TranslationHelper
include TagHelper
def t(key, options = {})
current_locale = options[:locale].presence || I18n.locale
i18_content = I18nContent.find_by_key(key)
translation = I18nContentTranslation.where(i18n_content_id: i18_content&.id,
locale: current_locale).first&.value
translation.presence || translate(key, options)
end
end
end
end