module

I18n::Pluralization

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)

Class methods

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.

Source
rule_for(locale : String | Symbol)

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

Source

Nested types