Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [16.10.x, 18.x, 20.x]
node-version: [20.x, 22.x]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
Expand Down
50 changes: 35 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,18 @@ function nextTranslate(
}
}

let nextConfigWithI18n: NextConfig = hasAppJs
? nextConfig
: {
...nextConfig,
i18n: {
locales,
defaultLocale,
domains,
localeDetection,
},
}
const nextConfigWithI18n: NextConfig =
hasAppJs || !existPagesFolder
? nextConfig
: {
...nextConfig,
i18n: {
locales,
defaultLocale,
domains,
localeDetection,
},
}

const webpackConfig: NextConfig['webpack'] = (
conf: webpack.Configuration,
Expand Down Expand Up @@ -169,23 +170,42 @@ function nextTranslate(
},
resolveAlias: {
...(nextConfig.turbopack?.resolveAlias || {}),
'@next-translate-root/*': `./*`,
'@next-translate-root': '.',
'@next-translate-root/*': './*',
'next-translate': './node_modules/next-translate',
'next-translate/*': './node_modules/next-translate/*',
},
}

return {
const finalConfig: NextConfig = {
...nextConfigWithI18n,
...(turbopack
? { turbopack: turbopackConfig }
: { webpack: webpackConfig }),
}

if (turbopack && finalConfig.webpack) {
delete finalConfig.webpack
}

return finalConfig
}

function pkgDir() {
const cwd = process.cwd()
if (
fs.existsSync(path.join(cwd, 'i18n.js')) ||
fs.existsSync(path.join(cwd, 'i18n.json')) ||
fs.existsSync(path.join(cwd, 'i18n.mjs')) ||
fs.existsSync(path.join(cwd, 'i18n.cjs'))
) {
return cwd
}

try {
return (require('pkg-dir').sync() as string) || process.cwd()
return (require('pkg-dir').sync() as string) || cwd
} catch (e) {
return process.cwd()
return cwd
}
}

Expand Down