Skip to content

I18n messages backend does not support message metadata #210

Closed
@robhanlon22

Description

@robhanlon22

To Reproduce

# example.rb

require "i18n"
require "dry-schema"

I18n.backend.store_translations(
  :en,
  dry_schema: {
    errors: {
      key?: {
        text: "is missing",
        code: "123"
      }
    }
  }
)

schema = Dry::Schema.Params do
  config.messages.backend = :i18n
  config.messages.load_paths = []

  required(:id)
end

schema.call({}).errors[:key?]
$ ruby example.rb
Traceback (most recent call last):
	8: from example.rb:23:in `<main>'
	7: from /Users/self/.rvm/gems/ruby-2.6.3/gems/dry-schema-1.4.1/lib/dry/schema/message_set.rb:79:in `[]'
	6: from /Users/self/.rvm/gems/ruby-2.6.3/gems/dry-schema-1.4.1/lib/dry/schema/message_set.rb:67:in `to_h'
	5: from /Users/self/.rvm/gems/ruby-2.6.3/gems/dry-schema-1.4.1/lib/dry/schema/message_set.rb:117:in `messages_map'
	4: from /Users/self/.rvm/gems/ruby-2.6.3/gems/dry-schema-1.4.1/lib/dry/schema/message_set.rb:117:in `reduce'
	3: from /Users/self/.rvm/gems/ruby-2.6.3/gems/dry-schema-1.4.1/lib/dry/schema/message_set.rb:117:in `each'
	2: from /Users/self/.rvm/gems/ruby-2.6.3/gems/dry-schema-1.4.1/lib/dry/schema/message_set.rb:124:in `block in messages_map'
	1: from /Users/self/.rvm/gems/ruby-2.6.3/gems/dry-schema-1.4.1/lib/dry/schema/message_set.rb:124:in `map!'
/Users/self/.rvm/gems/ruby-2.6.3/gems/dry-schema-1.4.1/lib/dry/schema/message.rb:55:in `dump': undefined method `empty?' for nil:NilClass (NoMethodError)

Expected behavior

Should not raise an error. Message should include the translated text as well as the metadata.

Your environment

  • Affects my production application: NO
  • Ruby version: 2.6.3
  • OS: macOS 10.14.6

Activity

added this to the 1.4.2 milestone on Dec 12, 2019
added a commit that references this issue on Dec 19, 2019

Merge pull request #212 from robhanlon22/i18n-metadata

d96be2c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @solnic@robhanlon22

      Issue actions

        I18n messages backend does not support message metadata · Issue #210 · dry-rb/dry-schema