Translation system for PureAdmin components.
Ships with English defaults that work out of the box. Applications can override translations at runtime by providing a callback function via config:
# config/config.exs
config :keen_pure_admin,
translate: &MyApp.Translations.translate/2The callback receives a translation key and a params map:
defmodule MyApp.Translations do
def translate(key, params) do
# Load from DB, Gettext, ETS, etc.
translation = MyApp.Repo.get_translation(key, current_locale())
# Use the interpolation helper to replace %{param} placeholders
PureAdmin.Translations.interpolate(translation, params)
end
endIf the callback returns nil, the English default is used as fallback.
Translation Keys
All keys follow the flat pureAdmin.* convention:
pureAdmin.buttons.*— Cancel, Confirm, Close, OKpureAdmin.search.*— Searching..., No resultspureAdmin.pagination.*— First/Prev/Next/Last Page, Load More, page countspureAdmin.commandPalette.*— Placeholder, hints, step indicatorspureAdmin.popconfirm.*— Confirm, CancelpureAdmin.settings.*— Theme, Mode, Layout Width, etc.pureAdmin.a11y.*— Accessibility labels
Interpolation
Use %{param} placeholders in translation strings:
t("pureAdmin.pagination.pages", %{page: 2, total: 5})
# => "2 of 5 pages"
t("pureAdmin.commandPalette.stepOf", %{current: 1, total: 3})
# => "Step 1 of 3"
Summary
Functions
Returns the default English translation for a key with interpolation.
Returns the full map of default English translations.
Interpolates %{param} placeholders in a string with values from the params map.
Translates a key with optional parameter interpolation.
Functions
Returns the default English translation for a key with interpolation.
Returns the key itself if no default exists.
@spec defaults() :: map()
Returns the full map of default English translations.
Useful for apps that want to see all available keys.
Interpolates %{param} placeholders in a string with values from the params map.
Exported for use by app translation callbacks.
Examples
interpolate("Found %{count} results", %{count: 3})
# => "Found 3 results"
interpolate("Page %{page} of %{total}", %{page: 2, total: 5})
# => "Page 2 of 5"
Translates a key with optional parameter interpolation.
Calls the app-configured callback if set, falls back to English defaults.
Examples
t("pureAdmin.buttons.cancel")
# => "Cancel"
t("pureAdmin.pagination.pages", %{total: 5})
# => "/ 5 pages"
t("pureAdmin.commandPalette.stepOf", %{current: 1, total: 3})
# => "Step 1 of 3"