Skip to content

Commit

Permalink
fix(server-side): use environment I18NEXT_DEFAULT_CONFIG_PATH to ch…
Browse files Browse the repository at this point in the history
…ange the default config path (#2089)
  • Loading branch information
intpp committed Feb 7, 2023
1 parent 58a0869 commit efa1a63
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ 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`.
Expand Down Expand Up @@ -357,7 +356,8 @@ module.exports = {
```

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}`.
-->

**Notice** If your config `next-i18next.config.js` is not in the same directory as `next.config.js`, you must copy it manually (or by custom script).

## Notes

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions src/serverSideTranslations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ import { globalI18n } from './appWithTranslation'
import { UserConfig, SSRConfig } from './types'
import { getFallbackForLng, unique } from './utils'

const DEFAULT_CONFIG_PATH = './next-i18next.config.js'
let DEFAULT_CONFIG_PATH = './next-i18next.config.js'

/**
* One line expression like `const { I18NEXT_DEFAULT_CONFIG_PATH: DEFAULT_CONFIG_PATH = './next-i18next.config.js' } = process.env;`
* is breaking the build, so keep it like this.
*
* @see https://github.com/i18next/next-i18next/pull/2084#issuecomment-1420511358
*/
if (process.env.I18NEXT_DEFAULT_CONFIG_PATH) {
DEFAULT_CONFIG_PATH = process.env.I18NEXT_DEFAULT_CONFIG_PATH
}

export const serverSideTranslations = async (
initialLocale: string,
Expand All @@ -24,7 +34,6 @@ export const serverSideTranslations = async (
}

let userConfig = configOverride
// const configPath = path.resolve(process.env.I18NEXT_DEFAULT_CONFIG_PATH || DEFAULT_CONFIG_PATH)
const configPath = path.resolve(DEFAULT_CONFIG_PATH)

if (
Expand Down

0 comments on commit efa1a63

Please sign in to comment.