module Rosetta

Defined in:

rosetta/aliases.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/translatable.cr
rosetta/translation.cr
rosetta/version.cr

Constant Summary

VERSION = "0.2.0"

Class Method Summary

Macro Summary

Class Method Detail

def self.interpolate(translation : String, values : Hash(String | Symbol, String | Time) | 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(format : String, time : Time) #

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

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

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

Temporarily use a different locale.


[View source]

Macro Detail

macro available_locales #

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.


[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 #

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.


[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]