-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
415 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,9 @@ | ||
import { | ||
RoutingBaseConfigInput, | ||
receiveLocalePrefixConfig | ||
} from '../routing/config'; | ||
import {Locales, LocalePrefixConfigVerbose, Pathnames} from '../routing/types'; | ||
|
||
export type MiddlewareRoutingConfigInput< | ||
AppLocales extends Locales, | ||
AppPathnames extends Pathnames<AppLocales> | ||
> = RoutingBaseConfigInput<AppLocales> & { | ||
locales: AppLocales; | ||
defaultLocale: AppLocales[number]; | ||
|
||
export type MiddlewareOptions = { | ||
/** Sets the `Link` response header to notify search engines about content in other languages (defaults to `true`). See https://developers.google.com/search/docs/specialty/international/localized-versions#http */ | ||
alternateLinks?: boolean; | ||
|
||
/** By setting this to `false`, the cookie as well as the `accept-language` header will no longer be used for locale detection. */ | ||
localeDetection?: boolean; | ||
|
||
/** Maps internal pathnames to external ones which can be localized per locale. */ | ||
pathnames?: AppPathnames; | ||
}; | ||
|
||
export type MiddlewareRoutingConfig< | ||
AppLocales extends Locales, | ||
AppPathnames extends Pathnames<AppLocales> | ||
> = Omit< | ||
MiddlewareRoutingConfigInput<AppLocales, AppPathnames>, | ||
'alternateLinks' | 'localeDetection' | 'localePrefix' | ||
> & { | ||
alternateLinks: boolean; | ||
localeDetection: boolean; | ||
localePrefix: LocalePrefixConfigVerbose<AppLocales>; | ||
}; | ||
|
||
export function receiveConfig< | ||
AppLocales extends Locales, | ||
AppPathnames extends Pathnames<AppLocales> | ||
>( | ||
input: MiddlewareRoutingConfigInput<AppLocales, AppPathnames> | ||
): MiddlewareRoutingConfig<AppLocales, AppPathnames> { | ||
return { | ||
...input, | ||
alternateLinks: input?.alternateLinks ?? true, | ||
localeDetection: input?.localeDetection ?? true, | ||
localePrefix: receiveLocalePrefixConfig(input?.localePrefix) | ||
}; | ||
} | ||
export type ResolvedMiddlewareOptions = Required<MiddlewareOptions>; |
Oops, something went wrong.