Skip to content

Commit

Permalink
fix: fixed ouptut when using nuxtjs/i18n without options #87
Browse files Browse the repository at this point in the history
  • Loading branch information
victorgarciaesgi committed Apr 22, 2023
1 parent dd4142d commit 21cb5ff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
34 changes: 17 additions & 17 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ export default defineNuxtConfig({
experimentalRemoveNuxtDefs: true,
},
srcDir: './src',
i18n: {
locales: ['en', 'fr-FR'],
defaultLocale: 'en',
strategy: 'no_prefix',
vueI18n: {
legacy: false,
locale: 'en',
messages: {
en: {
welcome: 'Welcome',
},
fr: {
welcome: 'Bienvenue',
},
},
},
},
// i18n: {
// locales: ['en', 'fr-FR'],
// defaultLocale: 'en',
// strategy: 'no_prefix',
// vueI18n: {
// legacy: false,
// locale: 'en',
// messages: {
// en: {
// welcome: 'Welcome',
// },
// fr: {
// welcome: 'Bienvenue',
// },
// },
// },
// },
});
1 change: 1 addition & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function createTypedRouter({

// We use extendPages here to access the NuxtPage, not accessible in the `pages:extend` hook
extendPages(async (routes: NuxtPage[]) => {
// console.log(JSON.stringify(routes));
hasRoutesDefined = true;
const outputData = constructRouteMap(routes);

Expand Down
4 changes: 2 additions & 2 deletions src/core/parser/i18n.modifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function is18Sibling(
route: NuxtPage
) {
const { i18n, i18nOptions, i18nLocales } = moduleOptionStore;
if (i18n && i18nOptions?.strategy !== 'no_prefix') {
if (i18n && i18nOptions && i18nOptions?.strategy !== 'no_prefix') {
const separator = i18nOptions?.routesNameSeparator ?? '___';

const i18LocalesRecognizer = i18nLocales
Expand Down Expand Up @@ -43,7 +43,7 @@ export function is18Sibling(

export function modifyRoutePrefixDefaultIfI18n(route: NuxtPage) {
const { i18n, i18nOptions, i18nLocales } = moduleOptionStore;
if (i18n && route.name) {
if (i18n && i18nOptions && route.name) {
const separator = i18nOptions?.routesNameSeparator ?? '___';
const i18LocalesRecognizer = i18nLocales
?.map((m) => m.replace(specialCharacterRegxp, '\\$&'))
Expand Down

1 comment on commit 21cb5ff

@vercel
Copy link

@vercel vercel bot commented on 21cb5ff Apr 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.