Skip to content
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

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

Closed
lucasReghiniM opened this issue Dec 30, 2020 · 15 comments
Closed

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

lucasReghiniM opened this issue Dec 30, 2020 · 15 comments
Labels
bug Issue was opened via the bug report template.

Comments

@lucasReghiniM
Copy link

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

image
image
image
image

System information

  • OS: Linux Ubuntu
  • IDE: VSCode
  • Version of Next.js: 10
  • Version of Node.js: v15.3.0
  • Deployment: next deploy
@lucasReghiniM lucasReghiniM added the bug Issue was opened via the bug report template. label Dec 30, 2020
@ijjk
Copy link
Member

ijjk commented Dec 30, 2020

Closing as duplicate of #18318

@ijjk ijjk closed this as completed Dec 30, 2020
@lucasReghiniM
Copy link
Author

Closing as duplicate of #18318

But no one came to a conclusion on this topic.
I18n is a new next function that is presented on next's own website, there should be documentation explaining this error. (well ... that error shouldn't even exist.)

@lucasReghiniM
Copy link
Author

I need to deploy this today, what can i do?

@lucasReghiniM
Copy link
Author

You just closed that issue report too

@ijjk
Copy link
Member

ijjk commented Dec 30, 2020

If you are deploying on a platform that supports Next.js like Vercel you do not need to call next export and will not encounter the error, also note calling next export disables pages from using getServerSideProps or other SSR features. next export support was not mentioned in the initial i18n RFC since next export is opting out of Next.js server routing support.

@lucasReghiniM
Copy link
Author

If you are deploying on a platform that supports Next.js like Vercel you do not need to call next export and will not encounter the error, also note calling next export disables pages from using getServerSideProps or other SSR features. next export support was not mentioned in the initial i18n RFC since next export is opting out of Next.js server routing support.

I understand.
However I did not try to use the export.
I just used the deploy script (npm run deploy). This script already comes with the project.
What can I do to deploy without export.
I'm deploying through Debian, on a company server.

@lucasReghiniM
Copy link
Author

I just need the SSR working well with a good performance. In using NEXT JS to deal better with SEO.

@quyphan97
Copy link

i had similar problem. can anyone tell me how to fix it?

@lucasReghiniM
Copy link
Author

i had similar problem. can anyone tell me how to fix it?

Unfortunately not.
I had a big problem with this, and unfortunately after a lot of searching I couldn't find anyone who was able to solve it.

I think it's really bad that one of the main tools in NEXT doesn't support something that important. simply shameful

@adrai
Copy link

adrai commented Dec 9, 2021

@lucasReghiniM you might have a look at: https://dev.to/adrai/static-html-export-with-i18n-compatibility-in-nextjs-8cd

@bakydev
Copy link

bakydev commented Jan 26, 2022

@lucasReghiniM you might have a look at: https://dev.to/adrai/static-html-export-with-i18n-compatibility-in-nextjs-8cd

Can anyone tell me if it works?

@adrai
Copy link

adrai commented Jan 26, 2022

@bakydev
Copy link

bakydev commented Jan 26, 2022

@lucasReghiniM you might have a look at: https://dev.to/adrai/static-html-export-with-i18n-compatibility-in-nextjs-8cd

Can anyone tell me if it works?

@bakydev for sure it works... an example here: https://github.com/adrai/next-language-detector/tree/main/example

And a production example of localistars.com here: https://github.com/localistars/localistars-landing

cool, I'm gonna try out, btw thank you for the fast answer

@poohia
Copy link

poohia commented Feb 16, 2022

Hello I show you my soluce with only i18n-js, I know is closed

  // i18n.ts
  import i18n from "i18n-js";
  
  import en from "./en.json";
  import fr from "./fr.json";
  
  const localeEnable = ["fr", "en"];
  
  const formatLocale = () => {
    const { language } = window.navigator;
    if (language.includes("en")) return "en";
    if (language.includes("fr")) return "fr";
    if (!localeEnable.includes(language)) return "en";
  
    return "en";
  };
  // Set the key-value pairs for the different languages you want to support.
  i18n.translations = {
    en,
    fr,
  };
  // Set the locale once at the beginning of your app.
  i18n.locale = "en";
  
  const useTranslate = () => {
    return (t: string) => {
      if (typeof window !== "undefined") {
        i18n.locale = formatLocale();
      }
      return i18n.t(t);
    };
  };
  
  export default useTranslate;

  // home.tsx
  import useTranslate from "../locales/i18n";
  
  const t = useTranslate();
  
  return (<p>{t("idstring")}</p>)

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

6 participants