Fab.Locale (fab v1.1.2)

Provides dynamic function dispatch based on the current locale.

Summary

Functions

Dynamically resolves and invokes a localized implementation of a given function.

Functions

localize(mod, fun, args)

@spec localize(module(), atom(), list()) :: any()

Dynamically resolves and invokes a localized implementation of a given function.

Constructs a module path based on the current locale by inserting the locale between the root and the provider module segments. Then attempts to load and invoke the specified function from this localized module. If the localized module or function is unavailable, falls back to using the English version of the module.

Example

iex> Fab.set_locale(:es)
...> Fab.Locale.localize(Fab.MyMod, :rando, [])

This would resolve to:

  • Fab.Es.MyMod.rando/0
  • or Fab.En.MyMod.rando/0 if the localized implementation does not exist