Module: ViewComponent::Translatable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/view_component/translatable.rb
Defined Under Namespace
Classes: I18nBackend
Instance Method Summary collapse
-
#i18n_scope ⇒ Object
Exposes .i18n_scope as an instance method.
- #translate(key = nil, locale: nil, **options) ⇒ Object (also: #t)
Instance Method Details
#i18n_scope ⇒ Object
Exposes .i18n_scope as an instance method
77 78 79 |
# File 'lib/view_component/translatable.rb', line 77 def i18n_scope self.class.i18n_scope end |
#translate(key = nil, locale: nil, **options) ⇒ Object Also known as: t
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/view_component/translatable.rb', line 58 def translate(key = nil, locale: nil, **) locale ||= ::I18n.locale key = "#{i18n_scope}#{key}" if key.start_with?(".") result = catch(:exception) do i18n_backend.translate(locale, key, ) end # Fallback to the global translations if result.is_a? ::I18n::MissingTranslation result = helpers.t(key, locale: locale, **) end result end |