Module: Zabon::Helper
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/zabon/helper.rb
Instance Method Summary collapse
-
#zabon_translate(key, **options) ⇒ Object
can be used as a replacement for ActionView::Helpers::TranslationHelper.translate will use original translate method if locale is not :ja or translation is missing if not will split translation into semantic chunks wrap them into a configurable HTML tag and join again.
Instance Method Details
#zabon_translate(key, **options) ⇒ Object
can be used as a replacement for ActionView::Helpers::TranslationHelper.translate will use original translate method if locale is not :ja or translation is missing if not will split translation into semantic chunks wrap them into a configurable HTML tag and join again
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zabon/helper.rb', line 14 def zabon_translate(key, **) orig_translate = [:orig_translate] || :translate = .except(:orig_translate) locale = ([:locale] || I18n.locale || :en).to_sym return public_send(orig_translate, key, **) if locale != :ja # if locale is not Japanese we use original method return key.map { |k| zabon_translate(k, **) } if key.is_a?(Array) return public_send(orig_translate, key, **) unless I18n.exists?(key, locale: :ja) orig_translation = public_send(orig_translate, key, **) orig_translation = ActionView::Base.full_sanitizer.sanitize(orig_translation, tags: []) if Zabon.config. Sentry.set_context("zabon", { key: key, locale: locale }) if defined?(Sentry) translation = Zabon.split(orig_translation).map do |segment| content_tag(Zabon.config.tag, segment, Zabon.config.) end.join.html_safe block_given? ? yield(translation, key) : translation end |