Skip to content

Internationalization (i18n)

Nexical provides a robust i18n system that merges locales from all modules.

Standard i18n libraries expect a single JSON file. Nexical scans modules/{name}/locales/{lang}.json and deep-merges them at runtime. This allows modules to own their own translation keys.

Returns a t function for the specified language (defaults to system default).

import { getTranslation } from '@/lib/core/i18n';
const t = await getTranslation('es');
console.log(t('welcome.message', { name: 'Alice' }));

Extracts the language from the request cookies and returns the appropriate t function.

import { getServerTranslation } from '@/lib/core/i18n';
export async function GET({ request }) {
const t = await getServerTranslation(request);
return new Response(t('error.not_found'));
}

Create a locales folder in your module.

modules/user/locales/en.json
{
"user": {
"welcome": "Hello {{name}}"
}
}