Serving static localization json files for i18n libraries (like i18next) #4885
-
Hi there! I'm using Parcel 2 with a React app and i18next for, well, i18n. The library has a plugin for loading the localization files directly from the server, like so: i18n.use(HttpApi)
.use(initReactI18next)
.init({
lng: 'en',
fallbackLng: 'en',
keySeparator: false,
interpolation: {
escapeValue: false,
},
backend: {
loadPath: '/static/locales/{{lng}}.json', // this is the path from wich the library will try to fetch the files
},
}); The ./
├── src
├── static
│ ├── icons
│ └── locales
└─ But when I start the app with parcel dev server, the file is not served thus i18next does not load the translations (I assume because I'm not importing the json directly, although I tried this and it didn't work either). If I go to the browser and put |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ended up using the |
Beta Was this translation helpful? Give feedback.
Ended up using the
live-server
package to serve the localization files separately and using Parcel's proxy functionality to redirectlocale
requests to that server. Don't know if that is overkill or what, but it works; if someone happens to have a different idea I'm happy to hear!