0

i18next-http-backend - Docs

I have the following configuration for i18next in react application. My problem is to set dynamic values in header, such as: "accept-lang". According to documentation customHeaders provided for this, but it has no any context arguments. For example, i can't get current language in this customHeaders function.

How can i set dynamic header values in configuration?

const initOptions: I18nInitOptions = {
            debug: true,
            fallbackLng: 'en',
            supportedLngs: ['en'],
            interpolation: {
                escapeValue: false,
            },
            detection: {
                order: ['localStorage'],
            },
            backend: {
                backends: backends,
                backendOptions: [
                    {
                        loadPath: backendUrl,
                        customHeaders: () => {
                            return {
                                'accept-lang': 'LANG VALUE HERE?',
                            };
                        },
                    },
                ],
            },
            initImmediate: false,
            saveMissing: true,
        };

I tried to set custom headers, get current language, but library doesn't provide, tried to log params of provided method, but its "undefined"

coder21
  • 1
  • 1
  • 4

0 Answers0