# `Localize.Inflection.DataDir`
[🔗](https://github.com/elixir-localize/localize/blob/v1.4.0/lib/localize/inflection/data_dir.ex#L1)

Resolves the directory holding the compiled inflection data.

Inflection data is optional: when it has not been downloaded,
inflection functions return
`{:error, %Localize.InflectionDataNotAvailableError{}}` rather
than raising. Three configuration forms are
recognised, following the locale-cache convention (see
`Localize.Locale.Provider.locale_cache_dir/0`):

    # 1. Recommended. Resolved as
    #    `Application.app_dir(:my_app, "priv/localize/inflection")`
    #    at every read, so it computes the right path in mix
    #    tasks and in releases.
    config :localize, otp_app: :my_app

    # 2. :otp_app plus a *relative* :inflection_data_dir,
    #    resolved against the app's runtime root.
    config :localize, otp_app: :my_app, inflection_data_dir: "priv/i18n/inflection"

    # 3. An absolute :inflection_data_dir for fully custom
    #    locations.
    config :localize, inflection_data_dir: "/var/lib/localize/inflection"

Without configuration the directory defaults to the `localize`
dependency's own `priv/localize/inflection`.

## The data version segment

Artifacts live in a subdirectory named for
`Localize.Inflection.Provider.data_version/0`, mirroring the CDN
layout the same version addresses, so the configured directory
holds one subdirectory per data version:

    priv/localize/inflection/ae92d425e57a-r3/de.etf

The segment makes an artifact of an earlier data version
unreachable rather than merely detectable: it is never the file a
later version reads, so `dir/0` is empty after a version bump and
the data downloads afresh. Recording the version *inside* each
artifact instead, as the locale cache does in
`Localize.Locale.Provider.Cache.stale?/1`, would mean decoding the
file to learn whether to read it, and an inflection artifact
reaches 11 MB where a locale file stays near 1 MB.

# `base_dir`

```elixir
@spec base_dir() :: String.t()
```

Returns the configured inflection data directory, without the data
version segment.

This is the directory `:inflection_data_dir` and `:otp_app`
configure. Artifacts are not written here: each data version takes
a subdirectory of it, which `dir/0` returns.

### Returns

* An absolute directory path as a string.

### Examples

    iex> is_binary(Localize.Inflection.DataDir.base_dir())
    true

# `dir`

```elixir
@spec dir() :: String.t()
```

Returns the directory holding the current data version's artifacts.

It is `base_dir/0` joined with
`Localize.Inflection.Provider.data_version/0`.

### Returns

* An absolute directory path as a string.

### Examples

    iex> dir = Localize.Inflection.DataDir.dir()
    iex> String.ends_with?(dir, Localize.Inflection.Provider.data_version())
    true

# `path`

```elixir
@spec path(String.t()) :: String.t()
```

Returns the path of a file within the current data version's
inflection data directory.

### Arguments

* `name` is a file name such as "en.etf".

### Returns

* An absolute file path as a string.

### Examples

    iex> path = Localize.Inflection.DataDir.path("en.etf")
    iex> String.ends_with?(path, "en.etf")
    true

---

*Consult [api-reference.md](api-reference.md) for complete listing*
