Skip to content
joshmh edited this page Sep 13, 2010 · 2 revisions

Overview of experimental pluralize backend

Different pluralization rulesets for a different locales can be stored to the pluralize backend.

The pluralizer backend has a #add_pluralizer function that accepts lambda code block as a pluralization rule for the given locale:


  # Instantiating backend
  backend = I18n::Backend::Pluralizing.new

  # Pluralization ruleset for :cz locale
  cz_pluralizer = lambda{ |c| c == 1 ? :one : (2..4).include?(c) ? :few : :other }

  # Adding ruleset to pluralize backend
  backend.add_pluralizer(:cz, cz_pluralizer)

  # Pluralization rules are used when requesting translation for :cz locale
  I18n.translate :cz, :foo

  # Backend defaults to :en locale in case no ruleset is defined for given locale
  I18n.translate :fi, :foo

Clone this wiki locally