Skip to content

Commit

Permalink
i18nNotEnabled error
Browse files Browse the repository at this point in the history
  • Loading branch information
lilnasy committed Jan 23, 2024
1 parent 4abc42e commit 70d5a85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,19 @@ export const UnhandledRejection = {
hint: 'Make sure your promises all have an `await` or a `.catch()` handler.',
} satisfies ErrorData;

/**
* @docs
* @description
* Astro could not find any code to handle a rejected `Promise`. Make sure all your promises have an `await` or `.catch()` handler.
*/
export const i18nNotEnabled = {
name: 'i18nNotEnabled',
title: 'i18n Not Enabled',
message: "The `astro:i18n` module can not be used without enabling i18n in your Astro config.",
hint: 'See https://docs.astro.build/en/guides/internationalization for a guide on setting up i18n.',
} satisfies ErrorData;


/**
* @docs
* @kind heading
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/i18n/vite-plugin-i18n.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type * as vite from 'vite';
import type { AstroConfig, AstroSettings } from '../@types/astro.js';
import { AstroError } from '../core/errors/errors.js';
import { AstroErrorData } from '../core/errors/index.js';

const virtualModuleId = 'astro:i18n';
const configId = 'astro-internal:i18n-config';
Expand All @@ -20,7 +22,7 @@ export default function astroInternationalization({
enforce: 'pre',
async resolveId(id) {
if (id === virtualModuleId) {
if (i18n === undefined) throw new Error("The `astro:i18n` module can not be used without enabling i18n in your Astro config.");
if (i18n === undefined) throw new AstroError(AstroErrorData.i18nNotEnabled);
return this.resolve("astro/virtual-modules/i18n.js");
}
if (id === configId) return resolvedConfigId;
Expand Down

0 comments on commit 70d5a85

Please sign in to comment.