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

feat(server-side): custom default config path #2084

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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