Sha256: 7ad700053fb3001cec076710d5a91a393419497b5e2076788e927531227aedbe

Contents?: true

Size: 722 Bytes

Versions: 3

Compression:

Stored size: 722 Bytes

Contents

# frozen_string_literal: true

module Servitium
  module I18n
    def t(key, passed_options = {})
      @service_scope ||= nil

      unless @service_scope.present?
        parts = (is_a?(Class) ? self : self.class).to_s.underscore.gsub('/', '.').split('.')
        parts[-1] = "#{parts.last.gsub('_service', '').pluralize}.service" if parts.last.end_with?('_service')
        parts[-1] = "#{parts.last.gsub('_context', '').pluralize}.context" if parts.last.end_with?('_context')
        @service_scope = parts.compact.join('.')
      end

      options = { scope: @service_scope }
      options[:default] = ::I18n.t(key) unless key.start_with?('.')

      ::I18n.t(key, **options.merge(passed_options))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
servitium-1.3.0 lib/servitium/i18n.rb
servitium-1.2.28 lib/servitium/i18n.rb
servitium-1.2.20 lib/servitium/i18n.rb