# Server-side

Source: https://verbaly.dev/docs/guide/server

The core runs anywhere JavaScript does, including Node. Create an instance, pass the language, call `t()`. No DOM required.

## One instance per request

Build a fresh instance per request and hand it the visitor's language. `negotiateLocale` reads the `Accept-Language` header and picks the best match among your languages (it understands quality values, and `es-PE` matches `es`). `resolveRequestLocale` makes the whole decision in one call: the address first when it carries the language, then the saved choice, then the browser, then your fallback. Instances don't share state, so two requests never mix their languages.

```ts title="server.ts"
import { createVerbaly, negotiateLocale } from 'verbaly';
import es from './locales/es.json';
import en from './locales/en.json';

function handle(req) {
  const locale = negotiateLocale(req.headers['accept-language'], ['en', 'es']);
  const v = createVerbaly({ locale, fallback: 'en', messages: { en, es } });
  return v.t('home.title');
}
```

> **Always pass a language**
>
> Auto-detection is browser-only: on the server there's no user to detect. Without an explicit `locale` the instance defaults to `en`, never the machine's language.

## When your addresses carry the language

If your pages live at `/es/dashboard`, that address is the answer. Anyone who opens the link gets Spanish, whether or not they ever picked a language here, because an address is public and shared while a saved choice belongs to one person. A page without a prefix then means your source language, so a visitor who once chose Spanish never sees your English pages translated by accident.

You switch this on by telling your integration the `routing` you already set. Here is the whole of it, per stack:

| Stack | What you write |
| --- | --- |
| SvelteKit | Pass `routing` to `verbalyHandle`, and add `verbalyReroute` in `hooks.ts` so one route tree serves every language |
| Nuxt | Nothing: the module reads the address for you |
| Next.js | `routing: 'prefix-all'` in your config and the `[locale]` segment in your root layout. Before Next 16.3, also `setRequestLocale(locale)` in every layout and page |
| Astro | `createRequestInstance(Astro.currentLocale ?? sourceLocale)` in the page |

> **On Next.js this is also what keeps your pages fast**
>
> Without the language in hand, Verbaly has to read the request headers to find it, and reading them is what makes Next build the page on every visit instead of once. Pass the segment and no header is read, so the page can be built ahead of time again. A route with no request at all, like an OG image or a sitemap, calls `getT({ locale })` with the language it wants and reads nothing either.

Your pages can also point search engines at each other. `alternateLinks` gives you the list of addresses for one page in every language, the same list a statically rendered site gets, so a server-rendered page is not a second-class citizen. See [URL strategy](https://verbaly.dev/docs/guide/urls.md).

## Render HTML ahead of time

For static sites, `verbaly render` pre-fills your built HTML per language so pages ship already translated. See [CLI → Static rendering](https://verbaly.dev/docs/reference/cli.md).

## Meta-frameworks

On SvelteKit, Nuxt and Next.js you do not wire any of this by hand. [The SvelteKit integration](https://verbaly.dev/docs/frameworks/svelte.md#sveltekit), [the Nuxt module](https://verbaly.dev/docs/frameworks/vue.md#nuxt) and [the Next.js integration](https://verbaly.dev/docs/frameworks/react.md#next) pick the language per request and load in the browser without a flash, all with these same functions.
