-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with react-i18next / next-i18next #66
Comments
FYI, Does any of you see a way to be able to interact with each other ? I would love to be able to use both of you libraries together ! |
For those looking for something good as I am writing this, I encourage you to have a look to this vercel/next.js#33892 |
To be frank, |
That's not true, I've personally hacked |
"Superior" is a subjective measure – it's not the direction the framework is headed in. |
This library uses |
I managed to get everything working using relay-nextjs except making it work with i18next. Has anyone found a workaround that can make it work? |
@mortezaalizadeh |
I've found it simpler to just to call I'm using export default function withTranslations<T>(Page: NextPageWithLayout<T>) {
const originalGetInitialProps = Page.getInitialProps;
// Load translations in getInitialProps if running on server
Page.getInitialProps = async (ctx) => {
const originalProps = originalGetInitialProps
? await originalGetInitialProps(ctx)
: {};
if (typeof window === 'undefined') {
const getTranslations = (
await import('src/util/getTranslations')
).default;
const translationProps = await getTranslations({
locale: ctx.locale || 'en',
});
return {
...originalProps,
...translationProps,
};
}
return originalProps;
};
return Page;
} You can implement |
Hi, I just ran into this issue and I was able to fix it by following this: i18next/next-i18next#1917 (comment) I just had to pass import i18nextConfig from '../../next-i18next.config';
...
export default appWithTranslation(MyApp, i18nextConfig); |
@mo-rally-dev Thank you for continuing to look into this! Would there be any way to see a full example of how your app is working with i18n? Would be great to put something in the docs. |
Hey @rrdelaney , I sadly can't share my app as it's a private one but here's my const HttpBackend = require('i18next-http-backend/cjs');
const ChainedBackend = require('i18next-chained-backend').default
const LocalStorageBackend = require('i18next-localstorage-backend').default
const yaml = require('js-yaml');
const isBrowser = typeof window !== 'undefined'
const isDev = process.env.NODE_ENV === 'development'
// @ts-check
/**
* @type {import('next-i18next').UserConfig}
*/
module.exports = {
debug: isDev,
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr', 'es', 'it', 'ro'],
},
localePath: isBrowser ? '/lang' : require('path').resolve('./public/lang'),
localeExtension: 'yml',
reloadOnPrerender: isDev,
lng: 'en',
ns: ['app', 'research'],
defaultNS: 'app',
interpolation: {
escapeValue: false,
},
serializeConfig: false,
use: isBrowser ? [ChainedBackend] : [],
backend: {
// For the client side, we save the translations in localstorage and fetch them if they are missing
backends: isBrowser ? [LocalStorageBackend, HttpBackend] : [],
backendOptions: [
{
prefix: 'test_i18next_',
expirationTime: isDev ? 0 : 60 * 60 * 1000, // 1 hour
store: isBrowser ? window.localStorage : null
},
{
loadPath: '/lang/{{lng}}/{{ns}}.yml',
parse: function(data) { return yaml.load(data); },
},
],
},
}; I am storing my translations in the public folder under Server side rendering works because I am calling if (typeof window === 'undefined') {
const { serverSideTranslations } = await import(
'next-i18next/serverSideTranslations'
);
const locale = context.locale; // TODO: when we are ready plug in this code below: (locale ?? 'en')
const namespaces = ['app', ...additionalLocaleNamespacesToLoad];
return {
...(await serverSideTranslations(
'en',
namespaces,
null,
SUPPORTED_LANGUAGES
)),
};
} Hope this helps! |
I am trying to use
withRelay
on a page that need preloading of info (classic/account/edit
where I want fields to be filled with user data upfront).So I started converting a simple page by adding
withRelay
required logic.I started with this (working, but no query to prefill)
to this (same page, with a new query and
withRelay
call)I am getting an warning in the browser
And the translations are not available.
What is weird is that my
getServerSideProps
is exactly the same, exportserverSideTranslations
properly.Any idea why
withRelay
might conflict somehow with next-i18next ?The text was updated successfully, but these errors were encountered: