Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i18n support is not compatible with next export. (SSR - NextJS 10)

i18n support is not compatible with next export.

NextJS dont run the deploy with i18n

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.

My code

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/"

Steps to reproduce

  1. Go to 'next.config,js'
  2. create the i18n export
  3. create a Translate file that recognizes the browser language
  4. import JSONs files with your site text
  5. Use where you want
  6. Try to deploy

Expected behavior

Its just suppose to work fine and Deploy normal.

Screenshots

imageimageimageimage

System information

  • OS: Linux Ubuntu
  • IDE: VSCode
  • Version of Next.js: 10
  • Version of Node.js: v15.3.0
  • Deployment: next deploy
like image 621
Luck dev Avatar asked Dec 30 '20 20:12

Luck dev


People also ask

Can I use I18N with next export?

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.

Does next export integrate with internationalized routing?

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!

What version of next JS is 100% serverless?

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.


1 Answers

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.

like image 135
Piotr Ma'niak Avatar answered Sep 23 '22 15:09

Piotr Ma'niak