Next-i18next: Incorrect setup instructions

Created on 19 Apr 2020  路  6Comments  路  Source: isaachinman/next-i18next

Describe the bug

In step 3 you suggest to setup i18n config using import type of modules which does not work by default in express server.

import NextI18Next from 'next-i18next'

const NextI18NextInstance = new NextI18Next({
  defaultLanguage: 'en',
  otherLanguages: ['de']
})

export default NextI18NextInstance

Your own simple example uses require type of modules but as you mention in the comments we can't just copy paste it. Even if we switch on the experimental feature for node.js to support import modules, the example still breaks as your server.js file uses old require modules. So you need a bit more hassle with the example and the instructions.

I would suggest to change the step 3 to:

const NextI18Next = require('next-i18next').default

module.exports = new NextI18Next({
  defaultLanguage: 'en',
  otherLanguages: ['de'],
})

Also I would appreciate if you add in your setup instruction a bit of reasoning information. It is not completely clear why you decided to go with the custom express server instead of loading translations in getInitialProps of _app.js file.
Is it only for the custom routing feature?

Most helpful comment

If we change the module setup for docs/examples, someone will later complain that we're not using ES6 modules, etc.

@isaachinman At least the documentation should be consistent, don't you agree? Unexpirenced Users tend to follow installation and setup instructions step by step an getting confused if something unexpected happens.

All 6 comments

+

How you manage modules and syntax is entirely up to you! If we change the module setup for docs/examples, someone will later complain that we're not using ES6 modules, etc.

That said, if you think you can clarify or simplify documentation, please do feel free to submit a PR and I will review it promptly.

The custom server is necessary to use i18next-express-middleware, which drives language detection. No routing occurs at the Express level - NextJs includes a router.

If we change the module setup for docs/examples, someone will later complain that we're not using ES6 modules, etc.

@isaachinman At least the documentation should be consistent, don't you agree? Unexpirenced Users tend to follow installation and setup instructions step by step an getting confused if something unexpected happens.

Sure, I don't have much of an opinion on which module system to use in the docs. If you think it'll help unexperienced users, that's fine with me. The reason we have a working example is to provide something concrete if you really do want to copy/paste.

I will submit PR for this part of the doc in the next few days

Okay - just a heads up that I will be rewriting next-i18next pretty significantly quite soon and the API will change.

Was this page helpful?
0 / 5 - 0 ratings