# i18n (Rails view helpers)

**This SDK has i18n.** Although it's a server SDK, the gem ships server-side i18n
view helpers for Rails (translated label rendering at SSR) plus loader tags for
the browser SDK. The same `Shipeasy.configure` covers it — there is no separate
i18n init.

## Configure

i18n uses the **public client key** (not the server key) and a `profile`:

```ruby
Shipeasy.configure do |c|
  c.api_key    = ENV.fetch("SHIPEASY_SERVER_KEY")
  c.public_key = ENV.fetch("SHIPEASY_CLIENT_KEY")   # for i18n
  c.profile    = "{{PROFILE}}"
end
```

## Rails view helpers

When Rails is loaded, the Railtie auto-mounts these helpers — no include needed:

```erb
<%# Renders <script id="i18n-data" ...> inline data + the loader <script> tag: %>
<%= i18n_head_tags %>

<h1><%= i18n_t("hero.title", name: current_user.name) %></h1>
```

| Helper | Purpose |
| --- | --- |
| `i18n_head_tags(profile:, chunk:)` | Inline label JSON + loader `<script>` tag for `<head>`. |
| `i18n_inline_data(profile:, chunk:)` | Just the inline `application/json` label blob. |
| `i18n_script_tag(hide_until_ready:)` | Just the loader `<script>` (uses `config.public_key` + `config.profile`). |
| `i18n_t(key, variables = {}, profile:, chunk:)` | Render a translated label server-side, interpolating `{{var}}` placeholders. Falls back to the key if missing. |

`i18n_t` resolves the label from the fetched label file for the configured
profile/chunk and interpolates `{{name}}`-style variables. If the key is absent
it returns the key verbatim.

## SSR i18n loader tag (framework-agnostic)

Outside Rails, emit the loader tag with the package-level helper (it delegates to
the engine configured by `Shipeasy.configure`). This tag carries the **public
client key**, never the server key:

```ruby
Shipeasy.i18n_script_tag(client_key, profile: "{{PROFILE}}")
```

`Shipeasy.bootstrap_script_tag` also takes an `i18n_profile:` so the browser
hydrates the same profile (see [advanced](advanced.md)).

## Cross-SDK story

The browser SDK loads translations via the loader `<script>` (data-key = the
public client key, data-profile = the profile) and exposes `t()` client-side.
The Ruby helpers render the same `{{PROFILE}}` profile server-side so the first
paint is already translated.
