Sha256: 7dc20a266c542de49e00b47f9df6fc84566996b6677a6c976c95e780a68ea26f

Contents?: true

Size: 698 Bytes

Versions: 14

Compression:

Stored size: 698 Bytes

Contents

require 'i18n'
require 'dry/validation/messages/abstract'

module Dry
  module Validation
    class Messages::I18n < Messages::Abstract
      attr_reader :t

      ::I18n.load_path.concat(config.paths)

      def initialize
        super
        @t = I18n.method(:t)
      end

      def get(key, options = {})
        t.(key, options) if key
      end

      def key?(key, options)
        ::I18n.exists?(key, options.fetch(:locale, default_locale)) ||
        ::I18n.exists?(key, I18n.default_locale)
      end

      def merge(path)
        ::I18n.load_path << path
        self
      end

      def default_locale
        I18n.locale || I18n.default_locale || super
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
dry-validation-0.11.2 lib/dry/validation/messages/i18n.rb
dry-validation-0.12.1 lib/dry/validation/messages/i18n.rb
dry-validation-0.12.0 lib/dry/validation/messages/i18n.rb
dry-validation-0.11.1 lib/dry/validation/messages/i18n.rb
dry-validation-0.11.0 lib/dry/validation/messages/i18n.rb
dry-validation-0.10.7 lib/dry/validation/messages/i18n.rb
dry-validation-0.10.6 lib/dry/validation/messages/i18n.rb
dry-validation-0.10.5 lib/dry/validation/messages/i18n.rb
dry-validation-0.10.4 lib/dry/validation/messages/i18n.rb
dry-validation-0.10.3 lib/dry/validation/messages/i18n.rb
dry-validation-0.10.2 lib/dry/validation/messages/i18n.rb
dry-validation-0.10.1 lib/dry/validation/messages/i18n.rb
dry-validation-0.10.0 lib/dry/validation/messages/i18n.rb
dry-validation-0.9.5 lib/dry/validation/messages/i18n.rb