Skip to content

I18n nested text and missing options when using lambda #492

@roksanarothenberger-monterail

Description

Describe the bug

When using I18n for translations and returning hash with lambda the text the whole hash is put inside it's text field, and initial call for meta is not sending options to I18n, so if we want to introduce meta data based on those there is nothing there.

To Reproduce

require "dry-schema"
require "i18n"

I18n.backend.store_translations(:en, dry_schema: {
    errors: {
      max_size?: ->(*, **kargs) { {text: "is over limit", max_size: kargs[:num]} }
    }
  }
)

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

  required(:type).value(:string, max_size?: 1)
end

puts schema.call({type: "abc"}).errors.to_h
ruby example.rb

{type: [{text: {text: "is over limit", max_size: 1}, max_size: nil}]}

Expected behavior

Message should not be nested and options should be provided to call for meta attributes.

ruby example.rb

{type: [{text: "is over limit", max_size: 1}]}

My environment

  • Affects my production application: YES
  • Ruby version: 3.4.5
  • OS: Ubuntu 24.04/Alpine 3.22

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions