Class: Locomotive::Steam::TranslatorService
- Inherits:
-
Object
- Object
- Locomotive::Steam::TranslatorService
- Defined in:
- lib/locomotive/steam/services/translator_service.rb
Instance Method Summary collapse
-
#translate(input, options = {}) ⇒ String
Return the translation described by a key.
Instance Method Details
#translate(input, options = {}) ⇒ String
Return the translation described by a key.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/locomotive/steam/services/translator_service.rb', line 15 def translate(input, = {}) locale = ['locale'] || self.current_locale scope = .delete('scope') key = scope.present? ? "#{scope.gsub('.', '_')}_#{input}" : input key = "#{key}_#{pluralize_prefix(['count'])}" if ['count'] values = find_values_by_key(key) # FIXME: important to check if the returned value is nil (instead of nil + false) # false being reserved for an existing key but without provided translation) if (translation = values[locale.to_s]).present? _translate(translation, ) elsif output = I18n.t(input, scope: scope&.split('.'), locale: locale, default: nil) output else Locomotive::Common::Logger.warn "Missing translation '#{input}' for the '#{locale}' locale".yellow ActiveSupport::Notifications.instrument('steam.missing_translation', input: input, locale: locale) input end end |