module Rosetta
Defined in:
rosetta/aliases.crrosetta/backend.cr
rosetta/config.cr
rosetta/configuration.cr
rosetta/interpolation.cr
rosetta/localizable.cr
rosetta/localization.cr
rosetta/lucky/integration.cr
rosetta/parser.cr
rosetta/parser/builder.cr
rosetta/translatable.cr
rosetta/translation.cr
rosetta/version.cr
Constant Summary
-
VERSION =
"0.2.0"
Class Method Summary
-
.interpolate(translation : String, values : Hash(String | Symbol, String | Time) | NamedTuple)
Interpolates a given string with the values from the given hash or named tuple.
-
.locale : String
Gets the current locale at runtime using the config instance stored in the current fiber.
-
.locale=(locale : String | Symbol)
Sets the current locale at runtime using the config instance stored in the current fiber.
-
.localize_time(format : String, time : Time)
Uses a given format to localize a given Time object, for example:
-
.with_locale(locale : String | Symbol, &)
Temporarily use a different locale.
Macro Summary
-
available_locales
Tries to find the available locales configurad by the user.
-
date(format = :default)
Localizes a date, for example:
-
default_locale
Tries to find the default locale configurad by the user.
-
find(key)
Finds the translations for the given key as a dedicated class instance for the translation, which inherits from
Rosetta::Translation
. -
number(format = :default)
Localizes a numeric value, for example:
-
time(format = :default)
Localizes time, for example:
Class Method Detail
Interpolates a given string with the values from the given hash or named tuple.
Gets the current locale at runtime using the config instance stored in the current fiber.
Sets the current locale at runtime using the config instance stored in the current fiber.
Uses a given format to localize a given Time object, for example:
Rosetta.localize_time("%d %b %Y %H:%M:%S", Time.local)
Macro Detail
Tries to find the available locales configurad by the user. If it's not set, the available locales defined in the config class is used.
Localizes a date, for example:
Rosetta.date.t(Time.local)
Rosetta.date.t({2021, 8, 20})
Rosetta.date(:long).l(Time.local)
Rosetta.date("%a, %d %b %Y").l(Time.local.date)
Tries to find the default locale configurad by the user. If it's not set, the default locale defined in the config class is used.
Finds the translations for the given key as a dedicated class instance for
the translation, which inherits from Rosetta::Translation
.
If the key does not exist, a compile error will be raised.
Localizes a numeric value, for example:
Rosetta.number.t(123_456.789)
Rosetta.number(:custom).l(123_456.789)
Localizes time, for example:
Rosetta.time.t(Time.local)
Rosetta.time(:short).l(Time.local)
Rosetta.time("%d %b %Y %H:%M:%S").l(Time.local)