2
votes

I am building a Next.js application that will be using i18next translation organized into the recommended file structure for bundles...like:

static/locales/en/common.js static/locales/de/common.js

...etc.

Using this article: https://medium.com/@isaachinman/creating-localised-nextjs-apps-with-next-i18next-f01d5e610307

I have things currently setup where when the language is changed, the correct bundle is retrieved using the i18next Express middleware. Is there a good alternative that doesn't require a custom node server? Thanks!

I already have things setup using the example here: https://medium.com/@isaachinman/creating-localised-nextjs-apps-with-next-i18next-f01d5e610307

I have also been able to get react-i18next working and delivering all of the bundles at init time.

My custom server.js...

const express = require("express");
const next = require("next");
const nextI18NextMiddleware = require("next-i18next");

const nextI18next = require("./i18n");

const port = process.env.PORT || 3000;
const app = next({ dev: process.env.NODE_ENV !== "production" });
const handle = app.getRequestHandler();

(async () => {
  await app.prepare();
  const server = express();

  server.use(nextI18NextMiddleware(nextI18next));

  server.get("*", (req, res) => handle(req, res));

  await server.listen(port);
  console.log(`> Express.js is Ready on http://localhost:${port}`);
})();

It works great, but I'm looking for alternative methods of retrieving the language bundles in a NEXT.js app that might not require the use of a custom Node Express server.

Any insight, links or assistance is much appreciated!!

1

1 Answers

0
votes

I received an answer on Spectrum:

currently no way, but maybe future https://github.com/zeit/next.js/issues/7208