Skip to content
fluenti

SSR & Hydration

  1. No shared global state — Every SSR request gets its own Fluenti instance
  2. Hydration consistency — Client always reads the server-determined locale from payload
  3. Path-first detection — In SSG/ISR, the URL path is the only reliable locale source

Use detectLocale from core with a clear priority chain:

cookie → query → path → Accept-Language → fallback
import { detectLocale } from '@fluenti/core'
const locale = detectLocale({
cookie: req.headers.cookie,
query: url.searchParams.get('lang'),
path: url.pathname,
headers: req.headers,
available: ['en', 'ja', 'zh-CN'],
fallback: 'en',
})
import { getDirection } from '@fluenti/core'
const dir = getDirection(locale) // 'ltr' or 'rtl'
// <html lang="${locale}" dir="${dir}">

After the user explicitly switches locale, store the preference in a cookie so detectLocale picks it up on the next server request.

For manual SSR (without Nuxt or Next.js), use getSSRLocaleScript to inject the server-detected locale into the HTML:

import { getSSRLocaleScript, getHydratedLocale } from '@fluenti/core'
// Server: inject into HTML <head>
const script = getSSRLocaleScript(locale)
// → <script>window.__FLUENTI_LOCALE__="ja"</script>
// Client: read it back
const locale = getHydratedLocale('en')

Uses withFluenti() and FluentProvider. Cookie-based locale detection via cookies() from next/headers. RSC support via createServerI18n.

See Next.js guide and Server Components.

UtilityDescription
detectLocale(options)Detect locale from cookie, query, path, or Accept-Language header
getSSRLocaleScript(locale)Generate a <script> tag to inject locale into HTML (XSS-safe)
getHydratedLocale(fallback)Read the injected locale on the client
getDirection(locale)Return 'rtl' or 'ltr'
isRTL(locale)Check if a locale is right-to-left