jay2p
jay2p

Reputation: 75

Cannot make i18next work in nodeJS express backend

I'm currently trying to add localization to my nodeJS backend but im having trouble.

In my frontend (angular) i have an interceptor that sets the language in the header: interceptor

Which succesfully works as can be seen below in 'Accept-Language' in the headers of my request: request

In my backend app.js i import and configure i18next, i18next-fs-backend, i18next-http-middleware and set the path of the locale files (which can also be seen bellow) and : appjs

But when i try to use the translations in my response it doesn't work, it displays the 'delete_success' and not the translation. requesting the translation

Inside my translation file: inside file

Bellow im posting some stuff that is printed in the req.i18n console.log in case it helps:

bound I18n {
 observers: { languageChanged: [ [Function (anonymous)] ] },
 options: {
 debug: false,
 initImmediate: false,
 ns: [ 'translation' ],
 defaultNS: [ 'translation' ],
 fallbackLng: [ 'en' ],
 preload: [ 'pt-BR' ],
 backend: {
   loadPath: './locales/{{lng}}/translation.json',
   addPath: '/locales/{{lng}}/{{ns}}.missing.json',
   ident: 2,
   parse: [Function: parse],
   stringify: [Function: stringify]
 },
 language: 'en',
}

I have no idea what else to try, any tips? :(

Upvotes: 0

Views: 1506

Answers (1)

jay2p
jay2p

Reputation: 75

I found my problem!

The problem was in the path specified to the locales as shown bellow:

enter image description here

Three hours to figure that out T_T

Upvotes: 2

Related Questions