i18n
Configuration

Configuration

Configuration file

Create nimpl-i18n.js file in the app root directory

/nimpl-i18n.js
const fs = require("fs/promises");
 
/** @type {import('@nimpl/i18n/configuration/types').Config} */
module.exports = {
    load: async (language) => {
        const data = await fs.readFile(`./translates/${language}.json`);
        const dictionary = JSON.parse(data);
        return dictionary;
    },
    getLanguage: async ({ params }) => params.language,
    languages: ['en', 'de', 'fr'],
};

Options

load [required]

An asynchronous function that describes the logic of loading translations. Should return an object containing translations.

Function will receive 1 argument - language - current language;

languages [required]

Array of allowed languages. Languages outside of this array will be ignored.

getLanguage [required]

Функция для определения текущего языка. Принимает аргумент в виде объекта с ключами:

pathname - current route pathname;

params - current route segment params;

Configure app

If you can transfer the package configuration file to the server in such a way that it remains readable - the instructions above will be enough.

However, if there is no way to transfer the file or the hosting has internal blocks (for example, Vercel considers this file unused and does not read it) - you need to wrap next.config.js in withI18n

/next.config.js
const { default: i18n } = require('@nimpl/i18n/i18n');
 
const i18nWrapper = i18n();
 
/** @type {import('next').NextConfig} */
const nextConfig = {};
 
module.exports = i18nWrapper(nextConfig);