i18n config, pages function callback not working as expected
According to https://github.com/vinissimus/next-translate#3-configuration
I should be able to do something like this:
pages: { "/": ({ req }) => req.headers.hostname === 'example' ? ['example'] : []}
This however doesn't work, when logging out the value passed in the callback it just returns me the i18n config 🤷♂️
Steps to reproduce
- Use the "complex" example
- Change this line: https://github.com/vinissimus/next-translate/blob/master/examples/complex/i18n.js#L8
to:
'/': ({ req }) => (req.headers.hostname === 'example' ? ['example'] : []), - Observe errors in the console like this:
Cannot read properties of undefined (reading 'headers')
I managed to get it to work, I had to make sure I was spreading the context inside of loadNamespaces in my getInitialProps.
await loadNamespaces({ ...ctx, locale, pathname: '/' });, I'm getting a typescript error which I have to ignore... Any thoughts on this?
@sigginjals don't you use the Webpack loader we provide? Are you using loadNamespaces instead?
If this is the case, I understand is a thing to improve in the documentation. However, if you use the Webpack loader and also you need to use the loadNamespaces to fix this, is not the way (maybe as a temporal workaround) and needs to be fixed.
@sigginjals I'm not using the webpack loader, I'm using loadNamespaces.