Module: CMDx::Locale
Overview
Provides internationalization and localization support for CMDx. Handles translation lookups with fallback to the configured locale’s default messages when I18n gem is not available.
Instance Method Summary collapse
-
#translate(key, **options) ⇒ String
(also: #t)
Translates a key to the current locale with optional interpolation.
Instance Method Details
#translate(key, **options) ⇒ String Also known as: t
Translates a key to the current locale with optional interpolation. Falls back to the configured locale’s YAML file translations if I18n gem is unavailable.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cmdx/locale.rb', line 37 def translate(key, **) [:default] ||= translation_default(key) return ::I18n.t(key, **) if defined?(::I18n) case = .delete(:default) when String then % when NilClass then "Translation missing: #{key}" else end end |