class Gettext::PluralForm::Interpreter

Overview

A interpreter that calculates the plural-form to take from syntax trees representing the plural-form expression.

Based on this interpreter from crafting interpreters

Defined in:

backend/gettext/plural-forms/interpreter.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(expressions : Array(Expression)) #

Creates an interpreter with the given expression trees from the PluralForm::Parser as input.

plural_form_scanner = Gettext::PluralForm::Scanner.new("nplurals=2; plural=(n > 1);")
expressions = Gettext::PluralForm::Parser.new(plural_form_scanner.scan).parse
interpreter = Gettext::PluralForm::Interpreter.new(expressions)
interpreter.interpret(1)  # => 0
interpreter.interpret(50) # => 1

[View source]

Instance Method Detail

def interpret(number) #

Calculates which plural form to use for the given number


[View source]