module I18n
Extended Modules
Defined in:
i18n.cri18n/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
- #available_locales
- #available_locales=(value)
- #backend
- #backend=(value)
-
#config
Gets I18n configuration object.
-
#config=(value)
Sets I18n configuration object.
- #default_locale
- #default_locale=(value)
- #default_separator
- #default_separator=(value)
- #exception_handler
- #exception_handler=(value)
-
#exists?(key : String, force_locale = config.locale, count = nil) : Bool
Returns whether a translation exists for a given key.
- #init
- #load_path
- #load_path=(value)
- #locale
- #locale=(value)
-
#localize(object, force_locale = config.locale, *args, **options) : String
Localizes certain objects, such as dates and numbers to local formatting.
- #plural_rules
- #plural_rules=(value)
-
#translate(key : String, options : Hash | NamedTuple | Nil = 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.
-
#with_locale(tmp_locale, &)
Executes block with given I18.locale set.
Macro Summary
Instance Method Detail
Returns whether a translation exists for a given key.
Localizes certain objects, such as dates and numbers to local formatting.
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')