#Access to astro.config.mjs schema

3 messages · Page 1 of 1 (latest)

river shaleBOT
#

Hi @analog gust. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The best way to access defaultLocale from your Astro config is to use the astro:config virtual module, introduced in Astro 5.7.0. The i18n configuration (including defaultLocale) is available from both the client and server submodules.

From server-side code (e.g., .astro components, API routes):

import { i18n } from "astro:config/server";

const defaultLocale = i18n?.defaultLocale; // "en"

From client-side code:

import { i18n } from "astro:config/client";

const defaultLocale = i18n?.defaultLocale; // "en"

This gives you a type-safe, serializable access to your Astro configuration values without needing to manually pass them around. [Config imports API]

Note: This feature requires [email protected] or later. If you're on an older version, you would need to manually import or pass the config value through your own utility/module.


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@analog gust Kapa.ai is still learning and improving, please let me know how I did by reacting below.