dry-rb / dry-schema

Coercion and validation for data structures
https://dry-rb.org/gems/dry-schema
MIT License
415 stars 108 forks source link

Support pluralization in I18n messages backend #465

Open cutalion opened 1 year ago

cutalion commented 1 year ago

It turned out that pluralization in i81n backend does not work, because :count is stripped out from provided options.

  en:
    foo:
      one: %{count} foo
      other: %{count} foos
  I18n.t(:foo, count: 1) #=> 1 foo
  I18n.t(:foo, count: 1) #=> 2 foos

I suggest to pass all options down to I18n.t method. Already tested this in production with dry-validation.

Not sure that the meta in case of pluralization should be returned when no :count provided, because meta and template are the same in that case. Is it ok?

template, meta = messages[:apples, path: :path]

expect(meta).to eql({
  one: "single apple",
  other: "%{count} apples"
})

expect(template.()).to eql({
  one: "single apple",
  other: "%{count} apples"
})