module I18n
Extended Modules
Defined in:
i18n.cri18n/backend.cr
i18n/version.cr
Constant Summary
-
VERSION =
"0.1.0"
Class Method Summary
-
.available_locales : Array(String)
An array of all available locales.
-
.available_locales=(available_locales : Array(String))
An array of all available locales.
-
.backend : Backend | Nil
A current
Backend
used by I18n. -
.backend=(backend : Backend | Nil)
A current
Backend
used by I18n. -
.default_locale : String
Default locale picked when no locale is passed to
#translate
. -
.default_locale=(default_locale : String)
Default locale picked when no locale is passed to
#translate
. -
.locale : String | Nil
Current locale.
-
.locale=(locale : String | Nil)
Current locale.
-
.rescue_missing : Bool
Whether to rescue
Backend::TranslationNotFoundError
when a translation is missing (defaults to true). -
.rescue_missing=(rescue_missing : Bool)
Whether to rescue
Backend::TranslationNotFoundError
when a translation is missing (defaults to true).
Instance Method Summary
-
#t(key : String, *a, **n)
ditto
-
#translate(keys : Array(String), locale : String | Nil = locale || default_locale, count : Int32 | Nil = nil) : String
Translates a value in a locale found by keys.
-
#translate(key : String, *a, **n)
A convenient overloader, keys are passed as a String with dot delimeters.
Class Method Detail
An array of all available locales. Must be set explicitly.
I18n.available_locales = %w(en es)
An array of all available locales. Must be set explicitly.
I18n.available_locales = %w(en es)
A current Backend
used by I18n. Can be changed in a runtime.
A current Backend
used by I18n. Can be changed in a runtime.
Default locale picked when no locale is passed to #translate
.
Defaults to "en"
.
Default locale picked when no locale is passed to #translate
.
Defaults to "en"
.
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"
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"
Whether to rescue Backend::TranslationNotFoundError
when a translation is missing (defaults to true).
I18n.translate("unknown.key") # => "MISSING: en.unknown.key"
Whether to rescue Backend::TranslationNotFoundError
when a translation is missing (defaults to true).
I18n.translate("unknown.key") # => "MISSING: en.unknown.key"
Instance Method Detail
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"
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"