Skip to content

Commit

Permalink
Add i18n items to routes manifest (#17893)
Browse files Browse the repository at this point in the history
This adds the i18n config items to the routes-manifest so that they can accessed in the builder. This doesn't increment the routes-manifest version as existing value shapes haven't been modified and an additional non-breaking value is being added

x-ref: #17370
  • Loading branch information
ijjk committed Oct 15, 2020
1 parent b14331c commit acd44c5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/next/build/index.ts
Expand Up @@ -306,6 +306,15 @@ export default async function build(
dataRouteRegex: string
namedDataRouteRegex?: string
}>
i18n?: {
locales: string[]
defaultLocale: string[]
domains: Array<{
domain: string
defaultLocale: string
locales: string[]
}>
}
} = {
version: 3,
pages404: true,
Expand All @@ -325,6 +334,7 @@ export default async function build(
}
}),
dataRoutes: [],
i18n: config.experimental.i18n || undefined,
}

await promises.mkdir(distDir, { recursive: true })
Expand Down
6 changes: 6 additions & 0 deletions packages/next/export/index.ts
Expand Up @@ -285,6 +285,12 @@ export default async function exportApp(

const { i18n } = nextConfig.experimental

if (i18n && !options.buildExport) {
throw new Error(
`i18n support is not compatible with next export. See here for more info on deploying: https://nextjs.org/docs/deployment`
)
}

// Start the rendering process
const renderOpts = {
dir,
Expand Down
25 changes: 25 additions & 0 deletions test/integration/i18n-support/test/index.test.js
Expand Up @@ -34,6 +34,31 @@ async function addDefaultLocaleCookie(browser) {
}

function runTests(isDev) {
if (!isDev) {
it('should add i18n config to routes-manifest', async () => {
const routesManifest = await fs.readJSON(
join(appDir, '.next/routes-manifest.json')
)

expect(routesManifest.i18n).toEqual({
locales: ['en-US', 'nl-NL', 'nl-BE', 'nl', 'fr-BE', 'fr', 'en'],
defaultLocale: 'en-US',
domains: [
{
http: true,
domain: 'example.be',
defaultLocale: 'nl-BE',
},
{
http: true,
domain: 'example.fr',
defaultLocale: 'fr',
},
],
})
})
}

it('should navigate with locale prop correctly', async () => {
const browser = await webdriver(appPort, '/links?nextLocale=fr')
await addDefaultLocaleCookie(browser)
Expand Down

0 comments on commit acd44c5

Please sign in to comment.