Skip to main content

Next.js

1. Install dependencies

npm install @lingva/react @lingva/next

2. Configure Next.js

// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ['@lingva/react', '@lingva/core'],

// Optional: Configure for server components
serverExternalPackages: ['@lingva/core'],
};

module.exports = nextConfig;

3. Server Component example

// app/page.tsx (Server Component)
import { LingvaServer } from '@lingva/next';

export default async function HomePage() {
const lingva = new LingvaServer({
apiKey: process.env.LINGVA_API_KEY!,
projectId: process.env.LINGVA_PROJECT_ID!,
});

const title = await lingva.t('home.title');
const description = await lingva.t('home.description');

return (
<div>
<h1>{title}</h1>
<p>{description}</p>
</div>
);
}