Skip to content

Commit

Permalink
chore: remove experimental from i18n configuration (#9264)
Browse files Browse the repository at this point in the history
* update types and schema

* update typescript files

* update tests

* chore: update JSDoc
  • Loading branch information
ematipico authored Dec 4, 2023
1 parent 2fdcd6d commit bd99078
Show file tree
Hide file tree
Showing 18 changed files with 360 additions and 410 deletions.
226 changes: 114 additions & 112 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1414,145 +1414,147 @@ export interface AstroUserConfig {
* Astro offers experimental flags to give users early access to new features.
* These flags are not guaranteed to be stable.
*/
experimental?: {

/**
* @docs
* @name i18n
* @type {object}
* @version 3.5.0
* @type {object}
* @description
*
* Configures experimental i18n routing and allows you to specify some customization options.
*
* See our guide for more information on [internationalization in Astro](/en/guides/internationalization/)
*/
i18n?: {
/**
* @docs
* @name experimental.optimizeHoistedScript
* @type {boolean}
* @default `false`
* @version 2.10.4
* @kind h4
* @name i18n.defaultLocale
* @type {string}
* @version 3.5.0
* @description
* Prevents unused components' scripts from being included in a page unexpectedly.
* The optimization is best-effort and may inversely miss including the used scripts. Make sure to double-check your built pages
* before publishing.
* Enable hoisted script analysis optimization by adding the experimental flag:
*
* ```js
* {
* experimental: {
* optimizeHoistedScript: true,
* },
* }
* ```
* The default locale of your website/application. This is a required field.
*
* No particular language format or syntax is enforced, but we suggest using lower-case and hyphens as needed (e.g. "es", "pt-br") for greatest compatibility.
*/
optimizeHoistedScript?: boolean;
defaultLocale: string;
/**
* @docs
* @kind h4
* @name i18n.locales
* @type {Locales}
* @version 3.5.0
* @description
*
* A list of all locales supported by the website, including the `defaultLocale`. This is a required field.
*
* Languages can be listed either as individual codes (e.g. `['en', 'es', 'pt-br']`) or mapped to a shared `path` of codes (e.g. `{ path: "english", codes: ["en", "en-US"]}`). These codes will be used to determine the URL structure of your deployed site.
*
* No particular language code format or syntax is enforced, but your project folders containing your content files must match exactly the `locales` items in the list. In the case of multiple `codes` pointing to a custom URL path prefix, store your content files in a folder with the same name as the `path` configured.
*/
locales: Locales;

/**
* @docs
* @name experimental.i18n
* @type {object}
* @kind h4
* @name i18n.fallback
* @type {Record<string, string>}
* @version 3.5.0
* @type {object}
* @description
*
* Configures experimental i18n routing and allows you to specify some customization options.
* The fallback strategy when navigating to pages that do not exist (e.g. a translated page has not been created).
*
* Use this object to declare a fallback `locale` route for each language you support. If no fallback is specified, then unavailable pages will return a 404.
*
* See our guide for more information on [internationalization in Astro](/en/guides/internationalization/)
* ##### Example
*
* The following example configures your content fallback strategy to redirect unavailable pages in `/pt-br/` to their `es` version, and unavailable pages in `/fr/` to their `en` version. Unavailable `/es/` pages will return a 404.
*
* ```js
* export default defineConfig({
* experimental: {
* i18n: {
* defaultLocale: "en",
* locales: ["en", "fr", "pt-br", "es"],
* fallback: {
* pt: "es",
* fr: "en"
* }
* }
* }
* })
* ```
*/
i18n?: {
/**
* @docs
* @kind h4
* @name experimental.i18n.defaultLocale
* @type {string}
* @version 3.5.0
* @description
*
* The default locale of your website/application. This is a required field.
*
* No particular language format or syntax is enforced, but we suggest using lower-case and hyphens as needed (e.g. "es", "pt-br") for greatest compatibility.
*/
defaultLocale: string;
/**
* @docs
* @kind h4
* @name experimental.i18n.locales
* @type {Locales}
* @version 3.5.0
* @description
*
* A list of all locales supported by the website, including the `defaultLocale`. This is a required field.
*
* Languages can be listed either as individual codes (e.g. `['en', 'es', 'pt-br']`) or mapped to a shared `path` of codes (e.g. `{ path: "english", codes: ["en", "en-US"]}`). These codes will be used to determine the URL structure of your deployed site.
*
* No particular language code format or syntax is enforced, but your project folders containing your content files must match exactly the `locales` items in the list. In the case of multiple `codes` pointing to a custom URL path prefix, store your content files in a folder with the same name as the `path` configured.
*/
locales: Locales;
fallback?: Record<string, string>;

/**
* @docs
* @kind h4
* @name i18n.routing
* @type {Routing}
* @version 3.7.0
* @description
*
* Controls the routing strategy to determine your site URLs. Set this based on your folder/URL path configuration for your default language.
*/
routing?: {
/**
* @docs
* @kind h4
* @name experimental.i18n.fallback
* @type {Record<string, string>}
* @version 3.5.0
* @name i18n.routing.prefixDefaultLocale
* @type {boolean}
* @default `false`
* @version 3.7.0
* @description
*
* The fallback strategy when navigating to pages that do not exist (e.g. a translated page has not been created).
*
* Use this object to declare a fallback `locale` route for each language you support. If no fallback is specified, then unavailable pages will return a 404.
* When `false`, only non-default languages will display a language prefix.
* The `defaultLocale` will not show a language prefix and content files do not exist in a localized folder.
* URLs will be of the form `example.com/[locale]/content/` for all non-default languages, but `example.com/content/` for the default locale.
*
* ##### Example
*
* The following example configures your content fallback strategy to redirect unavailable pages in `/pt-br/` to their `es` version, and unavailable pages in `/fr/` to their `en` version. Unavailable `/es/` pages will return a 404.
*
* ```js
* export default defineConfig({
* experimental: {
* i18n: {
* defaultLocale: "en",
* locales: ["en", "fr", "pt-br", "es"],
* fallback: {
* pt: "es",
* fr: "en"
* }
* }
* }
* })
* ```
* When `true`, all URLs will display a language prefix.
* URLs will be of the form `example.com/[locale]/content/` for every route, including the default language.
* Localized folders are used for every language, including the default.
*/
fallback?: Record<string, string>;
prefixDefaultLocale: boolean;

/**
* @docs
* @kind h4
* @name experimental.i18n.routing
* @type {Routing}
* @name i18n.routing.strategy
* @type {"pathname"}
* @default `"pathname"`
* @version 3.7.0
* @description
*
* Controls the routing strategy to determine your site URLs. Set this based on your folder/URL path configuration for your default language.
* - `"pathanme": The strategy is applied to the pathname of the URLs
*/
routing?: {
/**
* @docs
* @name experimental.i18n.routing.prefixDefaultLocale
* @type {boolean}
* @default `false`
* @version 3.7.0
* @description
*
* When `false`, only non-default languages will display a language prefix.
* The `defaultLocale` will not show a language prefix and content files do not exist in a localized folder.
* URLs will be of the form `example.com/[locale]/content/` for all non-default languages, but `example.com/content/` for the default locale.
*
* When `true`, all URLs will display a language prefix.
* URLs will be of the form `example.com/[locale]/content/` for every route, including the default language.
* Localized folders are used for every language, including the default.
*/
prefixDefaultLocale: boolean;

/**
* @name experimental.i18n.routing.strategy
* @type {"pathname"}
* @default `"pathname"`
* @version 3.7.0
* @description
*
* - `"pathanme": The strategy is applied to the pathname of the URLs
*/
strategy: 'pathname';
};
strategy: 'pathname';
};
};

experimental?: {
/**
* @docs
* @name experimental.optimizeHoistedScript
* @type {boolean}
* @default `false`
* @version 2.10.4
* @description
* Prevents unused components' scripts from being included in a page unexpectedly.
* The optimization is best-effort and may inversely miss including the used scripts. Make sure to double-check your built pages
* before publishing.
* Enable hoisted script analysis optimization by adding the experimental flag:
*
* ```js
* {
* experimental: {
* optimizeHoistedScript: true,
* },
* }
* ```
*/
optimizeHoistedScript?: boolean;

/**
* @docs
* @name experimental.contentCollectionCache
Expand Down
14 changes: 7 additions & 7 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ async function generatePage(
pipeline.getManifest().base,
pipeline.getManifest().trailingSlash
);
if (config.experimental.i18n && i18nMiddleware) {
if (config.i18n && i18nMiddleware) {
if (onRequest) {
pipeline.setMiddlewareFunction(sequence(i18nMiddleware, onRequest));
} else {
Expand Down Expand Up @@ -546,7 +546,7 @@ async function generatePath(
logger: pipeline.getLogger(),
ssr,
});
const i18n = pipeline.getConfig().experimental.i18n;
const i18n = pipeline.getConfig().i18n;

const renderContext = await createRenderContext({
pathname,
Expand Down Expand Up @@ -629,12 +629,12 @@ export function createBuildManifest(
renderers: SSRLoadedRenderer[]
): SSRManifest {
let i18nManifest: SSRManifestI18n | undefined = undefined;
if (settings.config.experimental.i18n) {
if (settings.config.i18n) {
i18nManifest = {
fallback: settings.config.experimental.i18n.fallback,
routing: settings.config.experimental.i18n.routing,
defaultLocale: settings.config.experimental.i18n.defaultLocale,
locales: settings.config.experimental.i18n.locales,
fallback: settings.config.i18n.fallback,
routing: settings.config.i18n.routing,
defaultLocale: settings.config.i18n.defaultLocale,
locales: settings.config.i18n.locales,
};
}
return {
Expand Down
10 changes: 5 additions & 5 deletions packages/astro/src/core/build/plugins/plugin-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ function buildManifest(
entryModules[BEFORE_HYDRATION_SCRIPT_ID] = '';
}
let i18nManifest: SSRManifestI18n | undefined = undefined;
if (settings.config.experimental.i18n) {
if (settings.config.i18n) {
i18nManifest = {
fallback: settings.config.experimental.i18n.fallback,
routing: settings.config.experimental.i18n.routing,
locales: settings.config.experimental.i18n.locales,
defaultLocale: settings.config.experimental.i18n.defaultLocale,
fallback: settings.config.i18n.fallback,
routing: settings.config.i18n.routing,
locales: settings.config.i18n.locales,
defaultLocale: settings.config.i18n.defaultLocale,
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export function shouldAppendForwardSlash(
}

export function i18nHasFallback(config: AstroConfig): boolean {
if (config.experimental.i18n && config.experimental.i18n.fallback) {
if (config.i18n && config.i18n.fallback) {
// we have some fallback and the control is not none
return Object.keys(config.experimental.i18n.fallback).length > 0;
return Object.keys(config.i18n.fallback).length > 0;
}

return false;
Expand Down
Loading

0 comments on commit bd99078

Please sign in to comment.