Next.js reference

init(options)

Import from @18ways/next/server.

ts
import { init } from '@18ways/next/server';

Common options:

OptionTypeNotes
apiKeystringRequired.
baseLocalestringSource locale for the app.
localestringOptional fixed locale override.
acceptedLocalesstring[]Optional explicit locale list.
persistLocaleCookieboolean | ((request) => boolean)Default locale-cookie policy for middleware and client locale changes.
cacheTtlnumberCache TTL for adapter requests.
fetchertypeof fetchCustom fetch implementation.
pathRoutingWaysPathRoutingConfigInclude or exclude locale-prefixed routes.

WaysRoot

Use WaysRoot in your App Router layout so the adapter can seed runtime state for the current request.

htmlAttrs()

htmlAttrs() resolves the current lang and dir values for the document element.

generateWaysMetadata()

Use generateWaysMetadata() inside generateMetadata() when you want translated titles, descriptions, and locale-aware canonical or alternate URLs.

waysMiddleware()

waysMiddleware() is the request-time middleware API returned from init(). It resolves locale state, applies locale cookies, and returns the final NextResponse. Use transformRequestHeaders or transformResponse when you need custom behavior.

init() return value

init() returns these fields:

FieldWhat it does
WaysRootRoot wrapper for App Router layouts.
htmlAttrs()Resolves lang and dir for the current request.
generateWaysMetadata()Builds locale-aware metadata and can translate metadata strings.
waysMiddleware()Resolves locale-aware middleware behavior and returns a response.

Client helpers

Import from @18ways/next/client.

useLocale()

Read and change the current locale. This is the hook you pair with LanguageSwitcher or your own custom selector UI.

useUnlocalizedPathname()

Read the current pathname without the locale prefix.

useLocalizedHref()

Convert an internal href into the current locale-aware href.

localizePathname()

Pure helper for building a localized pathname outside React.

stripLocalePrefix()

Pure helper for removing a locale prefix from a pathname.

Path routing config

WaysPathRoutingConfig accepts:

ts
{
  include?: Array<string | RegExp>;
  exclude?: Array<string | RegExp>;
}

Use it when public URLs should carry locale prefixes. Leave it out when you want cookie-based or header-based locale selection without path rewriting.

Lower-level exports

There are also RSC and middleware exports in @18ways/next/rsc and @18ways/next/server, but for most apps the init() surface above is the right abstraction.