module Rosetta

Defined in:

rosetta/aliases.cr
rosetta/annotations.cr
rosetta/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 = {{ (`shards version \"/home/runner/work/rosetta/rosetta/src/rosetta\"`).chomp.stringify }}

Class Method Summary

Macro Summary

Class Method Detail

def self.distance_of_time_in_words(from : Time, to : Time) : String #

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.


[View source]
def self.interpolate(translation : String, values : Hash | NamedTuple) #

Interpolates a given string with the values from the given hash or named tuple.


[View source]
def self.locale : String #

Gets the current locale at runtime using the config instance stored in the current fiber.


[View source]
def self.locale=(locale : String | Symbol) #

Sets the current locale at runtime using the config instance stored in the current fiber.


[View source]
def self.localize_time(time : Time, format : String) #

Uses a given format to localize a given Time object, for example:

Rosetta.localize_time(Time.local, "%d %b %Y %H:%M:%S")

[View source]
def self.localize_time(time : Tuple(Int32, Int32, Int32), format : String) #

[View source]
def self.pluralize(count : Rosetta::CountArg, translation : NamedTuple, rule : Pluralization::Rule = Pluralization::RULES[Rosetta.locale].new) #

Pluralizes a given pluralizable translation.


[View source]
def self.time_ago_in_words(from : Time) : String #

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.


[View source]
def self.time_from_now_in_words(to : Time) : String #

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.


[View source]
def self.with_locale(locale : String | Symbol, &) #

Temporarily use a different locale.


[View source]

Macro Detail

macro available_locales #

Fetches the available locales from the corresponding annotation.


[View source]
macro date(format = :default) #

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)

[View source]
macro default_locale #

Fetches the default locale from the corresponding annotation.


[View source]
macro find(key) #

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.


[View source]
macro number(format = :default) #

Localizes a numeric value, for example:

Rosetta.number.t(123_456.789)
Rosetta.number(:custom).l(123_456.789)

[View source]
macro time(format = :default) #

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)

[View source]