question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example of integrating next-i18next using typescript

See original GitHub issue

Right now I try to integrate next-i18next into my nextjs project where I am using typescript. I am struggling with making it work properly. Is there someone out there who has a repo where I can check how its done or can someone maybe create a small codesandbox or sth? Would be awesome, I could also make it nice and contribute it to the repo

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

21reactions
kachkaevcommented, Feb 22, 2019

Hi @BjoernRave! Feel free to check out my integration of this library into a TypeScript project: https://gitlab.com/kachkaev/website-frontend

I guess the issue can be close because it’s a question and not a bug or a feature request. Although it might be worth adding a TypeScript example into the repo at one point 😉

3reactions
MichalWcommented, Feb 18, 2020

This is my approach to this problem: Generally based on this: https://www.freecodecamp.org/news/how-to-enable-es6-and-beyond-syntax-with-node-and-express-68d3e11fe1ab

package.json:

 "scripts": {
    "dev": "npm-run-all clean transpile server:dev",
    "start": "npm-run-all clean transpile build server:prod",
    "build": "next build",
    "server:prod": "NODE_ENV=production node .build/server",
    "server:dev": "node .build/server",
    "transpile": "babel server.ts i18n.ts --extensions \".ts\" --out-dir .build",
    "clean": "rimraf dist-server",
    ...
  },
  "dependencies": {
    "@babel/cli": "^7.8.4",
    "express": "^4.17.1",
    "npm-run-all": "^4.1.5",
    "rimraf": "^3.0.2",
    ...
  }
  "

i18n.ts:

import NextI18Next from 'next-i18next';

const NextI18NextInstance = new NextI18Next({
  defaultLanguage: 'en',
  defaultNS: 'translations',
  localePath: 'public/locales',
  otherLanguages: ['de'],
});

export const { appWithTranslation, useTranslation } = NextI18NextInstance;

export default NextI18NextInstance;

server.ts

import express from 'express';
import next from 'next';
import nextI18NextMiddleware from 'next-i18next/middleware';
import nextI18next from './i18n';

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

(async () => {
  await app.prepare();
  await nextI18next.initPromise;

  await express()
    .use(nextI18NextMiddleware(nextI18next))
    .get('*', (req, res) => appHandler(req, res))
    .listen(port);
})();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Example of integrating next-i18next using typescript · Issue #195
Right now I try to integrate next-i18next into my nextjs project where I am using typescript. I am struggling with making it work...
Read more >
How to add i18n to your Next.js v10 app with Typescript
We are going to extend them by using Type Augmentation and Interface Merging. We import our new resources interface and extend react-i18next ......
Read more >
TypeScript - i18next documentation
TypeScript definitions for i18next can be extended by using Type Augmentation and Merging Interfaces. So the first step is creating a declaration file ......
Read more >
Internationalize your Next application with i18n and TypeScript
To do this, create a next application. With TypeScript, it makes it easy to define prop types, which makes code much easier to...
Read more >
Internationalize the Next.js application using next-i18next
In this tutorial, we'll walk you through Internationalizing the Next.js application ... First, we need to create the Next.js application with TypeScript.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found