Im using nextJS 10, and the main reason that i choose next 10, is that i can do SSR and use the i18n. Internationalized Routing its a new next js 10 feature and have a page only to tha feature.
But when im gonna do a deploy, this error appears: i18n support is not compatible with next export. Theres nothing about this in internationalized routing page.
next.config.js
const withImages = require('next-images')
const path = require('path')
module.exports = withImages({
esModule: false,
i18n: {
locales: ['en-US', 'pt-BR', 'pt-PT', 'es-ES'],
defaultLocale: 'pt-BR',
},
});
I created a translate archive that make the condition with next router obs: PT and EN are JSON files with text
import * as pt from "./pt";
import * as en from './en';
import { useRouter } from "next/router"
export const traducao = () =>{
let routes = useRouter();
let translate;
if (routes.locale == 'pt-PT' || routes.locale == 'pt-BR') {
translate = pt.default;
} else {
translate = en.default;
}
return translate
}
And the i just use in my project like a function:
{traducao().homeText.button_text}
Work well, recognizes the browser language and switch. Im using deploy script
npm run deploy
"deploy": "npm run clean && npm run build && next export -o dist/"
Its just suppose to work fine and Deploy normal.
i18n support is not compatible with next export. Im using nextJS 10, and the main reason that i choose next 10, is that i can do SSR and use the i18n. Internationalized Routing its a new next js 10 feature and have a page only to tha feature.
Note that Internationalized Routing does not integrate with next export as next export does not leverage the Next.js routing layer. Hybrid Next.js applications that do not use next export are fully supported. Thanks for contributing an answer to Stack Overflow!
So let's dive in using Next.js 9.3 Server-Side Generation (SSG) and 100% serverless. You can also jump straight into code by heading into this repo.
Digging through issues on vercel's github I found this alternative that doesn't use next-i18next or any other nextjs magic:
https://github.com/Xairoo/nextjs-i18n-static-page-starter
It's just basic i18n using i18next that bundles all locale together with JS, so there are obvious tradeoffs but at least it works with SSG. You can build upon that to come up with something more elaborate. That's what I will do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With