Skip to content

Commit

Permalink
Enable i18n feature flag (#18303)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Oct 27, 2020
1 parent 0f25051 commit 9a13dd3
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 64 deletions.
4 changes: 1 addition & 3 deletions packages/next/build/entries.ts
Expand Up @@ -98,9 +98,7 @@ export function createEntrypoints(
loadedEnvFiles: Buffer.from(JSON.stringify(loadedEnvFiles)).toString(
'base64'
),
i18n: config.experimental.i18n
? JSON.stringify(config.experimental.i18n)
: '',
i18n: config.i18n ? JSON.stringify(config.i18n) : '',
}

Object.keys(pages).forEach((page) => {
Expand Down
12 changes: 6 additions & 6 deletions packages/next/build/index.ts
Expand Up @@ -336,7 +336,7 @@ export default async function build(
}
}),
dataRoutes: [],
i18n: config.experimental.i18n || undefined,
i18n: config.i18n || undefined,
}

await promises.mkdir(distDir, { recursive: true })
Expand Down Expand Up @@ -576,8 +576,8 @@ export default async function build(
page,
serverBundle,
runtimeEnvConfig,
config.experimental.i18n?.locales,
config.experimental.i18n?.defaultLocale
config.i18n?.locales,
config.i18n?.defaultLocale
)

