Files
grecia/config/initializers/i18n_translation.rb
rgarcia 4c8b174274 Display only translations for the current language
After creating a translation in spanish, it was also displaying it when selecting
the english locale.

This was due to the code picking the first translation available

With this commit, we are checking for an existing translation in the current locale
and displaying it if it exists
2018-07-26 21:55:07 -04:00

24 lines
639 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].present? ? options[:locale] : I18n.locale
i18_content = I18nContent.by_key(key).first
translation = I18nContentTranslation.where(i18n_content_id: i18_content&.id,
locale: current_locale).first&.value
if translation.present?
translation
else
translate(key, options)
end
end
end
end
end