module I18n

Extended Modules

Defined in:

i18n.cr
i18n/backend.cr
i18n/version.cr

Constant Summary

VERSION = "0.1.0"

Class Method Summary

Instance Method Summary

Class Method Detail

def self.available_locales : Array(String) #

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

I18n.available_locales = %w(en es)

[View source]
def self.available_locales=(available_locales : Array(String)) #

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

I18n.available_locales = %w(en es)

[View source]
def self.backend : Backend | Nil #

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


[View source]
def self.backend=(backend : Backend | Nil) #

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


[View source]
def self.default_locale : String #

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

Defaults to "en".


[View source]
def self.default_locale=(default_locale : String) #

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

Defaults to "en".


[View source]
def self.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"

[View source]
def self.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"

[View source]
def self.rescue_missing : Bool #

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

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

[View source]
def self.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"

[View source]

Instance Method Detail

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

ditto


[View source]
def 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"

[View source]
def 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"

[View source]