Skip to content

Commit

Permalink
fix: opt-out of pages config with autoI18n: false
Browse files Browse the repository at this point in the history
Fixes #139
  • Loading branch information
harlan-zw committed Sep 27, 2023
1 parent 802597d commit 7544c4a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export default defineNuxtModule<ModuleOptions>({

let nuxtI18nConfig: NuxtI18nOptions = {}
let resolvedAutoI18n: false | AutoI18nConfig = typeof config.autoI18n === 'boolean' ? false : config.autoI18n || false
const hasDisabledAutoI18n = typeof config.autoI18n === 'boolean' && !config.autoI18n
let normalisedLocales: NormalisedLocales = []
if (hasNuxtModule('@nuxtjs/i18n')) {
const i18nVersion = await getNuxtModuleVersion('@nuxtjs/i18n')
Expand All @@ -285,7 +286,7 @@ export default defineNuxtModule<ModuleOptions>({
nuxtI18nConfig = (await getNuxtModuleOptions('@nuxtjs/i18n') || {}) as NuxtI18nOptions
normalisedLocales = mergeOnKey((nuxtI18nConfig.locales || []).map(locale => typeof locale === 'string' ? { code: locale } : locale), 'code')
const usingI18nPages = Object.keys(nuxtI18nConfig.pages || {}).length
if (usingI18nPages) {
if (usingI18nPages && !hasDisabledAutoI18n) {
for (const pageLocales of Object.values(nuxtI18nConfig?.pages as Record<string, Record<string, string>>)) {
for (const locale in pageLocales) {
// add root entry for default locale and ignore dynamic routes
Expand All @@ -312,7 +313,6 @@ export default defineNuxtModule<ModuleOptions>({
}
const hasDisabledAlternativePrefixes = typeof config.autoAlternativeLangPrefixes === 'boolean' && !config.autoAlternativeLangPrefixes
const hasSetAlternativePrefixes = (Array.isArray(config.autoAlternativeLangPrefixes) && config.autoAlternativeLangPrefixes.length) || Object.keys(config.autoAlternativeLangPrefixes || {}).length
const hasDisabledAutoI18n = typeof config.autoI18n === 'boolean' && !config.autoI18n
const hasSetAutoI18n = typeof config.autoI18n === 'object' && Object.keys(config.autoI18n).length
const hasI18nConfigForAlternatives = nuxtI18nConfig.strategy !== 'no_prefix' && nuxtI18nConfig.locales
if (!hasSetAutoI18n && !hasDisabledAutoI18n && !hasDisabledAlternativePrefixes && hasI18nConfigForAlternatives) {
Expand Down

0 comments on commit 7544c4a

Please sign in to comment.