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/parser/checks.cr
rosetta/parser/config.cr
rosetta/pluralization.cr
rosetta/pluralization/rule.cr
rosetta/pluralization/rule/arabic.cr
rosetta/pluralization/rule/breton.cr
rosetta/pluralization/rule/central_morocco_tamazight.cr
rosetta/pluralization/rule/colognian.cr
rosetta/pluralization/rule/east_slavic.cr
rosetta/pluralization/rule/irish.cr
rosetta/pluralization/rule/langi.cr
rosetta/pluralization/rule/latvian.cr
rosetta/pluralization/rule/lithuanian.cr
rosetta/pluralization/rule/macedonian.cr
rosetta/pluralization/rule/maltese.cr
rosetta/pluralization/rule/manx.cr
rosetta/pluralization/rule/one_other.cr
rosetta/pluralization/rule/one_two_other.cr
rosetta/pluralization/rule/one_up_to_two_other.cr
rosetta/pluralization/rule/one_with_zero_other.cr
rosetta/pluralization/rule/other.cr
rosetta/pluralization/rule/polish.cr
rosetta/pluralization/rule/romanian.cr
rosetta/pluralization/rule/scottish_gaelic.cr
rosetta/pluralization/rule/slovenian.cr
rosetta/pluralization/rule/upper_sorbian.cr
rosetta/pluralization/rule/welsh.cr
rosetta/pluralization/rule/west_slavic.cr
rosetta/translatable.cr
rosetta/translation.cr
rosetta/version.cr
Constant Summary
-
VERSION =
"0.5.0"
Class Method Summary
-
.distance_of_time_in_words(from : Time, to : Time) : String
Returns a
String
with approximate distance in time betweenfrom
andto
. -
.interpolate(translation : String, values : Hash | 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(time : Time, format : String)
Uses a given format to localize a given Time object, for example:
- .localize_time(time : Tuple(Int32, Int32, Int32), format : String)
-
.pluralize(count : Float | Int, translation : NamedTuple, rule : Pluralization::Rule = Pluralization::RULES[Rosetta.locale].new)
Pluralizes a given pluralizable translation.
-
.time_ago_in_words(from : Time) : String
Returns a
String
with approximate distance in time betweenfrom
and current moment. -
.time_from_now_in_words(to : Time) : String
Returns a
String
with approximate distance in time between current moment and future date. -
.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
Returns a String
with approximate distance in time between from
and
to
. For example:
Rosetta.distance_of_time_in_words(
Time.utc(2021, 10, 15, 8, 0, 0),
Time.utc(2021, 10, 15, 8, 0, 5))
)
# => "5 seconds"
Most of the code for this method is borrowed from Lucky.
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(Time.local, "%d %b %Y %H:%M:%S")
Pluralizes a given pluralizable translation.
Returns a String
with approximate distance in time between from
and
current moment.
time_ago_in_words(Time.utc(2019, 8, 30))
# => "about a month"
# gives the same result as:
distance_of_time_in_words(Time.utc(2019, 8, 30), Time.utc)
# => "about a month"
See more examples in #distance_of_time_in_words
.
Returns a String
with approximate distance in time between current
moment and future date.
time_from_now_in_words(Time.utc(2022, 8, 30))
# => "about a year"
# gives the same result as:
distance_of_time_in_words(Time.utc, Time.utc(2022, 8, 30))
# => "about a year"
See more examples in #distance_of_time_in_words
.
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)