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 36 |
# File 'lib/locomotive/steam/services/translator_service.rb', line 15 def translate(input, = {}) locale = ['locale'] || self.current_locale scope = .delete('scope') if scope.blank? input = "#{input}_#{pluralize_prefix(['count'])}" if ['count'] values = repository.by_key(input).try(:values) || {} # 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, ) 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 else I18n.t(input, scope: scope.split('.'), locale: locale) end end |