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

Support pluralization in I18n messages backend #465

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cutalion
Copy link

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"
})

Pass all provided options down to I18n.t method. It will use `:count`
option to pluralize the message.

  en:
    foo:
      one: %{count} foo
      other: %{count} foos

  I18n.t(:foo, count: 1) #=> 1 foo
  I18n.t(:foo, count: 1) #=> 2 foos
@cutalion cutalion force-pushed the feature/support-pluralization branch from 1f8a52f to 20f396c Compare August 25, 2023 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant