Skip to content

Commit

Permalink
refactor: merge I18nRoutingOptions with NuxtI18nOptions (#2724)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede authored Jan 22, 2024
1 parent 489f13d commit c9bdcd7
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 231 deletions.
3 changes: 1 addition & 2 deletions src/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { resolve, parse as parsePath } from 'pathe'
import { NUXT_I18N_COMPOSABLE_DEFINE_ROUTE } from './constants'

import type { Nuxt, NuxtPage } from '@nuxt/schema'
import type { NuxtI18nOptions, CustomRoutePages } from './types'
import type { ComputedRouteOptions, RouteOptionsResolver } from './routing'
import type { NuxtI18nOptions, CustomRoutePages, ComputedRouteOptions, RouteOptionsResolver } from './types'
import type { Node, ObjectExpression, ArrayExpression } from '@babel/types'

const debug = createDebug('@nuxtjs/i18n:pages')
Expand Down
32 changes: 1 addition & 31 deletions src/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getNormalizedLocales } from './utils'
import type { Locale } from 'vue-i18n'
import type { NuxtPage } from '@nuxt/schema'
import type { MarkRequired, MarkOptional } from 'ts-essentials'
import type { NuxtI18nOptions } from './types'
import type { NuxtI18nOptions, PrefixLocalizedRouteOptions, RouteOptionsResolver } from './types'

const join = (...args: (string | undefined)[]) => args.filter(Boolean).join('')

Expand All @@ -20,36 +20,6 @@ export declare interface ComputedRouteOptions {
paths: Record<string, string>
}

/**
* Resolver for route localizing options
*
* @public
*/
export declare type RouteOptionsResolver = (route: NuxtPage, localeCodes: string[]) => ComputedRouteOptions | undefined

/**
* Localize route path prefix judgment options used in {@link LocalizeRoutesPrefixable}
*
* @public
*/
export interface PrefixLocalizedRouteOptions {
/**
* Current locale
*/
locale: Locale
/**
* Default locale
*/
defaultLocale?: Locale | undefined
/**
* The parent route of the route to be resolved
*/
parent: NuxtPage | undefined
/**
* The path of route
*/
path: string
}
export function prefixLocalizedRoute(
localizeOptions: PrefixLocalizedRouteOptions,
options: LocalizeRoutesParams,
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/routing/extends/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type {
VueI18n,
VueI18nExtender
} from 'vue-i18n'
import type { I18nRoutingOptions, LocaleObject } from '#build/i18n.options.mjs'
import type { LocaleObject, NuxtI18nOptions } from '#build/i18n.options.mjs'

/**
* An options of Vue I18n Routing Plugin
Expand Down Expand Up @@ -57,7 +57,7 @@ export interface ExtendHooks {
onExtendVueI18n?: ExtendVueI18nHook
}

export type VueI18nExtendOptions<Context = unknown> = Pick<I18nRoutingOptions<Context>, 'baseUrl'> & {
export type VueI18nExtendOptions<Context = unknown> = Pick<NuxtI18nOptions<Context>, 'baseUrl'> & {
locales?: string[] | LocaleObject[]
localeCodes?: string[]
context?: Context
Expand Down
Loading

0 comments on commit c9bdcd7

Please sign in to comment.