@@ -9,8 +9,6 @@ import type { MiddlewareHandler } from '../types/public/common.js';
99import type { AstroConfig , ValidRedirectStatus } from '../types/public/config.js' ;
1010import type { APIContext } from '../types/public/context.js' ;
1111
12- export { normalizeTheLocale , toCodes , toPaths } from '../i18n/index.js' ;
13-
1412const { trailingSlash, format, site, i18n, isBuild } =
1513 // @ts -expect-error
1614 __ASTRO_INTERNAL_I18N_CONFIG__ as I18nInternalConfig ;
@@ -236,9 +234,9 @@ export const getLocaleByPath = (path: string) => I18nInternals.getLocaleByPath(p
236234 *
237235 * ```js
238236 * import { pathHasLocale } from "astro:i18n";
239- * getLocaleByPath ("italiano"); // returns `true`
240- * getLocaleByPath ("es"); // returns `true`
241- * getLocaleByPath ("it-VT"); // returns `false`
237+ * pathHasLocale ("italiano"); // returns `true`
238+ * pathHasLocale ("es"); // returns `true`
239+ * pathHasLocale ("it-VT"); // returns `false`
242240 * ```
243241 */
244242export const pathHasLocale = ( path : string ) => I18nInternals . pathHasLocale ( path , locales ) ;
@@ -388,3 +386,88 @@ if (i18n?.routing === 'manual') {
388386} else {
389387 middleware = noop ( 'middleware' ) ;
390388}
389+
390+ /**
391+ * Replaces underscores (`_`) with hyphens (`-`) in the given locale before
392+ * returning a lowercase version.
393+ *
394+ * @param {string } locale A locale code to normalize.
395+ * @returns {string } The normalized locale.
396+ *
397+ * ## Example
398+ *
399+ * ```js
400+ * import { normalizeTheLocale } from "astro:i18n";
401+ * normalizeTheLocale("it_VT") // returns `it-vt`
402+ * ```
403+ */
404+ export const normalizeTheLocale = I18nInternals . normalizeTheLocale ;
405+
406+ /**
407+ * Retrieves the configured locale codes for each locale defined in your
408+ * configuration. When multiple codes are associated to a locale, only the
409+ * first one will be added to the array.
410+ *
411+ * @param {Locales } locales The configured locales.
412+ * @returns {string[] } The configured locales codes.
413+ *
414+ * ## Example
415+ *
416+ * Given the following configuration:
417+ *
418+ * ```js
419+ * // astro.config.mjs
420+ *
421+ * export default defineConfig({
422+ * i18n: {
423+ * locales: [
424+ * { codes: ["it-VT", "it"], path: "italiano" },
425+ * "es"
426+ * ]
427+ * }
428+ * })
429+ * ```
430+ *
431+ * Here's a use case:
432+ *
433+ * ```js
434+ * import { i18n } from "astro:config/client";
435+ * import { toCodes } from "astro:i18n";
436+ * toCodes(i18n.locales); // ["it-VT", "es"]
437+ * ```
438+ */
439+ export const toCodes = I18nInternals . toCodes ;
440+
441+ /**
442+ * Retrieves the configured locale paths for each locale defined in your
443+ * configuration.
444+ *
445+ * @param {Locales } locales The configured locales.
446+ * @returns {string[] } The configured locales paths.
447+ *
448+ * ## Example
449+ *
450+ * Given the following configuration:
451+ *
452+ * ```js
453+ * // astro.config.mjs
454+ *
455+ * export default defineConfig({
456+ * i18n: {
457+ * locales: [
458+ * { codes: ["it-VT", "it"], path: "italiano" },
459+ * "es"
460+ * ]
461+ * }
462+ * })
463+ * ```
464+ *
465+ * Here's a use case:
466+ *
467+ * ```js
468+ * import { i18n } from "astro:config/client";
469+ * import { toPaths } from "astro:i18n";
470+ * toPaths(i18n.locales); // ["italiano", "es"]
471+ * ```
472+ */
473+ export const toPaths = I18nInternals . toPaths ;
0 commit comments