module

I18n

Constants

VERSION = "0.1.0"

Class methods

available_locales

An array of all available locales. Must be set explicitly.

I18n.available_locales = %w(en es)
Source
available_locales=(available_locales : Array(String))

An array of all available locales. Must be set explicitly.

I18n.available_locales = %w(en es)
Source
backend

A current Backend used by I18n. Can be changed in a runtime.

Source
backend=(backend : Backend | Nil)

A current Backend used by I18n. Can be changed in a runtime.

Source
default_locale

Default locale picked when no locale is passed to #translate.

Defaults to "en".

Source
default_locale=(default_locale : String)

Default locale picked when no locale is passed to #translate.

Defaults to "en".

Source
locale

Current locale. The next and ongoing translations will be made with this locale, if not passed explicitly.

I18n.locale = "es"
I18n.t("apples", count: 3) # => "3 manzanas"
Source
locale=(locale : String | Nil)

Current locale. The next and ongoing translations will be made with this locale, if not passed explicitly.

I18n.locale = "es"
I18n.t("apples", count: 3) # => "3 manzanas"
Source
rescue_missing

Whether to rescue Backend::TranslationNotFoundError when a translation is missing (defaults to true).

I18n.translate("unknown.key") # => "MISSING: en.unknown.key"
Source
rescue_missing=(rescue_missing : Bool)

Whether to rescue Backend::TranslationNotFoundError when a translation is missing (defaults to true).

I18n.translate("unknown.key") # => "MISSING: en.unknown.key"
Source

Instance methods

t(key : String, *a, **n)

ditto

Source
translate(keys : Array(String), locale : String | Nil = locale || default_locale, count : Int32 | Nil = nil) : String

Translates a value in a locale found by keys. Can pass count value to translate in plural form.

If locale not given, uses #locale or #default_locale.

I18n.translate(["hello", "world"])         # => "Hello world!"
I18n.translate(["apples"], "es", count: 3) # => "3 manzanas"
Source
translate(key : String, *a, **n)

A convenient overloader, keys are passed as a String with dot delimeters.

I18n.translate("hello.world")            # => "Hello world!"
I18n.translate("apples", "es", count: 3) # => "3 manzanas"
Source

Nested types