next-translate
next-translate copied to clipboard
How to use translation with serversideprops
I am using getServerSideProps in class component. When I am using next-translate/withTranslation api like this
import withTranslation form next-translate/withTranslation
export const getServerSideProps = async (ctx) => {
console.log("hello");
return ;
};
class Test from React.Component{
}
export default withTranslation (Test)
then I am getting error
Error: You can not use getInitialProps with getServerSideProps. Please remove getInitialProps.
. How can we use next-translate api with getServerSideProps in class componet?
How is your _app.js file?
import { csrfToken } from "../utils/common/csrftoken";
const MyApp = ({ Component, pageProps }) => (
<>
<Component {...pageProps} csrfToken={csrfToken}/>
</>
);
export default wrapper.withRedux(MyApp);
Using a HOC (wrapper.withRedux(MyApp)
) in _app.js
is using getInitialProps
by default in _app.js
.
To avoid it, you can use this:
https://github.com/vinissimus/next-translate/issues/801#issuecomment-1059800473
I believe this issue has been resolved with Next-translate 2.0, as we have rewritten the plugin and replaced the use of regex with a parser. This update has automatically addressed many of the issues related to attempting to parse items with regex.
I trust that this solution has fully resolved the matter, and as such, I will proceed to close the issue. Additionally, I would like to inform you that we have moved the plugin to this repository: https://github.com/aralroca/next-translate-plugin.
If, for any reason, you find that the issue has not been fully resolved, please feel free to reopen the issue on the next-translate-plugin repository.
Thank you very much.