if (workerResult.isHybridAmp) {
Expand Down Expand Up @@ -739,7 +739,7 @@ export default async function build(
// n.b. we cannot handle this above in combinedPages because the dynamic
// page must be in the `pages` array, but not in the mapping.
exportPathMap: (defaultMap: any) => {
const { i18n } = config.experimental
const { i18n } = config

// Dynamically routed pages should be prerendered to be used as
// a client-side skeleton (fallback) while data is being fetched.
Expand Down Expand Up @@ -878,7 +878,7 @@ export default async function build(
pagesManifest[page] = relativeDest
}

const { i18n } = config.experimental
const { i18n } = config
const isNotFound = ssgNotFoundPaths.includes(page)

// for SSG files with i18n the non-prerendered variants are
Expand Down Expand Up @@ -960,7 +960,7 @@ export default async function build(
}

if (isSsg) {
const { i18n } = config.experimental
const { i18n } = config

// For a non-dynamic SSG page, we must copy its data file from export.
if (!isDynamic) {
Expand Down
8 changes: 2 additions & 6 deletions packages/next/build/webpack-config.ts
Expand Up @@ -1004,12 +1004,8 @@ export default async function getBaseWebpackConfig(
}),
'process.env.__NEXT_ROUTER_BASEPATH': JSON.stringify(config.basePath),
'process.env.__NEXT_HAS_REWRITES': JSON.stringify(hasRewrites),
'process.env.__NEXT_I18N_SUPPORT': JSON.stringify(
!!config.experimental.i18n
),
'process.env.__NEXT_I18N_DOMAINS': JSON.stringify(
config.experimental.i18n.domains
),
'process.env.__NEXT_I18N_SUPPORT': JSON.stringify(!!config.i18n),
'process.env.__NEXT_I18N_DOMAINS': JSON.stringify(config.i18n.domains),
'process.env.__NEXT_ANALYTICS_ID': JSON.stringify(config.analyticsId),
...(isServer
? {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/export/index.ts
Expand Up @@ -283,7 +283,7 @@ export default async function exportApp(
}
}

const { i18n } = nextConfig.experimental
const { i18n } = nextConfig

if (i18n && !options.buildExport) {
throw new Error(
Expand Down
6 changes: 3 additions & 3 deletions packages/next/next-server/server/config.ts
Expand Up @@ -45,6 +45,7 @@ const defaultConfig: { [key: string]: any } = {
basePath: '',
sassOptions: {},
trailingSlash: false,
i18n: false,
experimental: {
cpus: Math.max(
1,
Expand All @@ -62,7 +63,6 @@ const defaultConfig: { [key: string]: any } = {
optimizeFonts: false,
optimizeImages: false,
scrollRestoration: false,
i18n: false,
},
future: {
excludeDefaultMomentLocales: false,
Expand Down Expand Up @@ -310,8 +310,8 @@ function assignDefaults(userConfig: { [key: string]: any }) {
}
}

if (result.experimental?.i18n) {
const { i18n } = result.experimental
if (result.i18n) {
const { i18n } = result
const i18nType = typeof i18n

if (i18nType !== 'object') {
Expand Down
11 changes: 5 additions & 6 deletions packages/next/next-server/server/next-server.ts
Expand Up @@ -198,7 +198,7 @@ export default class Server {
? requireFontManifest(this.distDir, this._isLikeServerless)
: null,
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
Expand Down Expand Up @@ -298,8 +298,7 @@ export default class Server {
parsedUrl.query = parseQs(parsedUrl.query)
}

const { basePath } = this.nextConfig
const { i18n } = this.nextConfig.experimental
const { basePath, i18n } = this.nextConfig

if (basePath && req.url?.startsWith(basePath)) {
// store original URL to allow checking if basePath was
Expand Down Expand Up @@ -577,7 +576,7 @@ export default class Server {
// re-create page's pathname
let pathname = `/${params.path.join('/')}`

const { i18n } = this.nextConfig.experimental
const { i18n } = this.nextConfig

if (i18n) {
const { host } = req?.headers || {}
Expand Down Expand Up @@ -1213,7 +1212,7 @@ export default class Server {
const locale = query.__nextLocale as string
delete query.__nextLocale

const { i18n } = this.nextConfig.experimental
const { i18n } = this.nextConfig
const locales = i18n.locales as string[]

let previewData: string | false | object | undefined
Expand Down Expand Up @@ -1243,7 +1242,7 @@ export default class Server {
)
}

if (this.nextConfig.experimental.i18n) {
if (this.nextConfig.i18n) {
return normalizeLocalePath(path, locales).pathname
}
return path
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/next-dev-server.ts
Expand Up @@ -534,7 +534,7 @@ export default class DevServer extends Server {

const __getStaticPaths = async () => {
const { publicRuntimeConfig, serverRuntimeConfig } = this.nextConfig
const { locales, defaultLocale } = this.nextConfig.experimental.i18n || {}
const { locales, defaultLocale } = this.nextConfig.i18n || {}

const paths = await this.staticPathsWorker.loadStaticPaths(
this.distDir,
Expand Down
3 changes: 1 addition & 2 deletions packages/next/telemetry/events/version.ts
Expand Up @@ -114,8 +114,7 @@ export function eventCliSession(

const userConfiguration = getNextConfig(phase, dir)

const { images, experimental } = userConfiguration || {}
const { i18n } = experimental || {}
const { images, i18n } = userConfiguration || {}

const payload: EventCliSessionStarted = {
nextVersion: process.env.__NEXT_VERSION,
Expand Down
40 changes: 19 additions & 21 deletions test/integration/i18n-support/next.config.js
@@ -1,25 +1,23 @@
module.exports = {
// target: 'experimental-serverless-trace',
experimental: {
i18n: {
locales: ['nl-NL', 'nl-BE', 'nl', 'fr-BE', 'fr', 'en-US', 'en'],
defaultLocale: 'en-US',
domains: [
{
// used for testing, this should not be needed in most cases
// as production domains should always use https
http: true,
domain: 'example.be',
defaultLocale: 'nl-BE',
locales: ['nl', 'nl-NL', 'nl-BE'],
},
{
http: true,
domain: 'example.fr',
defaultLocale: 'fr',
locales: ['fr-BE'],
},
],
},
i18n: {
locales: ['nl-NL', 'nl-BE', 'nl', 'fr-BE', 'fr', 'en-US', 'en'],
defaultLocale: 'en-US',
domains: [
{
// used for testing, this should not be needed in most cases
// as production domains should always use https
http: true,
domain: 'example.be',
defaultLocale: 'nl-BE',
locales: ['nl', 'nl-NL', 'nl-BE'],
},
{
http: true,
domain: 'example.fr',
defaultLocale: 'fr',
locales: ['fr-BE'],
},
],
},
}
28 changes: 13 additions & 15 deletions test/integration/telemetry/next.config.i18n-images
Expand Up @@ -4,21 +4,19 @@ module.exports = phase => {
sizes: [64, 128, 256, 512, 1024],
domains: ['example.com'],
},
experimental: {
i18n: {
locales: ['en','nl','fr'],
defaultLocale: 'en',
domains: [
{
domain: 'example.com',
defaultLocale: 'en'
},
{
domain: 'example.fr',
defaultLocale: 'fr'
}
]
}
i18n: {
locales: ['en','nl','fr'],
defaultLocale: 'en',
domains: [
{
domain: 'example.com',
defaultLocale: 'en'
},
{
domain: 'example.fr',
defaultLocale: 'fr'
}
]
}
}
}

0 comments on commit 9a13dd3

Please sign in to comment.