Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: i18n
  • Loading branch information
florian-lefebvre committed Jan 6, 2026
commit 1f1be79b21e4119c60a7f1bdc29a95b0e593acf2
2 changes: 2 additions & 0 deletions packages/astro/src/core/sync/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export function syncInternals({ settings, routes }: Options) {
export type RoutePattern = (${JSON.stringify(routes.map((r) => r.route))})[number];
export type Site = ${getCondition(!!settings.config.site)};
export type Session = ${getCondition(!!settings.config.session?.driver)};
export type I18n = ${getCondition(!!settings.config.i18n)};
${settings.config.i18n ? `export type I18nLocale = (${JSON.stringify(settings.config.i18n.locales)})[number];` : ''}
}`,
});
}
12 changes: 6 additions & 6 deletions packages/astro/src/types/public/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,18 +349,18 @@ export interface AstroSharedContext<
/**
* The current locale that is computed from the `Accept-Language` header of the browser (**SSR Only**).
*/
preferredLocale: string | undefined;
preferredLocale: ConditionalType<AstroInternals.I18nLocale, AstroInternals.I18n> | undefined;

/**
* The list of locales computed from the `Accept-Language` header of the browser, sorted by quality value (**SSR Only**).
*/

preferredLocaleList: string[] | undefined;
preferredLocaleList: ConditionalType<Array<AstroInternals.I18nLocale>, AstroInternals.I18n>;

/**
* The current locale computed from the URL of the request. It matches the locales in `i18n.locales`, and returns `undefined` otherwise.
*/
currentLocale: string | undefined;
currentLocale: ConditionalType<AstroInternals.I18nLocale, AstroInternals.I18n>;

/**
* Whether the current route is prerendered or not.
Expand Down Expand Up @@ -577,7 +577,7 @@ export interface APIContext<
*
* [quality value]: https://developer.mozilla.org/en-US/docs/Glossary/Quality_values
*/
preferredLocale: string | undefined;
preferredLocale: ConditionalType<AstroInternals.I18nLocale, AstroInternals.I18n> | undefined;

/**
* Available only when `i18n` configured and in SSR.
Expand All @@ -592,12 +592,12 @@ export interface APIContext<
*
* [quality value]: https://developer.mozilla.org/en-US/docs/Glossary/Quality_values
*/
preferredLocaleList: string[] | undefined;
preferredLocaleList: ConditionalType<Array<AstroInternals.I18nLocale>, AstroInternals.I18n>;

/**
* The current locale computed from the URL of the request. It matches the locales in `i18n.locales`, and returns `undefined` otherwise.
*/
currentLocale: string | undefined;
currentLocale: ConditionalType<AstroInternals.I18nLocale, AstroInternals.I18n>;

/**
* The route currently rendered. It's stripped of the `srcDir` and the `pages` folder, and it doesn't contain the extension.
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/src/types/public/extendables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ declare global {
export type RoutePattern = string;
export type Site = 'maybe';
export type Session = 'maybe';
export type I18n = 'maybe';
export type I18nLocale = string;
}
}

Expand Down
Loading