Search documentation of Localize

# Localize.Supervisor (Localize v0.39.0)

Copy Markdown View Source

The `:localize` runtime supervisor.

Owns the small set of processes the library needs at runtime — the data loader, the locale loader (which owns the locale-validation ETS table), the cache sweeper, the format cache, and the collation ICU table — and runs the one-time post-start work that interns every supplemental atom and resolves the configured `:supported_locales`.

By default this supervisor is started automatically when the `:localize` OTP application boots, so callers do not need to start it themselves. Applications that prefer to manage Localize's lifecycle alongside their own processes can disable that auto-start and mount this supervisor as a child of their own tree instead.

## Manual supervision

Mark the dependency as `runtime: false` in `mix.exs` so the OTP application is not auto-started:

    # mix.exs
    def deps do
      [
        {:localize, "~> 0.33", runtime: false}
      ]
    end

Then add the supervisor to your application's tree:

    # lib/my_app/application.ex
    def start(_type, _args) do
      children = [
        MyApp.Repo,
        Localize.Supervisor,
        MyAppWeb.Endpoint
      ]

      Supervisor.start_link(children, strategy: :one_for_one)
    end

Place `Localize.Supervisor` after any process that loads compile-time config Localize depends on (typically none) and before any process that calls Localize functions at startup (formatters, importers, background workers).

See `guides/supervision.md` for a more detailed walk-through.

## Summary

### Functions

child_spec(options \\ [])

Default child spec.

start_link(options \\ [])

Starts the Localize supervisor.

## Functions

# child_spec(options \\ [])

    @spec child_spec(keyword()) :: Supervisor.child_spec()

Default child spec.

Lets callers add `Localize.Supervisor` (or `{Localize.Supervisor, []}`) directly to their own application's `children` list.

# start_link(options \\ [])

    @spec start_link(keyword()) :: Supervisor.on_start()

Starts the Localize supervisor.

### Arguments

- `options` is a keyword list. Currently no options are honoured — the argument exists so callers can use the `{Localize.Supervisor, []}` child-spec shape without surprise.

### Returns

- `{:ok, pid}` on success.

- `{:error, reason}` if startup fails.