module I18n::Pluralization

Overview

Contains utilities allowing to pluralize translated strings.

Custom pluralization rules can be implemented by subclassing the I18n::Pluralization::Rule abstract class and by implementing a #rule method. Custom pluralization rules can then be registered for specific locale through the use of the #register_rule method.

class CustomRule < I18n::Pluralization::Rule
  def rule(count : Int) : Symbol
    count == 1 ? :one : :other
  end
end

I18n::Pluralization.register_rule("en-CA", CustomRule)

Defined in:

i18n/pluralization.cr
i18n/pluralization/rule.cr
i18n/pluralization/rule/arabic.cr
i18n/pluralization/rule/breton.cr
i18n/pluralization/rule/central_morocco_tamazight.cr
i18n/pluralization/rule/colognian.cr
i18n/pluralization/rule/east_slavic.cr
i18n/pluralization/rule/irish.cr
i18n/pluralization/rule/langi.cr
i18n/pluralization/rule/latvian.cr
i18n/pluralization/rule/lithuanian.cr
i18n/pluralization/rule/macedonian.cr
i18n/pluralization/rule/maltese.cr
i18n/pluralization/rule/manx.cr
i18n/pluralization/rule/one_other.cr
i18n/pluralization/rule/one_two_other.cr
i18n/pluralization/rule/one_up_to_two_other.cr
i18n/pluralization/rule/one_with_zero_other.cr
i18n/pluralization/rule/other.cr
i18n/pluralization/rule/polish.cr
i18n/pluralization/rule/romanian.cr
i18n/pluralization/rule/scottish_gaelic.cr
i18n/pluralization/rule/slovenian.cr
i18n/pluralization/rule/upper_sorbian.cr
i18n/pluralization/rule/welsh.cr
i18n/pluralization/rule/west_slavic.cr

Class Method Summary

Class Method Detail

def self.register_rule(locale : String | Symbol, rule_klass : Rule.class) #

Allows to register a pluralization rule for a specific locale.

This method will associate a specific locale to the passed rule_klass (subclass of I18n::Pluralization::Rule) and ensure that every pluralization performed for this locale are done using this rule.


def self.rule_for(locale : String | Symbol) #

Returns the rule registered for a specific locale, or nil if none is registered.