Module: CMDx::Locale
Overview
Provides internationalization and localization support for CMDx. Handles translation lookups with fallback to default English 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 English translations if I18n gem is unavailable.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cmdx/locale.rb', line 40 def translate(key, **) [:default] ||= EN.dig("en", *key.to_s.split(".")) return ::I18n.t(key, **) if defined?(::I18n) case = .delete(:default) when NilClass then "Translation missing: #{key}" when String then % else end end |