Search code examples
javascriptreactjstranslationi18next

React i18next modify translation file path


I am using a react application with react-i18next and I am loading the translation from the path

locales/en/translation.json
locales/de/translation.json
locales/fr/translation.json
...

Can I change the path and have the translations loaded from

lib/en.i18n.json
lib/de.i18n.json
lib/fr.i18n.json
...

Thank you very much


Solution

  • Updating the configuration of your i18n library.

    import i18n from 'i18next';
    import XHR from 'i18next-xhr-backend';
    
    i18n
      .use(XHR)
      .init({
        backend: {
          loadPath: 'lib/{{lng}}.i18n.json',
        },
        // ... other i18n options ...
      });