Raxol.Core.I18n (Raxol v2.0.1)
View SourceRefactored internationalization module using GenServer for state management.
This module provides the same API as the original I18n module but delegates all state management to a supervised GenServer, eliminating Process dictionary usage.
Migration Guide
Add the I18n.I18nServer to your supervision tree:
children = [ {Raxol.Core.I18n.I18nServer, name: Raxol.Core.I18n.I18nServer, config: config} ]
Replace
Raxol.Core.I18nwithRaxol.Core.I18nin your codeAll API calls remain the same
Summary
Functions
Add or update translations for a locale.
Get all available locales.
Clean up i18n resources.
Format a currency amount according to the current locale.
Format a datetime according to the current locale.
Get the current locale.
Handle locale changed events.
Initialize the i18n framework.
Check if the current locale is right-to-left.
Set the current locale.
Get a translated string for the given key.
Functions
Add or update translations for a locale.
Examples
iex> I18n.add_translations("en", %{
...> "new_key" => "New translation",
...> "another_key" => "Another translation"
...> })
:ok
Get all available locales.
Clean up i18n resources.
With GenServer, cleanup happens automatically when the server stops.
Format a currency amount according to the current locale.
Examples
iex> I18n.format_currency(1234.56, "USD")
"$1,234.56"
iex> I18n.set_locale("fr")
iex> I18n.format_currency(1234.56, "EUR")
"1 234,56 €"
Format a datetime according to the current locale.
Examples
iex> dt = DateTime.utc_now()
iex> I18n.format_datetime(dt)
"December 12, 2025 at 3:45 PM"
Get the current locale.
Examples
iex> I18n.get_locale()
"en"
Handle locale changed events.
This is now handled internally by the server.
Initialize the i18n framework.
Now initializes the GenServer state instead of Process dictionary.
Check if the current locale is right-to-left.
Examples
iex> I18n.set_locale("ar")
iex> I18n.rtl?()
true
iex> I18n.set_locale("en")
iex> I18n.rtl?()
false
Set the current locale.
Examples
iex> I18n.set_locale("fr")
:ok
iex> I18n.set_locale("invalid")
{:error, :locale_not_available}
Get a translated string for the given key.
Examples
iex> I18n.t("welcome_message")
"Welcome!"
iex> I18n.t("hello_name", %{name: "John"})
"Hello, John!"