Skip to content

Commit

Permalink
feat(server-side): custom default config path (#2084)
Browse files Browse the repository at this point in the history
  • Loading branch information
intpp authored Feb 2, 2023
1 parent 57fd3cb commit 8f67f5f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,34 @@ For example, if you want to use `{` and `}` the config would look like this:
}
```

#### Custom `next-i18next.config.js` path

If you want to change the default config path, you can set the environment variable `I18NEXT_DEFAULT_CONFIG_PATH`.

For example, inside the `.env` file you can set a static path:
```
I18NEXT_DEFAULT_CONFIG_PATH=/path/to/project/apps/my-app/next-i18next.config.js
```

Or you can use a trick for dynamic path and set the following inside `next.config.js`:

```js
process.env.I18NEXT_DEFAULT_CONFIG_PATH = `${__dirname}/next-i18next.config.js`;

// ... Some other imports

const { i18n } = require('./next-i18next.config');

// ... Some other code

module.exports = {
i18n,
...
};
```

This means that the i18n configuration file will be in the same directory as `next.config.js` and it doesn't matter where your current working directory is. This helps for example for `nx` when you have monorepo and start your application from project root but the application is in `apps/{appName}`.

## Notes

### Vercel and Netlify
Expand Down
2 changes: 1 addition & 1 deletion src/serverSideTranslations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { globalI18n } from './appWithTranslation'
import { UserConfig, SSRConfig } from './types'
import { getFallbackForLng, unique } from './utils'

const DEFAULT_CONFIG_PATH = './next-i18next.config.js'
const { I18NEXT_DEFAULT_CONFIG_PATH: DEFAULT_CONFIG_PATH = './next-i18next.config.js' } = process.env

export const serverSideTranslations = async (
initialLocale: string,
Expand Down

0 comments on commit 8f67f5f

Please sign in to comment.