module I18n

Extended Modules

Defined in:

i18n.cr
i18n/backend/base.cr
i18n/backend/yaml.cr
i18n/config.cr
i18n/config/plural_rules.cr
i18n/exceptions.cr
i18n/version.cr

Constant Summary

VERSION = "0.4.1"

Instance Method Summary

Macro Summary

Instance Method Detail

def available_locales #

[View source]
def available_locales=(value) #

[View source]
def backend #

[View source]
def backend=(value) #

[View source]
def config #

Gets I18n configuration object.


[View source]
def config=(value) #

Sets I18n configuration object.


[View source]
def default_locale #

[View source]
def default_locale=(value) #

[View source]
def default_separator #

[View source]
def default_separator=(value) #

[View source]
def exception_handler #

[View source]
def exception_handler=(value) #

[View source]
def exists?(key : String, force_locale = config.locale, count = nil) : Bool #

Returns whether a translation exists for a given key.


[View source]
def init #

[View source]
def load_path #

[View source]
def load_path=(value) #

[View source]
def locale #

[View source]
def locale=(value) #

[View source]
def localize(object, force_locale = config.locale, *args, **options) : String #

Localizes certain objects, such as dates and numbers to local formatting.


[View source]
def plural_rules #

[View source]
def plural_rules=(value) #

[View source]
def translate(key : String, options : Hash | NamedTuple? = nil, force_locale = config.locale, count = nil, default = nil, iter = nil) : String #

Translates, pluralizes and interpolates a given key using a given locale, default, as well as interpolation values.

INTERPOLATION

Translations can contain interpolation variables which will be replaced by values passed to #translate as part of the options hash, with the keys matching the interpolation variable names.

E.g., with a translation "foo" => "foo %{bar}" the option value for the key bar will be interpolated into the translation:

I18n.translate("foo", {"bar" => "baz"}) # => 'foo baz'

PLURALIZATION

Translation data can contain pluralized translations. Pluralized translations are arrays of singular/plural versions of translations like ["Foo", "Foos"].

This returns the singular version of a pluralized translation:

I18n.translate("foo", count: 1) # => "Foo"

DEFAULTS

This returns the translation for "foo" or "default" if no translation was found:

I18n.translate("foo", default: "default')

[View source]
def with_locale(tmp_locale, &) #

Executes block with given I18.locale set.


[View source]

Macro Detail

macro define_delegators(names) #

[View source]