1

In my Next.js app, I have an i18n.config.js file in the root directory of my next.js app. Inside i18n.config.js there is a configuration that is exported via module.exports={...}.

MyApp in _app.js is wrapped with that module.

Now, I want to initialize that module only if there is a specific query in the URL (e.g. "http://localhost:3000?enableEdit=true").

So, my question is, how can I set the config parameter inside module.exports object to depend based on a query?

Here is the _app.js

import { useStore } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react';
import appWithTranslation from '../i18n.config';
import { reduxWrapper } from '../src/store/createStore';

const MyApp = ({ Component, router, pageProps }) => {
  const store = useStore((state) => state);
  return (
    <PersistGate persistor={store.__persistor}>
      {() => (
        <Component router={router} {...pageProps} />
      )}
    </PersistGate>
  );
};

export default reduxWrapper.withRedux(MyApp, appWithTranslation);

And here is the module in i18n.config.js

const path = require('path');
const PhraseInContextEditorPostProcessor = process.browser
  ? require('i18next-phrase-in-context-editor-post-processor').default
  : require('i18next-phrase-in-context-editor-post-processor');
const NextI18Next = require('next-i18next').default;

module.exports = new NextI18Next({
  defaultLanguage: 'en',
  otherLanguages: ['de'],
  localePath: path.resolve('./public/static/locales'),
  use: [
    new PhraseInContextEditorPostProcessor({
      phraseEnabled: true;
      projectId: 'projectID',
    }),
  ],
  postProcess: ['phraseInContextEditor'],
});

0 Answers0