Unverified Commit 9a13dd34 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Enable i18n feature flag (#18303)

parent 0f250514
...@@ -98,9 +98,7 @@ export function createEntrypoints( ...@@ -98,9 +98,7 @@ export function createEntrypoints(
loadedEnvFiles: Buffer.from(JSON.stringify(loadedEnvFiles)).toString( loadedEnvFiles: Buffer.from(JSON.stringify(loadedEnvFiles)).toString(
'base64' 'base64'
), ),
i18n: config.experimental.i18n i18n: config.i18n ? JSON.stringify(config.i18n) : '',
? JSON.stringify(config.experimental.i18n)
: '',
} }
Object.keys(pages).forEach((page) => { Object.keys(pages).forEach((page) => {
......
...@@ -336,7 +336,7 @@ export default async function build( ...@@ -336,7 +336,7 @@ export default async function build(
} }
}), }),
dataRoutes: [], dataRoutes: [],
i18n: config.experimental.i18n || undefined, i18n: config.i18n || undefined,
} }
await promises.mkdir(distDir, { recursive: true }) await promises.mkdir(distDir, { recursive: true })
...@@ -576,8 +576,8 @@ export default async function build( ...@@ -576,8 +576,8 @@ export default async function build(
page, page,
serverBundle, serverBundle,
runtimeEnvConfig, runtimeEnvConfig,
config.experimental.i18n?.locales, config.i18n?.locales,
config.experimental.i18n?.defaultLocale config.i18n?.defaultLocale
) )
if (workerResult.isHybridAmp) { if (workerResult.isHybridAmp) {
...@@ -739,7 +739,7 @@ export default async function build( ...@@ -739,7 +739,7 @@ export default async function build(
// n.b. we cannot handle this above in combinedPages because the dynamic // n.b. we cannot handle this above in combinedPages because the dynamic
// page must be in the `pages` array, but not in the mapping. // page must be in the `pages` array, but not in the mapping.
exportPathMap: (defaultMap: any) => { exportPathMap: (defaultMap: any) => {
const { i18n } = config.experimental const { i18n } = config
// Dynamically routed pages should be prerendered to be used as // Dynamically routed pages should be prerendered to be used as
// a client-side skeleton (fallback) while data is being fetched. // a client-side skeleton (fallback) while data is being fetched.
...@@ -878,7 +878,7 @@ export default async function build( ...@@ -878,7 +878,7 @@ export default async function build(
pagesManifest[page] = relativeDest pagesManifest[page] = relativeDest
} }
const { i18n } = config.experimental const { i18n } = config
const isNotFound = ssgNotFoundPaths.includes(page) const isNotFound = ssgNotFoundPaths.includes(page)
// for SSG files with i18n the non-prerendered variants are // for SSG files with i18n the non-prerendered variants are
...@@ -960,7 +960,7 @@ export default async function build( ...@@ -960,7 +960,7 @@ export default async function build(
} }
if (isSsg) { if (isSsg) {
const { i18n } = config.experimental const { i18n } = config
// For a non-dynamic SSG page, we must copy its data file from export. // For a non-dynamic SSG page, we must copy its data file from export.
if (!isDynamic) { if (!isDynamic) {
......
...@@ -1004,12 +1004,8 @@ export default async function getBaseWebpackConfig( ...@@ -1004,12 +1004,8 @@ export default async function getBaseWebpackConfig(
}), }),
'process.env.__NEXT_ROUTER_BASEPATH': JSON.stringify(config.basePath), 'process.env.__NEXT_ROUTER_BASEPATH': JSON.stringify(config.basePath),
'process.env.__NEXT_HAS_REWRITES': JSON.stringify(hasRewrites), 'process.env.__NEXT_HAS_REWRITES': JSON.stringify(hasRewrites),
'process.env.__NEXT_I18N_SUPPORT': JSON.stringify( 'process.env.__NEXT_I18N_SUPPORT': JSON.stringify(!!config.i18n),
!!config.experimental.i18n 'process.env.__NEXT_I18N_DOMAINS': JSON.stringify(config.i18n.domains),
),
'process.env.__NEXT_I18N_DOMAINS': JSON.stringify(
config.experimental.i18n.domains
),
'process.env.__NEXT_ANALYTICS_ID': JSON.stringify(config.analyticsId), 'process.env.__NEXT_ANALYTICS_ID': JSON.stringify(config.analyticsId),
...(isServer ...(isServer
? { ? {
......
...@@ -283,7 +283,7 @@ export default async function exportApp( ...@@ -283,7 +283,7 @@ export default async function exportApp(
} }
} }
const { i18n } = nextConfig.experimental const { i18n } = nextConfig
if (i18n && !options.buildExport) { if (i18n && !options.buildExport) {
throw new Error( throw new Error(
......
...@@ -45,6 +45,7 @@ const defaultConfig: { [key: string]: any } = { ...@@ -45,6 +45,7 @@ const defaultConfig: { [key: string]: any } = {
basePath: '', basePath: '',
sassOptions: {}, sassOptions: {},
trailingSlash: false, trailingSlash: false,
i18n: false,
experimental: { experimental: {
cpus: Math.max( cpus: Math.max(
1, 1,
...@@ -62,7 +63,6 @@ const defaultConfig: { [key: string]: any } = { ...@@ -62,7 +63,6 @@ const defaultConfig: { [key: string]: any } = {
optimizeFonts: false, optimizeFonts: false,
optimizeImages: false, optimizeImages: false,
scrollRestoration: false, scrollRestoration: false,
i18n: false,
}, },
future: { future: {
excludeDefaultMomentLocales: false, excludeDefaultMomentLocales: false,
...@@ -310,8 +310,8 @@ function assignDefaults(userConfig: { [key: string]: any }) { ...@@ -310,8 +310,8 @@ function assignDefaults(userConfig: { [key: string]: any }) {
} }
} }
if (result.experimental?.i18n) { if (result.i18n) {
const { i18n } = result.experimental const { i18n } = result
const i18nType = typeof i18n const i18nType = typeof i18n
if (i18nType !== 'object') { if (i18nType !== 'object') {
......
...@@ -198,7 +198,7 @@ export default class Server { ...@@ -198,7 +198,7 @@ export default class Server {
? requireFontManifest(this.distDir, this._isLikeServerless) ? requireFontManifest(this.distDir, this._isLikeServerless)
: null, : null,
optimizeImages: this.nextConfig.experimental.optimizeImages, optimizeImages: this.nextConfig.experimental.optimizeImages,
defaultLocale: this.nextConfig.experimental.i18n?.defaultLocale, defaultLocale: this.nextConfig.i18n?.defaultLocale,
} }
// Only the `publicRuntimeConfig` key is exposed to the client side // Only the `publicRuntimeConfig` key is exposed to the client side
...@@ -298,8 +298,7 @@ export default class Server { ...@@ -298,8 +298,7 @@ export default class Server {
parsedUrl.query = parseQs(parsedUrl.query) parsedUrl.query = parseQs(parsedUrl.query)
} }
const { basePath } = this.nextConfig const { basePath, i18n } = this.nextConfig
const { i18n } = this.nextConfig.experimental
if (basePath && req.url?.startsWith(basePath)) { if (basePath && req.url?.startsWith(basePath)) {
// store original URL to allow checking if basePath was // store original URL to allow checking if basePath was
...@@ -577,7 +576,7 @@ export default class Server { ...@@ -577,7 +576,7 @@ export default class Server {
// re-create page's pathname // re-create page's pathname
let pathname = `/${params.path.join('/')}` let pathname = `/${params.path.join('/')}`
const { i18n } = this.nextConfig.experimental const { i18n } = this.nextConfig
if (i18n) { if (i18n) {
const { host } = req?.headers || {} const { host } = req?.headers || {}
...@@ -1213,7 +1212,7 @@ export default class Server { ...@@ -1213,7 +1212,7 @@ export default class Server {
const locale = query.__nextLocale as string const locale = query.__nextLocale as string
delete query.__nextLocale delete query.__nextLocale
const { i18n } = this.nextConfig.experimental const { i18n } = this.nextConfig
const locales = i18n.locales as string[] const locales = i18n.locales as string[]
let previewData: string | false | object | undefined let previewData: string | false | object | undefined
...@@ -1243,7 +1242,7 @@ export default class Server { ...@@ -1243,7 +1242,7 @@ export default class Server {
) )
} }
if (this.nextConfig.experimental.i18n) { if (this.nextConfig.i18n) {
return normalizeLocalePath(path, locales).pathname return normalizeLocalePath(path, locales).pathname
} }
return path return path
......
...@@ -534,7 +534,7 @@ export default class DevServer extends Server { ...@@ -534,7 +534,7 @@ export default class DevServer extends Server {
const __getStaticPaths = async () => { const __getStaticPaths = async () => {
const { publicRuntimeConfig, serverRuntimeConfig } = this.nextConfig const { publicRuntimeConfig, serverRuntimeConfig } = this.nextConfig
const { locales, defaultLocale } = this.nextConfig.experimental.i18n || {} const { locales, defaultLocale } = this.nextConfig.i18n || {}
const paths = await this.staticPathsWorker.loadStaticPaths( const paths = await this.staticPathsWorker.loadStaticPaths(
this.distDir, this.distDir,
......
...@@ -114,8 +114,7 @@ export function eventCliSession( ...@@ -114,8 +114,7 @@ export function eventCliSession(
const userConfiguration = getNextConfig(phase, dir) const userConfiguration = getNextConfig(phase, dir)
const { images, experimental } = userConfiguration || {} const { images, i18n } = userConfiguration || {}
const { i18n } = experimental || {}
const payload: EventCliSessionStarted = { const payload: EventCliSessionStarted = {
nextVersion: process.env.__NEXT_VERSION, nextVersion: process.env.__NEXT_VERSION,
......
module.exports = { module.exports = {
// target: 'experimental-serverless-trace', // target: 'experimental-serverless-trace',
experimental: { i18n: {
i18n: { locales: ['nl-NL', 'nl-BE', 'nl', 'fr-BE', 'fr', 'en-US', 'en'],
locales: ['nl-NL', 'nl-BE', 'nl', 'fr-BE', 'fr', 'en-US', 'en'], defaultLocale: 'en-US',
defaultLocale: 'en-US', domains: [
domains: [ {
{ // used for testing, this should not be needed in most cases
// used for testing, this should not be needed in most cases // as production domains should always use https
// as production domains should always use https http: true,
http: true, domain: 'example.be',
domain: 'example.be', defaultLocale: 'nl-BE',
defaultLocale: 'nl-BE', locales: ['nl', 'nl-NL', 'nl-BE'],
locales: ['nl', 'nl-NL', 'nl-BE'], },
}, {
{ http: true,
http: true, domain: 'example.fr',
domain: 'example.fr', defaultLocale: 'fr',
defaultLocale: 'fr', locales: ['fr-BE'],
locales: ['fr-BE'], },
}, ],
],
},
}, },
} }
...@@ -4,21 +4,19 @@ module.exports = phase => { ...@@ -4,21 +4,19 @@ module.exports = phase => {
sizes: [64, 128, 256, 512, 1024], sizes: [64, 128, 256, 512, 1024],
domains: ['example.com'], domains: ['example.com'],
}, },
experimental: { i18n: {
i18n: { locales: ['en','nl','fr'],
locales: ['en','nl','fr'], defaultLocale: 'en',
defaultLocale: 'en', domains: [
domains: [ {
{ domain: 'example.com',
domain: 'example.com', defaultLocale: 'en'
defaultLocale: 'en' },
}, {
{ domain: 'example.fr',
domain: 'example.fr', defaultLocale: 'fr'
defaultLocale: 'fr' }
} ]
]
}
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment