0

I'm trying to pluralize a word in the subject of a rails mailer :

these two don't working :

subject: "Réservation pour #{pluralize(@step.number_of_people.to_i, "personne")}"
subject: "Réservation pour #{pluralize(@step.number_of_people.to_i, "personne", locale: :fr)}"

but these two are working :

subject: "Réservation pour #{pluralize(@step.number_of_people.to_i, "personne", plural: 'personnes')}"
subject: "Réservation pour #{@step.number_of_people.to_i} #{"personne".pluralize(@step.number_of_people.to_i)}"

inflections.rb :

module Inflections
  ActiveSupport::Inflector.inflections(:fr) do |inflect|

    inflect.plural(/$/, 's')
    inflect.singular(/s$/, '')

    inflect.plural(/(bijou|caillou|chou|genou|hibou|joujou|pou|au|eu|eau)$/, '\1x')
    inflect.singular(/(bijou|caillou|chou|genou|hibou|joujou|pou|au|eu|eau)x$/, '\1')

    inflect.plural(/(bleu|émeu|landau|lieu|pneu|sarrau)$/, '\1s')
    inflect.plural(/al$/, 'aux')
    inflect.plural(/ail$/, 'ails')
    inflect.singular(/(journ|chev)aux$/, '\1al')
    inflect.singular(/ails$/, 'ail')

    inflect.plural(/(b|cor|ém|gemm|soupir|trav|vant|vitr)ail$/, '\1aux')
    inflect.singular(/(b|cor|ém|gemm|soupir|trav|vant|vitr)aux$/, '\1ail')

    inflect.plural(/(s|x|z)$/, '\1')

    inflect.irregular('monsieur', 'messieurs')
    inflect.irregular('madame', 'mesdames')
    inflect.irregular('mademoiselle', 'mesdemoiselles')
  end
end
Ben
  • 660
  • 5
  • 25
  • You're using the wrong tool. `ActiveSupport::Inflector` is really just meant to pluralize your class names and other words used in your code - in English. For handling user facing text you want to use the I18n module which is actually made to handle the complexity. https://guides.rubyonrails.org/i18n.html#pluralization – max Apr 17 '22 at 16:50
  • 1
    Adding a bunch of inflections for the frontend to ActiveSupport::Inflector can make your code do very strange things so I would not reccomend it. – max Apr 17 '22 at 16:58

0 Answers0