Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I18n messages backend does not support message metadata #210

Closed
robhanlon22 opened this issue Dec 12, 2019 · 0 comments · Fixed by #212
Closed

I18n messages backend does not support message metadata #210

robhanlon22 opened this issue Dec 12, 2019 · 0 comments · Fixed by #212
Labels
Milestone

Comments

@robhanlon22
Copy link
Member

robhanlon22 commented Dec 12, 2019

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
@solnic solnic added this to the 1.4.2 milestone Dec 12, 2019
solnic added a commit that referenced this issue Dec 19, 2019
Support metadata in I18n message backend

Closes #208 
Closes #210
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants