Internationalization (i18n)
Nexical provides a robust i18n system that merges locales from all modules.
Key Concepts
Section titled “Key Concepts”Merged Locales
Section titled “Merged Locales”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.
API Reference
Section titled “API Reference”getTranslation(lang?)
Section titled “getTranslation(lang?)”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' }));getServerTranslation(request)
Section titled “getServerTranslation(request)”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'));}Adding Translations
Section titled “Adding Translations”Create a locales folder in your module.
{ "user": { "welcome": "Hello {{name}}" }}