@mcendon/astro-translate 1.0.0-RC1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/LICENSE.md +13 -0
  2. package/README.md +268 -0
  3. package/dist/astro/internal-helpers/path.d.ts +2 -0
  4. package/dist/astro/internal-helpers/path.d.ts.map +1 -0
  5. package/dist/edge-runtime/config.d.ts +10 -0
  6. package/dist/edge-runtime/config.d.ts.map +1 -0
  7. package/dist/edge-runtime/filterCollectionByDefaultLocale.d.ts +2 -0
  8. package/dist/edge-runtime/filterCollectionByDefaultLocale.d.ts.map +1 -0
  9. package/dist/edge-runtime/getAllLocaleUrls.d.ts +13 -0
  10. package/dist/edge-runtime/getAllLocaleUrls.d.ts.map +1 -0
  11. package/dist/edge-runtime/getCollectionParamsSlug.d.ts +6 -0
  12. package/dist/edge-runtime/getCollectionParamsSlug.d.ts.map +1 -0
  13. package/dist/edge-runtime/getLocale.d.ts +13 -0
  14. package/dist/edge-runtime/getLocale.d.ts.map +1 -0
  15. package/dist/edge-runtime/getLocaleUrl.d.ts +32 -0
  16. package/dist/edge-runtime/getLocaleUrl.d.ts.map +1 -0
  17. package/dist/edge-runtime/getLocaleUrlPrefix.d.ts +13 -0
  18. package/dist/edge-runtime/getLocaleUrlPrefix.d.ts.map +1 -0
  19. package/dist/edge-runtime/getTranslateHelper.d.ts +8 -0
  20. package/dist/edge-runtime/getTranslateHelper.d.ts.map +1 -0
  21. package/dist/edge-runtime/getUrlWithoutLocale.d.ts +5 -0
  22. package/dist/edge-runtime/getUrlWithoutLocale.d.ts.map +1 -0
  23. package/dist/edge-runtime/index.cjs +2 -0
  24. package/dist/edge-runtime/index.cjs.map +1 -0
  25. package/dist/edge-runtime/index.d.ts +13 -0
  26. package/dist/edge-runtime/index.d.ts.map +1 -0
  27. package/dist/edge-runtime/index.js +2 -0
  28. package/dist/edge-runtime/index.js.map +1 -0
  29. package/dist/edge-runtime/middleware.d.ts +2 -0
  30. package/dist/edge-runtime/middleware.d.ts.map +1 -0
  31. package/dist/edge-runtime/removeHtmlExtension.d.ts +2 -0
  32. package/dist/edge-runtime/removeHtmlExtension.d.ts.map +1 -0
  33. package/dist/edge-runtime/removeTrailingSlash.d.ts +2 -0
  34. package/dist/edge-runtime/removeTrailingSlash.d.ts.map +1 -0
  35. package/dist/edge-runtime/resolveTrailingSlash.d.ts +2 -0
  36. package/dist/edge-runtime/resolveTrailingSlash.d.ts.map +1 -0
  37. package/dist/integration/ensureValidConfigs/createVirtualModules.d.ts +5 -0
  38. package/dist/integration/ensureValidConfigs/createVirtualModules.d.ts.map +1 -0
  39. package/dist/integration/ensureValidConfigs/createVirtualPlugin.d.ts +3 -0
  40. package/dist/integration/ensureValidConfigs/createVirtualPlugin.d.ts.map +1 -0
  41. package/dist/integration/ensureValidConfigs/ensureValidConfigs.d.ts +5 -0
  42. package/dist/integration/ensureValidConfigs/ensureValidConfigs.d.ts.map +1 -0
  43. package/dist/integration/ensureValidConfigs/ensureValidTrailingSlashAndFormat.d.ts +4 -0
  44. package/dist/integration/ensureValidConfigs/ensureValidTrailingSlashAndFormat.d.ts.map +1 -0
  45. package/dist/integration/ensureValidConfigs/index.d.ts +2 -0
  46. package/dist/integration/ensureValidConfigs/index.d.ts.map +1 -0
  47. package/dist/integration/index.cjs +2 -0
  48. package/dist/integration/index.cjs.map +1 -0
  49. package/dist/integration/index.d.ts +5 -0
  50. package/dist/integration/index.d.ts.map +1 -0
  51. package/dist/integration/index.js +2 -0
  52. package/dist/integration/index.js.map +1 -0
  53. package/dist/integration/integration.d.ts +9 -0
  54. package/dist/integration/integration.d.ts.map +1 -0
  55. package/dist/middleware/index.cjs +2 -0
  56. package/dist/middleware/index.cjs.map +1 -0
  57. package/dist/middleware/index.d.ts +2 -0
  58. package/dist/middleware/index.d.ts.map +1 -0
  59. package/dist/middleware/index.js +2 -0
  60. package/dist/middleware/index.js.map +1 -0
  61. package/dist/shared/configs.d.ts +68 -0
  62. package/dist/shared/configs.d.ts.map +1 -0
  63. package/dist/shared/filterSitemapByDefaultLocale.d.ts +3 -0
  64. package/dist/shared/filterSitemapByDefaultLocale.d.ts.map +1 -0
  65. package/dist/shared/index.d.ts +4 -0
  66. package/dist/shared/index.d.ts.map +1 -0
  67. package/package.json +98 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/edge-runtime/config.ts","../../src/edge-runtime/filterCollectionByDefaultLocale.ts","../../src/edge-runtime/getCollectionParamsSlug.ts","../../src/edge-runtime/resolveTrailingSlash.ts","../../src/edge-runtime/removeTrailingSlash.ts","../../src/edge-runtime/removeHtmlExtension.ts","../../src/edge-runtime/getAllLocaleUrls.ts","../../src/edge-runtime/getLocale.ts","../../src/edge-runtime/getLocaleUrl.ts","../../src/edge-runtime/getLocaleUrlPrefix.ts","../../src/edge-runtime/getUrlWithoutLocale.ts","../../src/edge-runtime/getTranslateHelper.ts","../../src/shared/configs.ts"],"sourcesContent":["import virtualConfig from 'virtual:@mcendon/astro-translate'\n\nexport const trailingSlash = virtualConfig.trailingSlash\nexport const BASE_URL = virtualConfig.BASE_URL ? virtualConfig.BASE_URL : '/'\nexport const defaultLocale = virtualConfig.defaultLocale\nexport const locales = virtualConfig.locales\nexport const localeKeys = Object.keys(virtualConfig.locales)\nexport const redirectDefaultLocale = virtualConfig.redirectDefaultLocale\nexport const build = virtualConfig.build\n","import { defaultLocale } from './config'\n\nexport function filterCollectionByDefaultLocale(entry: unknown) {\n if (\n typeof entry === 'object' &&\n entry !== null &&\n 'slug' in entry &&\n typeof entry.slug === 'string'\n ) {\n if (entry.slug.startsWith(defaultLocale + '/')) {\n return true\n }\n }\n return false\n}\n","import { defaultLocale } from './config'\n\nexport function getCollectionParamsSlug(entries: unknown[]) {\n return entries.reduce<{ params: { slug: string } }[]>(\n (accumulator, entry) => {\n if (\n typeof entry === 'object' &&\n entry !== null &&\n 'slug' in entry &&\n typeof entry.slug === 'string'\n ) {\n accumulator.push({\n params: { slug: entry.slug.replace(defaultLocale + '/', '') },\n })\n }\n return accumulator\n },\n []\n )\n}\n","import { trailingSlash } from './config'\n\nexport function resolveTrailingSlash(url: URL | string): string {\n let pathName = typeof url === 'string' ? url : url.pathname\n\n if (trailingSlash === 'always') {\n if (pathName.at(-1) !== '/') {\n pathName = pathName + '/'\n }\n } else if (trailingSlash === 'never') {\n if (pathName !== '/' && pathName.at(-1) === '/') {\n pathName = pathName.slice(0, -1)\n }\n }\n return pathName\n}\n","export function removeTrailingSlash(url: string) {\n return url.at(-1) === '/' ? url.slice(0, -1) : url\n}\n","export function removeHtmlExtension(url: string) {\n return url.endsWith('.html') ? url.slice(0, -'.html'.length) : url\n}\n","import {\n // astro `BASE_URL` always starts with `/` and respects `config.trailingSlash`\n BASE_URL as baseUrl,\n defaultLocale,\n localeKeys,\n} from './config'\nimport { resolveTrailingSlash } from './resolveTrailingSlash'\nimport { removeTrailingSlash } from './removeTrailingSlash'\nimport { removeHtmlExtension } from './removeHtmlExtension'\n/**\n * @returns url with chosen locale prefix\n * * @example\n * ```ts\n * getAllLocaleUrls(\"/es/about\") // { en: \"/about\", \"es\": \"/es/about\" }\n * ```\n * @example\n * ```ts\n * getAllLocaleUrls(\"/about\") // { en: \"/about\", \"es\": \"/es/about\" }\n * ```\n */\nexport function getAllLocaleUrls(url: URL | string): Record<string, string> {\n // support both string and url objects\n const pathName = typeof url === 'string' ? url : url.pathname\n const pathNameWithoutHtmlExtension = removeHtmlExtension(pathName)\n\n const baseUrlWithoutTrailingSlash = removeTrailingSlash(baseUrl)\n\n // remove baseUrlWithoutTrailingSlash from pathNameWithoutBaseUrl\n const pathNameWithoutBaseUrl =\n baseUrl === '/'\n ? pathNameWithoutHtmlExtension\n : pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash, '')\n\n const possibleLocaleKey = pathNameWithoutBaseUrl.slice(1, 3)\n const pathNameWithoutBaseUrlStartsWithLocale = localeKeys\n .filter((key) => key !== defaultLocale)\n .includes(possibleLocaleKey)\n\n // avoid catching original urls that start with \"/en\" like \"/enigma\"\n if (\n pathNameWithoutBaseUrl.length === 3 &&\n pathNameWithoutBaseUrlStartsWithLocale\n ) {\n return {\n ...localeKeys.reduce<Record<string, string>>((record, locale) => {\n record[locale] = resolveTrailingSlash(\n baseUrlWithoutTrailingSlash + '/' + locale + '/'\n )\n return record\n }, {}),\n [defaultLocale]: resolveTrailingSlash(baseUrl),\n }\n }\n if (\n pathNameWithoutBaseUrl[0] === '/' &&\n pathNameWithoutBaseUrl[3] === '/' &&\n pathNameWithoutBaseUrlStartsWithLocale\n ) {\n // catch all \"/fr/**/*\" original urls\n return {\n ...localeKeys.reduce<Record<string, string>>((record, locale) => {\n record[locale] = resolveTrailingSlash(\n baseUrlWithoutTrailingSlash +\n '/' +\n locale +\n pathNameWithoutBaseUrl.slice(3)\n )\n return record\n }, {}),\n [defaultLocale]: resolveTrailingSlash(\n baseUrlWithoutTrailingSlash + pathNameWithoutBaseUrl.slice(3)\n ),\n }\n }\n\n // otherwise, original url must be a defaultLocale or other url\n return {\n ...localeKeys.reduce<Record<string, string>>((record, locale) => {\n record[locale] = resolveTrailingSlash(\n baseUrlWithoutTrailingSlash + '/' + locale + pathNameWithoutBaseUrl\n )\n return record\n }, {}),\n [defaultLocale]: resolveTrailingSlash(\n baseUrlWithoutTrailingSlash + pathNameWithoutBaseUrl\n ),\n }\n}\n","import {\n // astro `BASE_URL` always starts with `/` and respects `config.trailingSlash`\n BASE_URL as baseUrl,\n defaultLocale,\n localeKeys,\n} from './config'\nimport { removeHtmlExtension } from './removeHtmlExtension'\nimport { removeTrailingSlash } from './removeTrailingSlash'\n\n/**\n * @returns locale key\n * @example\n * ```ts\n * getLocale(\"/es/about\") // \"es\"\n * ```\n * @example\n * ```ts\n * getLocale(\"/about\") // \"en\"\n * ```\n */\nexport function getLocale(url: URL | string): string {\n // support both string and url objects\n const pathName = typeof url === 'string' ? url : url.pathname\n const pathNameWithoutHtmlExtension = removeHtmlExtension(pathName)\n // astro `BASE_URL` always starts with `/` and respects `config.trailingSlash`\n\n const baseUrlWithoutTrailingSlash = removeTrailingSlash(baseUrl)\n\n // remove baseUrlWithoutTrailingSlash from pathNameWithoutBaseUrl\n const pathNameWithoutBaseUrl =\n baseUrl === '/'\n ? pathNameWithoutHtmlExtension\n : pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash, '')\n\n const possibleLocaleKey = pathNameWithoutBaseUrl.slice(1, 3)\n const pathNameWithoutBaseUrlStartsWithLocale = localeKeys\n .filter((key) => key !== defaultLocale)\n .includes(possibleLocaleKey)\n\n // avoid catching urls that start with \"/en\" like \"/enigma\"\n if (\n pathNameWithoutBaseUrl.length === 3 &&\n pathNameWithoutBaseUrlStartsWithLocale\n ) {\n return possibleLocaleKey\n }\n if (\n pathNameWithoutBaseUrl[0] === '/' &&\n pathNameWithoutBaseUrl[3] === '/' &&\n pathNameWithoutBaseUrlStartsWithLocale\n ) {\n // catch all \"/fr/**/*\" urls\n return possibleLocaleKey\n }\n // otherwise, it must be a defaultLocale or other url\n return defaultLocale\n}\n","import {\n // astro `BASE_URL` always starts with `/` and respects `config.trailingSlash`\n BASE_URL as baseUrl,\n defaultLocale,\n localeKeys,\n} from './config'\nimport { resolveTrailingSlash } from './resolveTrailingSlash'\nimport { removeTrailingSlash } from './removeTrailingSlash'\nimport { removeHtmlExtension } from './removeHtmlExtension'\n/**\n * @returns url with chosen locale prefix\n * * @example\n * ```ts\n * getLocaleUrl(\"/es/about\", \"en\") // \"/about\"\n * ```\n * * @example\n * ```ts\n * getLocaleUrl(\"/es/about\", \"fr\") // \"/fr/about\"\n * ```\n * @example\n * ```ts\n * getLocaleUrl(\"/about\", \"es\") // \"/es/about\"\n * ```\n */\n/**\n * @returns url with chosen locale prefix\n * * @example\n * ```ts\n * getLocaleUrl(\"/es/about\", \"en\") // \"/about\"\n * ```\n * * @example\n * ```ts\n * getLocaleUrl(\"/es/about\", \"fr\") // \"/fr/about\"\n * ```\n * @example\n * ```ts\n * getLocaleUrl(\"/about\", \"es\") // \"/es/about\"\n * ```\n */\nexport function getLocaleUrl(url: URL | string, locale: string): string {\n // support both string and url objects\n const pathName = typeof url === 'string' ? url : url.pathname\n const pathNameWithoutHtmlExtension = removeHtmlExtension(pathName)\n\n const baseUrlWithoutTrailingSlash = removeTrailingSlash(baseUrl)\n\n // remove baseUrlWithoutTrailingSlash from pathNameWithoutBaseUrl\n const pathNameWithoutBaseUrl =\n baseUrl === '/'\n ? pathNameWithoutHtmlExtension\n : pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash, '')\n\n const possibleLocaleKey = pathNameWithoutBaseUrl.slice(1, 3)\n const pathNameWithoutBaseUrlStartsWithLocale = localeKeys\n .filter((key) => key !== defaultLocale)\n .includes(possibleLocaleKey)\n\n // avoid catching original urls that start with \"/en\" like \"/enigma\"\n if (\n pathNameWithoutBaseUrl.length === 3 &&\n pathNameWithoutBaseUrlStartsWithLocale\n ) {\n if (locale === defaultLocale) {\n return resolveTrailingSlash(baseUrl)\n }\n\n return resolveTrailingSlash(\n baseUrlWithoutTrailingSlash + '/' + locale + '/'\n )\n }\n if (\n pathNameWithoutBaseUrl[0] === '/' &&\n pathNameWithoutBaseUrl[3] === '/' &&\n pathNameWithoutBaseUrlStartsWithLocale\n ) {\n // catch all \"/fr/**/*\" original urls\n if (locale === defaultLocale) {\n return resolveTrailingSlash(\n baseUrlWithoutTrailingSlash + pathNameWithoutBaseUrl.slice(3)\n )\n }\n return resolveTrailingSlash(\n baseUrlWithoutTrailingSlash +\n '/' +\n locale +\n pathNameWithoutBaseUrl.slice(3)\n )\n }\n // otherwise, original url must be a defaultLocale or other url\n if (locale === defaultLocale) {\n return resolveTrailingSlash(\n baseUrlWithoutTrailingSlash + pathNameWithoutBaseUrl\n )\n }\n return resolveTrailingSlash(\n baseUrlWithoutTrailingSlash + '/' + locale + pathNameWithoutBaseUrl\n )\n}\n","import {\n // astro `BASE_URL` always starts with `/` and respects `config.trailingSlash`\n BASE_URL as baseUrl,\n localeKeys,\n defaultLocale,\n} from './config'\nimport { removeHtmlExtension } from './removeHtmlExtension'\nimport { removeTrailingSlash } from './removeTrailingSlash'\n\n/**\n * @returns locale prefix or an empty string if defaultLocale\n * @example\n * ```ts\n * getLocaleUrlPrefix(\"/es/about\") // \"/es\"\n * ```\n * @example\n * ```ts\n * getLocale(\"/about\") // \"\"\n * ```\n */\nexport function getLocaleUrlPrefix(url: URL | string): string {\n // support both string and url objects\n const pathName = typeof url === 'string' ? url : url.pathname\n const pathNameWithoutHtmlExtension = removeHtmlExtension(pathName)\n\n const baseUrlWithoutTrailingSlash = removeTrailingSlash(baseUrl)\n\n // remove baseUrlWithoutTrailingSlash from pathNameWithoutBaseUrl\n const pathNameWithoutBaseUrl =\n baseUrl === '/'\n ? pathNameWithoutHtmlExtension\n : pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash, '')\n\n const possibleLocaleKey = pathNameWithoutBaseUrl.slice(1, 3)\n const pathNameWithoutBaseUrlStartsWithLocale = localeKeys\n .filter((key) => key !== defaultLocale)\n .includes(possibleLocaleKey)\n\n // avoid catching urls that start with \"/en\" like \"/enigma\"\n if (\n pathNameWithoutBaseUrl.length === 3 &&\n pathNameWithoutBaseUrlStartsWithLocale\n ) {\n return '/' + possibleLocaleKey\n }\n if (\n pathNameWithoutBaseUrl[0] === '/' &&\n pathNameWithoutBaseUrl[3] === '/' &&\n pathNameWithoutBaseUrlStartsWithLocale\n ) {\n // catch all \"/fr/**/*\" urls\n return '/' + possibleLocaleKey\n }\n // otherwise, it must be a defaultLocale or other url\n return ''\n}\n","import {\n // astro `BASE_URL` always starts with `/` and respects `config.trailingSlash`\n BASE_URL as baseUrl,\n localeKeys,\n defaultLocale,\n} from './config'\nimport { removeHtmlExtension } from './removeHtmlExtension'\nimport { removeTrailingSlash } from './removeTrailingSlash'\nimport { resolveTrailingSlash } from './resolveTrailingSlash'\n/**\n * @returns url without locale prefix, \"/es/about\" => \"/about\"\n */\nexport function getUrlWithoutLocale(url: URL | string): string {\n // support both string and url objects\n const pathName = typeof url === 'string' ? url : url.pathname\n const pathNameWithoutHtmlExtension = removeHtmlExtension(pathName)\n\n const baseUrlWithoutTrailingSlash = removeTrailingSlash(baseUrl)\n\n // remove baseUrlWithoutTrailingSlash from pathNameWithoutBaseUrl\n const pathNameWithoutBaseUrl =\n baseUrl === '/'\n ? pathNameWithoutHtmlExtension\n : pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash, '')\n\n const possibleLocaleKey = pathNameWithoutBaseUrl.slice(1, 3)\n const pathNameWithoutBaseUrlStartsWithLocale = localeKeys\n .filter((key) => key !== defaultLocale)\n .includes(possibleLocaleKey)\n\n // avoid catching urls that start with \"/en\" like \"/enigma\"\n if (\n pathNameWithoutBaseUrl.length === 3 &&\n pathNameWithoutBaseUrlStartsWithLocale\n ) {\n return resolveTrailingSlash(baseUrl)\n }\n if (\n pathNameWithoutBaseUrl[0] === '/' &&\n pathNameWithoutBaseUrl[3] === '/' &&\n pathNameWithoutBaseUrlStartsWithLocale\n ) {\n // catch all \"/fr/**/*\" urls\n return resolveTrailingSlash(\n baseUrlWithoutTrailingSlash + pathNameWithoutBaseUrl.slice(3)\n )\n }\n // otherwise, it must be a defaultLocale or other url\n return resolveTrailingSlash(\n baseUrlWithoutTrailingSlash + pathNameWithoutBaseUrl\n )\n}\n","import { defaultLocale } from './config'\n\ntype TranslationMap = Record<string, string>\n\nconst translationsByLocale: Record<string, TranslationMap> = {}\n\nconst modules = import.meta.glob<{ default: TranslationMap }>(\n '/src/i18n/*.json',\n {\n eager: true,\n }\n)\n\nfor (const [filePath, module] of Object.entries(modules)) {\n // Extract filename without extension as the locale name (e.g., \"../i18n/en.json\" -> \"en\")\n const locale = filePath.split('/').pop()?.replace('.json', '')\n if (locale) {\n translationsByLocale[locale] = module.default\n }\n}\n\n// Default fallback locale.\nconst DEFAULT_LOCALE = defaultLocale\n\n/**\n * Resolves a key (either flat or nested) from a translations object.\n */\nfunction getTranslationValue(\n translations: TranslationMap | undefined,\n key: string\n): unknown {\n if (!translations) return undefined\n\n // 1. Try flat key match first\n if (translations[key] !== undefined) {\n return translations[key]\n }\n\n // 2. Try nested path traversal (e.g. \"hello.message\")\n const parts = key.split('.')\n let current: TranslationMap | string = translations\n for (const part of parts) {\n if (current && typeof current === 'object' && part in current) {\n current = current[part]\n } else {\n return undefined\n }\n }\n\n return current\n}\n\n/**\n * Replaces double curly-brace placeholders with params.\n * e.g., \"Hello {{name}}\" with { name: 'World' } -> \"Hello World\"\n */\nfunction interpolate(\n template: string,\n params?: Record<string, string | number>\n): string {\n if (!params || typeof template !== 'string') return template\n return template.replace(/\\{\\{\\s*([^}]+?)\\s*\\}\\}/g, (match, key) => {\n return params[key] !== undefined ? String(params[key]) : match\n })\n}\n\n/**\n * Helper factory that takes a locale and returns a translation function.\n *\n * @param locale - The locale code (e.g. \"en\", \"es\")\n * @returns The translation function `t`\n */\nexport function getTranslateHelper(locale: string) {\n // Retrieve the translation map for the specified locale\n let translations = translationsByLocale[locale]\n\n // If target translation file is missing, fall back to default locale\n if (!translations && locale !== DEFAULT_LOCALE) {\n translations = translationsByLocale[DEFAULT_LOCALE]\n }\n\n return function t(\n key: string,\n params?: Record<string, string | number>\n ): string {\n let val = getTranslationValue(translations, key)\n\n // If key is not found in the target locale, try falling back to the default locale file\n if (val === undefined && locale !== DEFAULT_LOCALE) {\n const defaultTranslations = translationsByLocale[DEFAULT_LOCALE]\n val = getTranslationValue(defaultTranslations, key)\n }\n\n // If still not found, return the key itself\n if (val === undefined) {\n return key\n }\n\n if (typeof val === 'string') {\n return interpolate(val, params)\n }\n\n // If resolved value is an object or other type, fallback to key\n return key\n }\n}\n","import type { AstroConfig, ValidRedirectStatus } from 'astro'\n\nexport interface UserI18nConfig {\n /**\n * glob pattern(s) to include\n * @defaultValue [\"pages\\/\\*\\*\\/\\*\"]\n */\n include?: string | string[]\n /**\n * glob pattern(s) to exclude\n * @defaultValue [\"pages\\/api\\/\\*\\*\\/\\*\"]\n */\n exclude?: string | string[]\n /**\n * all language locales\n *\n * @example\n * ```ts\n * const locales = {\n * en: \"en-US\", // the `defaultLocale` value must present in `locales` keys\n * es: \"es-ES\",\n * fr: \"fr-CA\",\n * };\n * ```\n */\n locales: Record<string, string>\n /**\n * the default language locale\n *\n * the `defaultLocale` value must present in `locales` keys\n *\n * @example \"en\"\n */\n defaultLocale: string\n /**\n * given the defaultLocale \"en\", whether\n * \"/en/about\" redirects to \"/about\"\n *\n * whether the url with the default locale\n * should redirect to the url without the locale\n *\n * if a status is given, such as 302,\n * redirectDefaultLocale will be truthy,\n * and all redirects will use that status\n *\n * @defaultValue true\n */\n redirectDefaultLocale?: boolean | ValidRedirectStatus\n}\n\nexport type VirtualAstroi18nautConfig = Pick<\n UserI18nConfig,\n 'defaultLocale' | 'locales' | 'redirectDefaultLocale'\n> & {\n BASE_URL: string\n trailingSlash: AstroConfig['trailingSlash']\n build: {\n format: AstroConfig['build']['format']\n }\n}\n\nexport type UserFilterSitemapByDefaultLocaleConfig = Pick<\n UserI18nConfig,\n 'defaultLocale'\n> & {\n base?: string\n}\n\nexport type I18nConfig = Required<UserI18nConfig>\n\n// opposite of RequiredFieldsOnly https://stackoverflow.com/a/68261391\ntype PartialFieldsOnly<T> = {\n [K in keyof T as T[K] extends Required<T>[K] ? never : K]: T[K]\n}\n\n/**\n * The default values for I18nConfig\n */\nexport const defaultI18nConfig: Required<PartialFieldsOnly<UserI18nConfig>> = {\n include: ['pages/**/*'],\n exclude: ['pages/api/**/*'],\n redirectDefaultLocale: 308,\n}\n"],"mappings":"gHAAA,OAAO,kBAAmB,mCAEnB,IAAM,cAAgB,cAAc,cAC9B,SAAW,cAAc,SAAW,cAAc,SAAW,IAC7D,cAAgB,cAAc,cAC9B,QAAU,cAAc,QACxB,WAAa,OAAO,KAAK,cAAc,OAAO,EAC9C,sBAAwB,cAAc,sBACtC,MAAQ,cAAc,MCN5B,SAAS,gCAAgC,MAAgB,CAC9D,MAC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B,cAAc,EAC/D,IAAM,oBAAoB,oBAAqB,GAAG,CACpD,CAGA,OAAI,MAAQ,OACH,IAGL,OAAO,KAAQ,SACV,YAAY,IAAK,MAAM,EAIzB,GACT,EAvBO,IAwBT,CAjCgB,gDCMT,IAAM,kBAAiE,CAC5E,QAAS,CAAC,YAAY,EACtB,QAAS,CAAC,gBAAgB,EAC1B,sBAAuB,GACzB","names":[]}
@@ -0,0 +1,2 @@
1
+ export declare const i18nMiddleware: import("astro").MiddlewareHandler;
2
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/middleware.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,cAAc,mCA8CzB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare function removeHtmlExtension(url: string): string;
2
+ //# sourceMappingURL=removeHtmlExtension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removeHtmlExtension.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/removeHtmlExtension.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,UAE9C"}
@@ -0,0 +1,2 @@
1
+ export declare function removeTrailingSlash(url: string): string;
2
+ //# sourceMappingURL=removeTrailingSlash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removeTrailingSlash.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/removeTrailingSlash.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,UAE9C"}
@@ -0,0 +1,2 @@
1
+ export declare function resolveTrailingSlash(url: URL | string): string;
2
+ //# sourceMappingURL=resolveTrailingSlash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveTrailingSlash.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/resolveTrailingSlash.ts"],"names":[],"mappings":"AAEA,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,CAa9D"}
@@ -0,0 +1,5 @@
1
+ import type { AstroConfig } from 'astro';
2
+ import { UpdateConfig } from './UpdateConfig';
3
+ import type { I18nConfig } from '../../shared/configs';
4
+ export declare function createVirtualModules(config: AstroConfig, updateConfig: UpdateConfig, i18nConfig: I18nConfig): void;
5
+ //# sourceMappingURL=createVirtualModules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createVirtualModules.d.ts","sourceRoot":"","sources":["../../../src/integration/ensureValidConfigs/createVirtualModules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,KAAK,EACV,UAAU,EAEX,MAAM,sBAAsB,CAAA;AAG7B,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,WAAW,EACnB,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAU,GACrB,IAAI,CA8BN"}
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function createVirtualPlugin(virtualModuleId: string, json: unknown): Plugin;
3
+ //# sourceMappingURL=createVirtualPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createVirtualPlugin.d.ts","sourceRoot":"","sources":["../../../src/integration/ensureValidConfigs/createVirtualPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC,wBAAgB,mBAAmB,CACjC,eAAe,EAAE,MAAM,EACvB,IAAI,EAAE,OAAO,GACZ,MAAM,CAkBR"}
@@ -0,0 +1,5 @@
1
+ import type { AstroConfig, AstroIntegrationLogger } from 'astro';
2
+ import type { UpdateConfig } from './UpdateConfig';
3
+ import type { I18nConfig } from '../../shared/configs';
4
+ export declare function ensureValidConfigs(config: AstroConfig, updateConfig: UpdateConfig, i18nConfig: I18nConfig, logger: AstroIntegrationLogger): Promise<void>;
5
+ //# sourceMappingURL=ensureValidConfigs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensureValidConfigs.d.ts","sourceRoot":"","sources":["../../../src/integration/ensureValidConfigs/ensureValidConfigs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAItD,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,WAAW,EACnB,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,sBAAsB,iBAI/B"}
@@ -0,0 +1,4 @@
1
+ import type { AstroConfig, AstroIntegrationLogger } from 'astro';
2
+ import type { UpdateConfig } from './UpdateConfig';
3
+ export declare function ensureValidTrailingSlashAndFormat(config: AstroConfig, updateConfig: UpdateConfig, logger: AstroIntegrationLogger): void;
4
+ //# sourceMappingURL=ensureValidTrailingSlashAndFormat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensureValidTrailingSlashAndFormat.d.ts","sourceRoot":"","sources":["../../../src/integration/ensureValidConfigs/ensureValidTrailingSlashAndFormat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,WAAW,EACnB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,sBAAsB,QAuC/B"}
@@ -0,0 +1,2 @@
1
+ export { ensureValidConfigs } from './ensureValidConfigs';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/integration/ensureValidConfigs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var integration_exports={};__export(integration_exports,{default:()=>i18n,defaultI18nConfig:()=>defaultI18nConfig,filterSitemapByDefaultLocale:()=>filterSitemapByDefaultLocale,i18n:()=>i18n});module.exports=__toCommonJS(integration_exports);var import_node_path=__toESM(require("path"),1),import_node_url=require("url"),import_fast_glob=__toESM(require("fast-glob"),1),import_fs_extra=__toESM(require("fs-extra"),1),import_slash=__toESM(require("slash"),1);function removeLeadingForwardSlashWindows(path2){return path2.startsWith("/")&&path2[2]===":"?path2.substring(1):path2}__name(removeLeadingForwardSlashWindows,"removeLeadingForwardSlashWindows");var defaultI18nConfig={include:["pages/**/*"],exclude:["pages/api/**/*"],redirectDefaultLocale:308};function ensureValidTrailingSlashAndFormat(config,updateConfig,logger){config.trailingSlash==="ignore"&&config.output==="static"&&(logger.warn('avoid setting config.trailingSlash = "ignore" when config.output = "static"'),logger.warn('config.trailingSlash = "always" && config.build.format = "directory"'),logger.warn('config.trailingSlash = "never" && config.build.format = "file"'),logger.warn(`setting config.trailingSlash = "${config.trailingSlash}"`),updateConfig({trailingSlash:config.build.format==="directory"?"always":"never"})),config.trailingSlash==="always"&&config.build.format==="file"&&(logger.warn('config.trailingSlash = "always" must always be used with config.build.format = "directory"'),logger.warn('setting config.build.format = "directory"'),updateConfig({build:{format:"directory"}})),config.trailingSlash==="never"&&config.build.format==="directory"&&(logger.warn('config.trailingSlash = "never" must always be used with config.build.format = "file"'),logger.warn('setting config.build.format = "file"'),updateConfig({build:{format:"file"}}))}__name(ensureValidTrailingSlashAndFormat,"ensureValidTrailingSlashAndFormat");function createVirtualPlugin(virtualModuleId,json){let resolvedVirtualModuleId="\0"+virtualModuleId;return{name:"vite-plugin:"+virtualModuleId,resolveId(id){return id===virtualModuleId?resolvedVirtualModuleId:null},load(id){return id===resolvedVirtualModuleId?`export default ${JSON.stringify(json)}`:null}}}__name(createVirtualPlugin,"createVirtualPlugin");function createVirtualModules(config,updateConfig,i18nConfig){let virtualAstroi18nautConfig={defaultLocale:i18nConfig.defaultLocale,locales:i18nConfig.locales,redirectDefaultLocale:i18nConfig.redirectDefaultLocale,BASE_URL:getBaseUrl(config),trailingSlash:config.trailingSlash,build:{format:config.build.format}},virtualPlugin=createVirtualPlugin("virtual:@mcendon/astro-translate",virtualAstroi18nautConfig);updateConfig({vite:{plugins:[virtualPlugin],worker:{plugins:__name(()=>[virtualPlugin],"plugins")},optimizeDeps:{exclude:["virtual:@mcendon/astro-translate"]}}})}__name(createVirtualModules,"createVirtualModules");function getBaseUrl(config){let base=config.base;return base[0]!=="/"&&(base="/"+base),config.trailingSlash==="always"?base.at(-1)!=="/"&&(base=base+"/"):config.trailingSlash==="never"&&base!=="/"&&base.at(-1)==="/"&&(base=base.slice(0,-1)),base}__name(getBaseUrl,"getBaseUrl");async function ensureValidConfigs(config,updateConfig,i18nConfig,logger){ensureValidTrailingSlashAndFormat(config,updateConfig,logger),createVirtualModules(config,updateConfig,i18nConfig)}__name(ensureValidConfigs,"ensureValidConfigs");function i18n(userI18nConfig){let i18nConfig=Object.assign(defaultI18nConfig,userI18nConfig),{defaultLocale,locales,exclude,include,redirectDefaultLocale}=i18nConfig,pagesPathTmp={};async function removePagesPathTmp(){await Promise.all(Object.values(pagesPathTmp).map(pagePathTmp=>import_fs_extra.default.remove(pagePathTmp)))}return __name(removePagesPathTmp,"removePagesPathTmp"),{name:"astro-i18n-integration",hooks:{"astro:config:setup":__name(async({config,updateConfig,addMiddleware,command,injectRoute,logger})=>{ensureValidLocales(locales,defaultLocale,logger),await ensureValidConfigs(config,updateConfig,i18nConfig,logger),addMiddleware({entrypoint:"@mcendon/astro-translate/middleware",order:"pre"});let configSrcDirPathname=(0,import_node_url.fileURLToPath)(config.srcDir),included=ensureGlobsHaveConfigSrcDirPathname(typeof include=="string"?[include]:include,configSrcDirPathname),excluded=ensureGlobsHaveConfigSrcDirPathname(typeof exclude=="string"?[exclude]:exclude,configSrcDirPathname),pagesPath=import_node_path.default.join(configSrcDirPathname,"pages"),pagesPathTmpRoot=import_node_path.default.join(configSrcDirPathname,"astro_tmp_pages");for(let locale of Object.keys(locales))pagesPathTmp[locale]=`${pagesPathTmpRoot}_${locale}`;await removePagesPathTmp(),command==="build"&&await Promise.all(Object.keys(locales).filter(locale=>redirectDefaultLocale===!1||config.output==="server"?locale!==defaultLocale:!0).map(locale=>import_fs_extra.default.copy(pagesPath,pagesPathTmp[locale])));let entries=import_fast_glob.default.stream(included,{ignore:excluded,onlyFiles:!0}),entry;for await(entry of entries){let parsedPath=import_node_path.default.parse(entry),relativePath=import_node_path.default.relative(pagesPath,parsedPath.dir),extname=parsedPath.ext.slice(1).toLowerCase();if(extname!=="astro"){warnIsInvalidPage(extname,import_node_path.default.join(relativePath,parsedPath.base),configSrcDirPathname,logger);continue}for(let locale of Object.keys(locales)){if((redirectDefaultLocale===!1||config.output==="server")&&locale===defaultLocale)continue;let entrypoint=command==="build"?import_node_path.default.join(pagesPathTmp[locale],relativePath,parsedPath.base):import_node_path.default.join(pagesPath,relativePath,parsedPath.base),pattern=(0,import_slash.default)(import_node_path.default.join(locale,relativePath,parsedPath.name.endsWith("index")?"":parsedPath.name,config.build.format==="directory"?"/":""));injectRoute({entrypoint,pattern})}}},"astro:config:setup"),"astro:build:done":__name(async()=>{await removePagesPathTmp()},"astro:build:done"),"astro:server:done":__name(async()=>{await removePagesPathTmp()},"astro:server:done")}}}__name(i18n,"i18n");function ensureValidLocales(locales,defaultLocale,logger){if(!Object.keys(locales).includes(defaultLocale)){let errorMessage=`locales ${JSON.stringify(locales)} does not include "${defaultLocale}"`;throw logger.error(errorMessage),new Error(errorMessage)}}__name(ensureValidLocales,"ensureValidLocales");function ensureGlobsHaveConfigSrcDirPathname(filePaths,configSrcDirPathname){return filePaths.map(filePath=>(filePath=import_node_path.default.normalize(removeLeadingForwardSlashWindows(filePath)),filePath.includes(configSrcDirPathname)&&(filePath=import_node_path.default.relative(configSrcDirPathname,filePath)),filePath=import_node_path.default.posix.join(import_fast_glob.default.convertPathToPattern(configSrcDirPathname),(0,import_slash.default)(filePath)),filePath))}__name(ensureGlobsHaveConfigSrcDirPathname,"ensureGlobsHaveConfigSrcDirPathname");var hasWarnedIsInvalidPage=!1;function warnIsInvalidPage(extname,filePath,configSrcDirPathname,logger){return["js","ts","md","mdx","html"].includes(extname)?(hasWarnedIsInvalidPage===!1&&(logger.warn(`exclude or remove non-astro files from "${configSrcDirPathname}pages", as they cannot be translated`),hasWarnedIsInvalidPage=!0),logger.warn(import_node_path.default.join(configSrcDirPathname,"pages",filePath)),!0):!1}__name(warnIsInvalidPage,"warnIsInvalidPage");function removeHtmlExtension(url){return url.endsWith(".html")?url.slice(0,-5):url}__name(removeHtmlExtension,"removeHtmlExtension");function filterSitemapByDefaultLocale({defaultLocale,base:baseUrl="/"}){baseUrl[0]!=="/"&&(baseUrl="/"+baseUrl);let baseUrlWithoutTrailingSlash=baseUrl.at(-1)==="/"?baseUrl.slice(0,-1):baseUrl;return __name(function(page){let pathName=new URL(page).pathname,pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),pathNameWithoutBaseUrl=baseUrl==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),pathNameWithoutBaseUrlStartsWithDefaultLocale=pathNameWithoutBaseUrl.slice(1,3)===defaultLocale;return!(pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithDefaultLocale||pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithDefaultLocale)},"filter")}__name(filterSitemapByDefaultLocale,"filterSitemapByDefaultLocale");0&&(module.exports={defaultI18nConfig,filterSitemapByDefaultLocale,i18n});
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/integration/index.ts","../../src/integration/integration.ts","../../src/astro/internal-helpers/path.ts","../../src/shared/configs.ts","../../src/integration/ensureValidConfigs/ensureValidTrailingSlashAndFormat.ts","../../src/integration/ensureValidConfigs/createVirtualPlugin.ts","../../src/integration/ensureValidConfigs/createVirtualModules.ts","../../src/integration/ensureValidConfigs/ensureValidConfigs.ts","../../src/edge-runtime/removeHtmlExtension.ts","../../src/shared/filterSitemapByDefaultLocale.ts"],"sourcesContent":["export { i18n, i18n as default } from './integration'\nexport { filterSitemapByDefaultLocale } from '../shared/filterSitemapByDefaultLocale'\nexport { defaultI18nConfig } from '../shared/configs'\nexport type {\n UserI18nConfig,\n UserFilterSitemapByDefaultLocaleConfig,\n} from '../shared/configs'\n","import path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { AstroIntegration, AstroIntegrationLogger } from 'astro'\nimport fg from 'fast-glob'\nimport fs from 'fs-extra'\nimport slash from 'slash'\nimport { removeLeadingForwardSlashWindows } from '../astro/internal-helpers/path'\nimport { defaultI18nConfig } from '../shared/configs'\nimport type { UserI18nConfig, I18nConfig } from '../shared/configs'\nimport { ensureValidConfigs } from './ensureValidConfigs'\n\n// injectRoute doesn't generate build pages https://github.com/withastro/astro/issues/5096\n// workaround: copy pages folder when command === \"build\"\n\n/**\n * The i18n integration for Astro\n *\n * See the full [@mcendon/astro-translate](https://github.com/mcendon/astro-translate#readme) documentation\n */\nexport function i18n(userI18nConfig: UserI18nConfig): AstroIntegration {\n const i18nConfig: I18nConfig = Object.assign(\n defaultI18nConfig,\n userI18nConfig\n )\n\n const { defaultLocale, locales, exclude, include, redirectDefaultLocale } =\n i18nConfig\n\n const pagesPathTmp: Record<string, string> = {}\n async function removePagesPathTmp(): Promise<void> {\n await Promise.all(\n Object.values(pagesPathTmp).map((pagePathTmp) => fs.remove(pagePathTmp))\n )\n }\n\n return {\n name: 'astro-i18n-integration',\n hooks: {\n 'astro:config:setup': async ({\n config,\n updateConfig,\n addMiddleware,\n command,\n injectRoute,\n logger,\n }) => {\n ensureValidLocales(locales, defaultLocale, logger)\n await ensureValidConfigs(config, updateConfig, i18nConfig, logger)\n addMiddleware({\n entrypoint: '@mcendon/astro-translate/middleware',\n order: 'pre',\n })\n\n const configSrcDirPathname = fileURLToPath(config.srcDir)\n\n const included: string[] = ensureGlobsHaveConfigSrcDirPathname(\n typeof include === 'string' ? [include] : include,\n configSrcDirPathname\n )\n const excluded: string[] = ensureGlobsHaveConfigSrcDirPathname(\n typeof exclude === 'string' ? [exclude] : exclude,\n configSrcDirPathname\n )\n\n const pagesPath = path.join(configSrcDirPathname, 'pages')\n\n const pagesPathTmpRoot = path.join(\n configSrcDirPathname,\n // tmp filename from https://github.com/withastro/astro/blob/e6bff651ff80466b3e862e637d2a6a3334d8cfda/packages/astro/src/core/routing/manifest/create.ts#L279\n 'astro_tmp_pages'\n )\n for (const locale of Object.keys(locales)) {\n pagesPathTmp[locale] = `${pagesPathTmpRoot}_${locale}`\n }\n\n await removePagesPathTmp()\n if (command === 'build') {\n await Promise.all(\n Object.keys(locales)\n .filter((locale) => {\n if (\n redirectDefaultLocale === false ||\n config.output === 'server'\n ) {\n return locale !== defaultLocale\n } else {\n return true\n }\n })\n .map((locale) => fs.copy(pagesPath, pagesPathTmp[locale]))\n )\n }\n\n const entries = fg.stream(included, {\n ignore: excluded,\n onlyFiles: true,\n })\n // typing https://stackoverflow.com/a/68358341\n let entry: string\n // @ts-expect-error: fast-glob stream does not fully align with for-await typings in this environment\n for await (entry of entries) {\n const parsedPath = path.parse(entry)\n const relativePath = path.relative(pagesPath, parsedPath.dir)\n const extname = parsedPath.ext.slice(1).toLowerCase()\n\n // warn on files that cannot be translated with specific and actionable warnings\n // astro pages file types https://docs.astro.build/en/core-concepts/astro-pages/#supported-page-files\n // any file that is not included as an astro page file types, will be automatically warned about by astro\n if (extname !== 'astro') {\n warnIsInvalidPage(\n extname,\n path.join(relativePath, parsedPath.base),\n configSrcDirPathname,\n logger\n )\n continue\n }\n\n for (const locale of Object.keys(locales)) {\n // ignore defaultLocale if redirectDefaultLocale is false or if using SSR\n if (\n (redirectDefaultLocale === false || config.output === 'server') &&\n locale === defaultLocale\n ) {\n continue\n }\n\n const entrypoint =\n command === 'build'\n ? path.join(pagesPathTmp[locale], relativePath, parsedPath.base)\n : path.join(pagesPath, relativePath, parsedPath.base)\n\n const pattern = slash(\n path.join(\n // astro automatically handles prepending `config.base`\n locale,\n relativePath,\n parsedPath.name.endsWith('index') ? '' : parsedPath.name,\n config.build.format === 'directory' ? '/' : ''\n )\n )\n\n injectRoute({\n entrypoint,\n pattern,\n })\n }\n }\n },\n 'astro:build:done': async () => {\n await removePagesPathTmp()\n },\n 'astro:server:done': async () => {\n await removePagesPathTmp()\n },\n },\n }\n}\n\nfunction ensureValidLocales(\n locales: Record<string, string>,\n defaultLocale: string,\n logger: AstroIntegrationLogger\n) {\n if (!Object.keys(locales).includes(defaultLocale)) {\n const errorMessage = `locales ${JSON.stringify(\n locales\n )} does not include \"${defaultLocale}\"`\n logger.error(errorMessage)\n throw new Error(errorMessage)\n }\n}\n\nfunction ensureGlobsHaveConfigSrcDirPathname(\n filePaths: string[],\n configSrcDirPathname: string\n) {\n return filePaths.map((filePath) => {\n filePath = path.normalize(removeLeadingForwardSlashWindows(filePath))\n\n if (filePath.includes(configSrcDirPathname)) {\n filePath = path.relative(configSrcDirPathname, filePath)\n }\n\n // fast-glob prefers unix paths https://www.npmjs.com/package/fast-glob#how-to-write-patterns-on-windows\n filePath = path.posix.join(\n fg.convertPathToPattern(configSrcDirPathname),\n slash(filePath)\n )\n\n return filePath\n })\n}\n\nlet hasWarnedIsInvalidPage = false\nfunction warnIsInvalidPage(\n extname: string,\n filePath: string,\n configSrcDirPathname: string,\n logger: AstroIntegrationLogger\n): boolean {\n // astro pages file types https://docs.astro.build/en/core-concepts/astro-pages/#supported-page-files\n if (['js', 'ts', 'md', 'mdx', 'html'].includes(extname)) {\n if (hasWarnedIsInvalidPage === false) {\n logger.warn(\n `exclude or remove non-astro files from \"${configSrcDirPathname}pages\", as they cannot be translated`\n )\n hasWarnedIsInvalidPage = true\n }\n logger.warn(path.join(configSrcDirPathname, 'pages', filePath))\n return true\n }\n return false\n}\n","export function removeLeadingForwardSlashWindows(path: string) {\n return path.startsWith('/') && path[2] === ':' ? path.substring(1) : path\n}\n","import type { AstroConfig, ValidRedirectStatus } from 'astro'\n\nexport interface UserI18nConfig {\n /**\n * glob pattern(s) to include\n * @defaultValue [\"pages\\/\\*\\*\\/\\*\"]\n */\n include?: string | string[]\n /**\n * glob pattern(s) to exclude\n * @defaultValue [\"pages\\/api\\/\\*\\*\\/\\*\"]\n */\n exclude?: string | string[]\n /**\n * all language locales\n *\n * @example\n * ```ts\n * const locales = {\n * en: \"en-US\", // the `defaultLocale` value must present in `locales` keys\n * es: \"es-ES\",\n * fr: \"fr-CA\",\n * };\n * ```\n */\n locales: Record<string, string>\n /**\n * the default language locale\n *\n * the `defaultLocale` value must present in `locales` keys\n *\n * @example \"en\"\n */\n defaultLocale: string\n /**\n * given the defaultLocale \"en\", whether\n * \"/en/about\" redirects to \"/about\"\n *\n * whether the url with the default locale\n * should redirect to the url without the locale\n *\n * if a status is given, such as 302,\n * redirectDefaultLocale will be truthy,\n * and all redirects will use that status\n *\n * @defaultValue true\n */\n redirectDefaultLocale?: boolean | ValidRedirectStatus\n}\n\nexport type VirtualAstroi18nautConfig = Pick<\n UserI18nConfig,\n 'defaultLocale' | 'locales' | 'redirectDefaultLocale'\n> & {\n BASE_URL: string\n trailingSlash: AstroConfig['trailingSlash']\n build: {\n format: AstroConfig['build']['format']\n }\n}\n\nexport type UserFilterSitemapByDefaultLocaleConfig = Pick<\n UserI18nConfig,\n 'defaultLocale'\n> & {\n base?: string\n}\n\nexport type I18nConfig = Required<UserI18nConfig>\n\n// opposite of RequiredFieldsOnly https://stackoverflow.com/a/68261391\ntype PartialFieldsOnly<T> = {\n [K in keyof T as T[K] extends Required<T>[K] ? never : K]: T[K]\n}\n\n/**\n * The default values for I18nConfig\n */\nexport const defaultI18nConfig: Required<PartialFieldsOnly<UserI18nConfig>> = {\n include: ['pages/**/*'],\n exclude: ['pages/api/**/*'],\n redirectDefaultLocale: 308,\n}\n","import type { AstroConfig, AstroIntegrationLogger } from 'astro'\nimport type { UpdateConfig } from './UpdateConfig'\n\nexport function ensureValidTrailingSlashAndFormat(\n config: AstroConfig,\n updateConfig: UpdateConfig,\n logger: AstroIntegrationLogger\n) {\n if (config.trailingSlash === 'ignore' && config.output === 'static') {\n logger.warn(\n `avoid setting config.trailingSlash = \"ignore\" when config.output = \"static\"`\n )\n logger.warn(\n `config.trailingSlash = \"always\" && config.build.format = \"directory\"`\n )\n logger.warn(\n `config.trailingSlash = \"never\" && config.build.format = \"file\"`\n )\n logger.warn(`setting config.trailingSlash = \"${config.trailingSlash}\"`)\n updateConfig({\n trailingSlash: config.build.format === 'directory' ? 'always' : 'never',\n })\n }\n if (config.trailingSlash === 'always' && config.build.format === 'file') {\n logger.warn(\n `config.trailingSlash = \"always\" must always be used with config.build.format = \"directory\"`\n )\n logger.warn(`setting config.build.format = \"directory\"`)\n updateConfig({\n build: {\n format: 'directory',\n },\n })\n }\n if (config.trailingSlash === 'never' && config.build.format === 'directory') {\n logger.warn(\n `config.trailingSlash = \"never\" must always be used with config.build.format = \"file\"`\n )\n logger.warn(`setting config.build.format = \"file\"`)\n updateConfig({\n build: {\n format: 'file',\n },\n })\n }\n}\n","import type { Plugin } from 'vite'\n\n// documentation https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention\n\nexport function createVirtualPlugin(\n virtualModuleId: string,\n json: unknown\n): Plugin {\n const resolvedVirtualModuleId = '\\0' + virtualModuleId\n\n return {\n name: 'vite-plugin:' + virtualModuleId, // required, will show up in warnings and errors\n resolveId(id: string) {\n if (id === virtualModuleId) {\n return resolvedVirtualModuleId\n }\n return null\n },\n load(id: string) {\n if (id === resolvedVirtualModuleId) {\n return `export default ${JSON.stringify(json)}`\n }\n return null\n },\n }\n}\n","import type { AstroConfig } from 'astro'\nimport { UpdateConfig } from './UpdateConfig'\nimport type {\n I18nConfig,\n VirtualAstroi18nautConfig,\n} from '../../shared/configs'\nimport { createVirtualPlugin } from './createVirtualPlugin'\n\nexport function createVirtualModules(\n config: AstroConfig,\n updateConfig: UpdateConfig,\n i18nConfig: I18nConfig\n): void {\n const virtualAstroi18nautConfig: VirtualAstroi18nautConfig = {\n defaultLocale: i18nConfig.defaultLocale,\n locales: i18nConfig.locales,\n redirectDefaultLocale: i18nConfig.redirectDefaultLocale,\n BASE_URL: getBaseUrl(config),\n trailingSlash: config.trailingSlash,\n build: {\n format: config.build.format,\n },\n }\n\n const virtualPlugin = createVirtualPlugin(\n 'virtual:@mcendon/astro-translate',\n virtualAstroi18nautConfig\n )\n\n updateConfig({\n vite: {\n plugins: [virtualPlugin],\n // worker plugins are separate https://github.com/vitejs/vite/issues/8520\n worker: {\n plugins: () => [virtualPlugin],\n },\n // exclude virtual modules from optimizeDeps https://github.com/storybookjs/builder-vite/issues/311#issuecomment-1092577628\n optimizeDeps: {\n exclude: ['virtual:@mcendon/astro-translate'],\n },\n },\n })\n}\n\nfunction getBaseUrl(config: AstroConfig): string {\n let base = config.base\n\n // astro `BASE_URL` always starts with `/` and respects `config.trailingSlash`\n if (base[0] !== '/') {\n base = '/' + base\n }\n\n // https://docs.astro.build/en/reference/configuration-reference/#base\n // The value of import.meta.env.BASE_URL respects your trailingSlash config\n // and will include a trailing slash\n // if you explicitly include one\n // or if trailingSlash: \"always\" is set.\n // If trailingSlash: \"never\" is set,\n // BASE_URL will not include a trailing slash,\n // even if base includes one.\n if (config.trailingSlash === 'always') {\n if (base.at(-1) !== '/') {\n base = base + '/'\n }\n } else if (config.trailingSlash === 'never') {\n if (base !== '/' && base.at(-1) === '/') {\n base = base.slice(0, -1)\n }\n }\n\n return base\n}\n","import type { AstroConfig, AstroIntegrationLogger } from 'astro'\nimport type { UpdateConfig } from './UpdateConfig'\nimport type { I18nConfig } from '../../shared/configs'\nimport { ensureValidTrailingSlashAndFormat } from './ensureValidTrailingSlashAndFormat'\nimport { createVirtualModules } from './createVirtualModules'\n\nexport async function ensureValidConfigs(\n config: AstroConfig,\n updateConfig: UpdateConfig,\n i18nConfig: I18nConfig,\n logger: AstroIntegrationLogger\n) {\n ensureValidTrailingSlashAndFormat(config, updateConfig, logger)\n createVirtualModules(config, updateConfig, i18nConfig)\n}\n","export function removeHtmlExtension(url: string) {\n return url.endsWith('.html') ? url.slice(0, -'.html'.length) : url\n}\n","import { removeHtmlExtension } from '../edge-runtime/removeHtmlExtension'\nimport type { UserFilterSitemapByDefaultLocaleConfig } from './configs'\n\n// sitemap filter https://docs.astro.build/en/guides/integrations-guide/sitemap/#filter\nexport function filterSitemapByDefaultLocale({\n defaultLocale,\n base: baseUrl = '/',\n}: UserFilterSitemapByDefaultLocaleConfig) {\n // astro `BASE_URL` always starts with `/` and respects `config.trailingSlash`\n if (baseUrl[0] !== '/') {\n baseUrl = '/' + baseUrl\n }\n\n const baseUrlWithoutTrailingSlash =\n baseUrl.at(-1) === '/' ? baseUrl.slice(0, -1) : baseUrl\n\n return function filter(page: string) {\n const pathName = new URL(page).pathname\n const pathNameWithoutHtmlExtension = removeHtmlExtension(pathName)\n\n // remove baseUrlWithoutTrailingSlash from pathNameWithoutBaseUrl\n const pathNameWithoutBaseUrl =\n baseUrl === '/'\n ? pathNameWithoutHtmlExtension\n : pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash, '')\n\n const pathNameWithoutBaseUrlStartsWithDefaultLocale =\n pathNameWithoutBaseUrl.slice(1, 3) === defaultLocale\n\n if (\n pathNameWithoutBaseUrl.length === 3 &&\n pathNameWithoutBaseUrlStartsWithDefaultLocale\n ) {\n return false\n }\n // catch all \"/en/**/*\" urls\n if (\n pathNameWithoutBaseUrl[0] === '/' &&\n pathNameWithoutBaseUrl[3] === '/' &&\n pathNameWithoutBaseUrlStartsWithDefaultLocale\n ) {\n return false\n }\n\n return true\n }\n}\n"],"mappings":"q+BAAA,iPCAA,qBAAiB,2BACjB,gBAA8B,eAE9B,iBAAe,gCACf,gBAAe,+BACf,aAAkB,4BCLX,SAAS,iCAAiCA,MAAc,CAC7D,OAAOA,MAAK,WAAW,GAAG,GAAKA,MAAK,CAAC,IAAM,IAAMA,MAAK,UAAU,CAAC,EAAIA,KACvE,CAFgB,4EC8ET,IAAM,kBAAiE,CAC5E,QAAS,CAAC,YAAY,EACtB,QAAS,CAAC,gBAAgB,EAC1B,sBAAuB,GACzB,EC/EO,SAAS,kCACd,OACA,aACA,OACA,CACI,OAAO,gBAAkB,UAAY,OAAO,SAAW,WACzD,OAAO,KACL,6EACF,EACA,OAAO,KACL,sEACF,EACA,OAAO,KACL,gEACF,EACA,OAAO,KAAK,mCAAmC,OAAO,aAAa,GAAG,EACtE,aAAa,CACX,cAAe,OAAO,MAAM,SAAW,YAAc,SAAW,OAClE,CAAC,GAEC,OAAO,gBAAkB,UAAY,OAAO,MAAM,SAAW,SAC/D,OAAO,KACL,4FACF,EACA,OAAO,KAAK,2CAA2C,EACvD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IzD,SAAW,iBAAAA,QAAK,MAAM,KACpB,iBAAAC,QAAG,qBAAqB,oBAAoB,KAC5C,aAAAC,SAAM,QAAQ,CAChB,EAEO,SACR,CACH,CAnBS,kFAqBT,IAAI,uBAAyB,GAC7B,SAAS,kBACP,QACA,SACA,qBACA,OACS,CAET,MAAI,CAAC,KAAM,KAAM,KAAM,MAAO,MAAM,EAAE,SAAS,OAAO,GAChD,yBAA2B,KAC7B,OAAO,KACL,2CAA2C,oBAAoB,sCACjE,EACA,uBAAyB,IAE3B,OAAO,KAAK,iBAAAF,QAAK,KAAK,qBAAsB,QAAS,QAAQ,CAAC,EACvD,IAEF,EACT,CAlBS,8COnMF,SAAS,oBAAoB,IAAa,CAC/C,OAAO,IAAI,SAAS,OAAO,EAAI,IAAI,MAAM,EAAG,EAAe,EAAI,GACjE,CAFgB,kDCIT,SAAS,6BAA6B,CAC3C,cACA,KAAM,QAAU,GAClB,EAA2C,CAErC,QAAQ,CAAC,IAAM,MACjB,QAAU,IAAM,SAGlB,IAAM,4BACJ,QAAQ,GAAG,EAAE,IAAM,IAAM,QAAQ,MAAM,EAAG,EAAE,EAAI,QAElD,OAAO,gBAAgB,KAAc,CACnC,IAAM,SAAW,IAAI,IAAI,IAAI,EAAE,SACzB,6BAA+B,oBAAoB,QAAQ,EAG3D,uBACJ,UAAY,IACR,6BACA,6BAA6B,QAAQ,4BAA6B,EAAE,EAEpE,8CACJ,uBAAuB,MAAM,EAAG,CAAC,IAAM,cASzC,MANE,yBAAuB,SAAW,GAClC,+CAMA,uBAAuB,CAAC,IAAM,KAC9B,uBAAuB,CAAC,IAAM,KAC9B,8CAMJ,EA7BO,SA8BT,CA1CgB","names":["path","fs","path","fg","slash"]}
@@ -0,0 +1,5 @@
1
+ export { i18n, i18n as default } from './integration';
2
+ export { filterSitemapByDefaultLocale } from '../shared/filterSitemapByDefaultLocale';
3
+ export { defaultI18nConfig } from '../shared/configs';
4
+ export type { UserI18nConfig, UserFilterSitemapByDefaultLocaleConfig, } from '../shared/configs';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/integration/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAA;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,YAAY,EACV,cAAc,EACd,sCAAsC,GACvC,MAAM,mBAAmB,CAAA"}
@@ -0,0 +1,2 @@
1
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import path from"path";import{fileURLToPath}from"url";import fg from"fast-glob";import fs from"fs-extra";import slash from"slash";function removeLeadingForwardSlashWindows(path2){return path2.startsWith("/")&&path2[2]===":"?path2.substring(1):path2}__name(removeLeadingForwardSlashWindows,"removeLeadingForwardSlashWindows");var defaultI18nConfig={include:["pages/**/*"],exclude:["pages/api/**/*"],redirectDefaultLocale:308};function ensureValidTrailingSlashAndFormat(config,updateConfig,logger){config.trailingSlash==="ignore"&&config.output==="static"&&(logger.warn('avoid setting config.trailingSlash = "ignore" when config.output = "static"'),logger.warn('config.trailingSlash = "always" && config.build.format = "directory"'),logger.warn('config.trailingSlash = "never" && config.build.format = "file"'),logger.warn(`setting config.trailingSlash = "${config.trailingSlash}"`),updateConfig({trailingSlash:config.build.format==="directory"?"always":"never"})),config.trailingSlash==="always"&&config.build.format==="file"&&(logger.warn('config.trailingSlash = "always" must always be used with config.build.format = "directory"'),logger.warn('setting config.build.format = "directory"'),updateConfig({build:{format:"directory"}})),config.trailingSlash==="never"&&config.build.format==="directory"&&(logger.warn('config.trailingSlash = "never" must always be used with config.build.format = "file"'),logger.warn('setting config.build.format = "file"'),updateConfig({build:{format:"file"}}))}__name(ensureValidTrailingSlashAndFormat,"ensureValidTrailingSlashAndFormat");function createVirtualPlugin(virtualModuleId,json){let resolvedVirtualModuleId="\0"+virtualModuleId;return{name:"vite-plugin:"+virtualModuleId,resolveId(id){return id===virtualModuleId?resolvedVirtualModuleId:null},load(id){return id===resolvedVirtualModuleId?`export default ${JSON.stringify(json)}`:null}}}__name(createVirtualPlugin,"createVirtualPlugin");function createVirtualModules(config,updateConfig,i18nConfig){let virtualAstroi18nautConfig={defaultLocale:i18nConfig.defaultLocale,locales:i18nConfig.locales,redirectDefaultLocale:i18nConfig.redirectDefaultLocale,BASE_URL:getBaseUrl(config),trailingSlash:config.trailingSlash,build:{format:config.build.format}},virtualPlugin=createVirtualPlugin("virtual:@mcendon/astro-translate",virtualAstroi18nautConfig);updateConfig({vite:{plugins:[virtualPlugin],worker:{plugins:__name(()=>[virtualPlugin],"plugins")},optimizeDeps:{exclude:["virtual:@mcendon/astro-translate"]}}})}__name(createVirtualModules,"createVirtualModules");function getBaseUrl(config){let base=config.base;return base[0]!=="/"&&(base="/"+base),config.trailingSlash==="always"?base.at(-1)!=="/"&&(base=base+"/"):config.trailingSlash==="never"&&base!=="/"&&base.at(-1)==="/"&&(base=base.slice(0,-1)),base}__name(getBaseUrl,"getBaseUrl");async function ensureValidConfigs(config,updateConfig,i18nConfig,logger){ensureValidTrailingSlashAndFormat(config,updateConfig,logger),createVirtualModules(config,updateConfig,i18nConfig)}__name(ensureValidConfigs,"ensureValidConfigs");function i18n(userI18nConfig){let i18nConfig=Object.assign(defaultI18nConfig,userI18nConfig),{defaultLocale,locales,exclude,include,redirectDefaultLocale}=i18nConfig,pagesPathTmp={};async function removePagesPathTmp(){await Promise.all(Object.values(pagesPathTmp).map(pagePathTmp=>fs.remove(pagePathTmp)))}return __name(removePagesPathTmp,"removePagesPathTmp"),{name:"astro-i18n-integration",hooks:{"astro:config:setup":__name(async({config,updateConfig,addMiddleware,command,injectRoute,logger})=>{ensureValidLocales(locales,defaultLocale,logger),await ensureValidConfigs(config,updateConfig,i18nConfig,logger),addMiddleware({entrypoint:"@mcendon/astro-translate/middleware",order:"pre"});let configSrcDirPathname=fileURLToPath(config.srcDir),included=ensureGlobsHaveConfigSrcDirPathname(typeof include=="string"?[include]:include,configSrcDirPathname),excluded=ensureGlobsHaveConfigSrcDirPathname(typeof exclude=="string"?[exclude]:exclude,configSrcDirPathname),pagesPath=path.join(configSrcDirPathname,"pages"),pagesPathTmpRoot=path.join(configSrcDirPathname,"astro_tmp_pages");for(let locale of Object.keys(locales))pagesPathTmp[locale]=`${pagesPathTmpRoot}_${locale}`;await removePagesPathTmp(),command==="build"&&await Promise.all(Object.keys(locales).filter(locale=>redirectDefaultLocale===!1||config.output==="server"?locale!==defaultLocale:!0).map(locale=>fs.copy(pagesPath,pagesPathTmp[locale])));let entries=fg.stream(included,{ignore:excluded,onlyFiles:!0}),entry;for await(entry of entries){let parsedPath=path.parse(entry),relativePath=path.relative(pagesPath,parsedPath.dir),extname=parsedPath.ext.slice(1).toLowerCase();if(extname!=="astro"){warnIsInvalidPage(extname,path.join(relativePath,parsedPath.base),configSrcDirPathname,logger);continue}for(let locale of Object.keys(locales)){if((redirectDefaultLocale===!1||config.output==="server")&&locale===defaultLocale)continue;let entrypoint=command==="build"?path.join(pagesPathTmp[locale],relativePath,parsedPath.base):path.join(pagesPath,relativePath,parsedPath.base),pattern=slash(path.join(locale,relativePath,parsedPath.name.endsWith("index")?"":parsedPath.name,config.build.format==="directory"?"/":""));injectRoute({entrypoint,pattern})}}},"astro:config:setup"),"astro:build:done":__name(async()=>{await removePagesPathTmp()},"astro:build:done"),"astro:server:done":__name(async()=>{await removePagesPathTmp()},"astro:server:done")}}}__name(i18n,"i18n");function ensureValidLocales(locales,defaultLocale,logger){if(!Object.keys(locales).includes(defaultLocale)){let errorMessage=`locales ${JSON.stringify(locales)} does not include "${defaultLocale}"`;throw logger.error(errorMessage),new Error(errorMessage)}}__name(ensureValidLocales,"ensureValidLocales");function ensureGlobsHaveConfigSrcDirPathname(filePaths,configSrcDirPathname){return filePaths.map(filePath=>(filePath=path.normalize(removeLeadingForwardSlashWindows(filePath)),filePath.includes(configSrcDirPathname)&&(filePath=path.relative(configSrcDirPathname,filePath)),filePath=path.posix.join(fg.convertPathToPattern(configSrcDirPathname),slash(filePath)),filePath))}__name(ensureGlobsHaveConfigSrcDirPathname,"ensureGlobsHaveConfigSrcDirPathname");var hasWarnedIsInvalidPage=!1;function warnIsInvalidPage(extname,filePath,configSrcDirPathname,logger){return["js","ts","md","mdx","html"].includes(extname)?(hasWarnedIsInvalidPage===!1&&(logger.warn(`exclude or remove non-astro files from "${configSrcDirPathname}pages", as they cannot be translated`),hasWarnedIsInvalidPage=!0),logger.warn(path.join(configSrcDirPathname,"pages",filePath)),!0):!1}__name(warnIsInvalidPage,"warnIsInvalidPage");function removeHtmlExtension(url){return url.endsWith(".html")?url.slice(0,-5):url}__name(removeHtmlExtension,"removeHtmlExtension");function filterSitemapByDefaultLocale({defaultLocale,base:baseUrl="/"}){baseUrl[0]!=="/"&&(baseUrl="/"+baseUrl);let baseUrlWithoutTrailingSlash=baseUrl.at(-1)==="/"?baseUrl.slice(0,-1):baseUrl;return __name(function(page){let pathName=new URL(page).pathname,pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),pathNameWithoutBaseUrl=baseUrl==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),pathNameWithoutBaseUrlStartsWithDefaultLocale=pathNameWithoutBaseUrl.slice(1,3)===defaultLocale;return!(pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithDefaultLocale||pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithDefaultLocale)},"filter")}__name(filterSitemapByDefaultLocale,"filterSitemapByDefaultLocale");export{i18n as default,defaultI18nConfig,filterSitemapByDefaultLocale,i18n};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/integration/integration.ts","../../src/astro/internal-helpers/path.ts","../../src/shared/configs.ts","../../src/integration/ensureValidConfigs/ensureValidTrailingSlashAndFormat.ts","../../src/integration/ensureValidConfigs/createVirtualPlugin.ts","../../src/integration/ensureValidConfigs/createVirtualModules.ts","../../src/integration/ensureValidConfigs/ensureValidConfigs.ts","../../src/edge-runtime/removeHtmlExtension.ts","../../src/shared/filterSitemapByDefaultLocale.ts"],"sourcesContent":["import path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { AstroIntegration, AstroIntegrationLogger } from 'astro'\nimport fg from 'fast-glob'\nimport fs from 'fs-extra'\nimport slash from 'slash'\nimport { removeLeadingForwardSlashWindows } from '../astro/internal-helpers/path'\nimport { defaultI18nConfig } from '../shared/configs'\nimport type { UserI18nConfig, I18nConfig } from '../shared/configs'\nimport { ensureValidConfigs } from './ensureValidConfigs'\n\n// injectRoute doesn't generate build pages https://github.com/withastro/astro/issues/5096\n// workaround: copy pages folder when command === \"build\"\n\n/**\n * The i18n integration for Astro\n *\n * See the full [@mcendon/astro-translate](https://github.com/mcendon/astro-translate#readme) documentation\n */\nexport function i18n(userI18nConfig: UserI18nConfig): AstroIntegration {\n const i18nConfig: I18nConfig = Object.assign(\n defaultI18nConfig,\n userI18nConfig\n )\n\n const { defaultLocale, locales, exclude, include, redirectDefaultLocale } =\n i18nConfig\n\n const pagesPathTmp: Record<string, string> = {}\n async function removePagesPathTmp(): Promise<void> {\n await Promise.all(\n Object.values(pagesPathTmp).map((pagePathTmp) => fs.remove(pagePathTmp))\n )\n }\n\n return {\n name: 'astro-i18n-integration',\n hooks: {\n 'astro:config:setup': async ({\n config,\n updateConfig,\n addMiddleware,\n command,\n injectRoute,\n logger,\n }) => {\n ensureValidLocales(locales, defaultLocale, logger)\n await ensureValidConfigs(config, updateConfig, i18nConfig, logger)\n addMiddleware({\n entrypoint: '@mcendon/astro-translate/middleware',\n order: 'pre',\n })\n\n const configSrcDirPathname = fileURLToPath(config.srcDir)\n\n const included: string[] = ensureGlobsHaveConfigSrcDirPathname(\n typeof include === 'string' ? [include] : include,\n configSrcDirPathname\n )\n const excluded: string[] = ensureGlobsHaveConfigSrcDirPathname(\n typeof exclude === 'string' ? [exclude] : exclude,\n configSrcDirPathname\n )\n\n const pagesPath = path.join(configSrcDirPathname, 'pages')\n\n const pagesPathTmpRoot = path.join(\n configSrcDirPathname,\n // tmp filename from https://github.com/withastro/astro/blob/e6bff651ff80466b3e862e637d2a6a3334d8cfda/packages/astro/src/core/routing/manifest/create.ts#L279\n 'astro_tmp_pages'\n )\n for (const locale of Object.keys(locales)) {\n pagesPathTmp[locale] = `${pagesPathTmpRoot}_${locale}`\n }\n\n await removePagesPathTmp()\n if (command === 'build') {\n await Promise.all(\n Object.keys(locales)\n .filter((locale) => {\n if (\n redirectDefaultLocale === false ||\n config.output === 'server'\n ) {\n return locale !== defaultLocale\n } else {\n return true\n }\n })\n .map((locale) => fs.copy(pagesPath, pagesPathTmp[locale]))\n )\n }\n\n const entries = fg.stream(included, {\n ignore: excluded,\n onlyFiles: true,\n })\n // typing https://stackoverflow.com/a/68358341\n let entry: string\n // @ts-expect-error: fast-glob stream does not fully align with for-await typings in this environment\n for await (entry of entries) {\n const parsedPath = path.parse(entry)\n const relativePath = path.relative(pagesPath, parsedPath.dir)\n const extname = parsedPath.ext.slice(1).toLowerCase()\n\n // warn on files that cannot be translated with specific and actionable warnings\n // astro pages file types https://docs.astro.build/en/core-concepts/astro-pages/#supported-page-files\n // any file that is not included as an astro page file types, will be automatically warned about by astro\n if (extname !== 'astro') {\n warnIsInvalidPage(\n extname,\n path.join(relativePath, parsedPath.base),\n configSrcDirPathname,\n logger\n )\n continue\n }\n\n for (const locale of Object.keys(locales)) {\n // ignore defaultLocale if redirectDefaultLocale is false or if using SSR\n if (\n (redirectDefaultLocale === false || config.output === 'server') &&\n locale === defaultLocale\n ) {\n continue\n }\n\n const entrypoint =\n command === 'build'\n ? path.join(pagesPathTmp[locale], relativePath, parsedPath.base)\n : path.join(pagesPath, relativePath, parsedPath.base)\n\n const pattern = slash(\n path.join(\n // astro automatically handles prepending `config.base`\n locale,\n relativePath,\n parsedPath.name.endsWith('index') ? '' : parsedPath.name,\n config.build.format === 'directory' ? '/' : ''\n )\n )\n\n injectRoute({\n entrypoint,\n pattern,\n })\n }\n }\n },\n 'astro:build:done': async () => {\n await removePagesPathTmp()\n },\n 'astro:server:done': async () => {\n await removePagesPathTmp()\n },\n },\n }\n}\n\nfunction ensureValidLocales(\n locales: Record<string, string>,\n defaultLocale: string,\n logger: AstroIntegrationLogger\n) {\n if (!Object.keys(locales).includes(defaultLocale)) {\n const errorMessage = `locales ${JSON.stringify(\n locales\n )} does not include \"${defaultLocale}\"`\n logger.error(errorMessage)\n throw new Error(errorMessage)\n }\n}\n\nfunction ensureGlobsHaveConfigSrcDirPathname(\n filePaths: string[],\n configSrcDirPathname: string\n) {\n return filePaths.map((filePath) => {\n filePath = path.normalize(removeLeadingForwardSlashWindows(filePath))\n\n if (filePath.includes(configSrcDirPathname)) {\n filePath = path.relative(configSrcDirPathname, filePath)\n }\n\n // fast-glob prefers unix paths https://www.npmjs.com/package/fast-glob#how-to-write-patterns-on-windows\n filePath = path.posix.join(\n fg.convertPathToPattern(configSrcDirPathname),\n slash(filePath)\n )\n\n return filePath\n })\n}\n\nlet hasWarnedIsInvalidPage = false\nfunction warnIsInvalidPage(\n extname: string,\n filePath: string,\n configSrcDirPathname: string,\n logger: AstroIntegrationLogger\n): boolean {\n // astro pages file types https://docs.astro.build/en/core-concepts/astro-pages/#supported-page-files\n if (['js', 'ts', 'md', 'mdx', 'html'].includes(extname)) {\n if (hasWarnedIsInvalidPage === false) {\n logger.warn(\n `exclude or remove non-astro files from \"${configSrcDirPathname}pages\", as they cannot be translated`\n )\n hasWarnedIsInvalidPage = true\n }\n logger.warn(path.join(configSrcDirPathname, 'pages', filePath))\n return true\n }\n return false\n}\n","export function removeLeadingForwardSlashWindows(path: string) {\n return path.startsWith('/') && path[2] === ':' ? path.substring(1) : path\n}\n","import type { AstroConfig, ValidRedirectStatus } from 'astro'\n\nexport interface UserI18nConfig {\n /**\n * glob pattern(s) to include\n * @defaultValue [\"pages\\/\\*\\*\\/\\*\"]\n */\n include?: string | string[]\n /**\n * glob pattern(s) to exclude\n * @defaultValue [\"pages\\/api\\/\\*\\*\\/\\*\"]\n */\n exclude?: string | string[]\n /**\n * all language locales\n *\n * @example\n * ```ts\n * const locales = {\n * en: \"en-US\", // the `defaultLocale` value must present in `locales` keys\n * es: \"es-ES\",\n * fr: \"fr-CA\",\n * };\n * ```\n */\n locales: Record<string, string>\n /**\n * the default language locale\n *\n * the `defaultLocale` value must present in `locales` keys\n *\n * @example \"en\"\n */\n defaultLocale: string\n /**\n * given the defaultLocale \"en\", whether\n * \"/en/about\" redirects to \"/about\"\n *\n * whether the url with the default locale\n * should redirect to the url without the locale\n *\n * if a status is given, such as 302,\n * redirectDefaultLocale will be truthy,\n * and all redirects will use that status\n *\n * @defaultValue true\n */\n redirectDefaultLocale?: boolean | ValidRedirectStatus\n}\n\nexport type VirtualAstroi18nautConfig = Pick<\n UserI18nConfig,\n 'defaultLocale' | 'locales' | 'redirectDefaultLocale'\n> & {\n BASE_URL: string\n trailingSlash: AstroConfig['trailingSlash']\n build: {\n format: AstroConfig['build']['format']\n }\n}\n\nexport type UserFilterSitemapByDefaultLocaleConfig = Pick<\n UserI18nConfig,\n 'defaultLocale'\n> & {\n base?: string\n}\n\nexport type I18nConfig = Required<UserI18nConfig>\n\n// opposite of RequiredFieldsOnly https://stackoverflow.com/a/68261391\ntype PartialFieldsOnly<T> = {\n [K in keyof T as T[K] extends Required<T>[K] ? never : K]: T[K]\n}\n\n/**\n * The default values for I18nConfig\n */\nexport const defaultI18nConfig: Required<PartialFieldsOnly<UserI18nConfig>> = {\n include: ['pages/**/*'],\n exclude: ['pages/api/**/*'],\n redirectDefaultLocale: 308,\n}\n","import type { AstroConfig, AstroIntegrationLogger } from 'astro'\nimport type { UpdateConfig } from './UpdateConfig'\n\nexport function ensureValidTrailingSlashAndFormat(\n config: AstroConfig,\n updateConfig: UpdateConfig,\n logger: AstroIntegrationLogger\n) {\n if (config.trailingSlash === 'ignore' && config.output === 'static') {\n logger.warn(\n `avoid setting config.trailingSlash = \"ignore\" when config.output = \"static\"`\n )\n logger.warn(\n `config.trailingSlash = \"always\" && config.build.format = \"directory\"`\n )\n logger.warn(\n `config.trailingSlash = \"never\" && config.build.format = \"file\"`\n )\n logger.warn(`setting config.trailingSlash = \"${config.trailingSlash}\"`)\n updateConfig({\n trailingSlash: config.build.format === 'directory' ? 'always' : 'never',\n })\n }\n if (config.trailingSlash === 'always' && config.build.format === 'file') {\n logger.warn(\n `config.trailingSlash = \"always\" must always be used with config.build.format = \"directory\"`\n )\n logger.warn(`setting config.build.format = \"directory\"`)\n updateConfig({\n build: {\n format: 'directory',\n },\n })\n }\n if (config.trailingSlash === 'never' && config.build.format === 'directory') {\n logger.warn(\n `config.trailingSlash = \"never\" must always be used with config.build.format = \"file\"`\n )\n logger.warn(`setting config.build.format = \"file\"`)\n updateConfig({\n build: {\n format: 'file',\n },\n })\n }\n}\n","import type { Plugin } from 'vite'\n\n// documentation https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention\n\nexport function createVirtualPlugin(\n virtualModuleId: string,\n json: unknown\n): Plugin {\n const resolvedVirtualModuleId = '\\0' + virtualModuleId\n\n return {\n name: 'vite-plugin:' + virtualModuleId, // required, will show up in warnings and errors\n resolveId(id: string) {\n if (id === virtualModuleId) {\n return resolvedVirtualModuleId\n }\n return null\n },\n load(id: string) {\n if (id === resolvedVirtualModuleId) {\n return `export default ${JSON.stringify(json)}`\n }\n return null\n },\n }\n}\n","import type { AstroConfig } from 'astro'\nimport { UpdateConfig } from './UpdateConfig'\nimport type {\n I18nConfig,\n VirtualAstroi18nautConfig,\n} from '../../shared/configs'\nimport { createVirtualPlugin } from './createVirtualPlugin'\n\nexport function createVirtualModules(\n config: AstroConfig,\n updateConfig: UpdateConfig,\n i18nConfig: I18nConfig\n): void {\n const virtualAstroi18nautConfig: VirtualAstroi18nautConfig = {\n defaultLocale: i18nConfig.defaultLocale,\n locales: i18nConfig.locales,\n redirectDefaultLocale: i18nConfig.redirectDefaultLocale,\n BASE_URL: getBaseUrl(config),\n trailingSlash: config.trailingSlash,\n build: {\n format: config.build.format,\n },\n }\n\n const virtualPlugin = createVirtualPlugin(\n 'virtual:@mcendon/astro-translate',\n virtualAstroi18nautConfig\n )\n\n updateConfig({\n vite: {\n plugins: [virtualPlugin],\n // worker plugins are separate https://github.com/vitejs/vite/issues/8520\n worker: {\n plugins: () => [virtualPlugin],\n },\n // exclude virtual modules from optimizeDeps https://github.com/storybookjs/builder-vite/issues/311#issuecomment-1092577628\n optimizeDeps: {\n exclude: ['virtual:@mcendon/astro-translate'],\n },\n },\n })\n}\n\nfunction getBaseUrl(config: AstroConfig): string {\n let base = config.base\n\n // astro `BASE_URL` always starts with `/` and respects `config.trailingSlash`\n if (base[0] !== '/') {\n base = '/' + base\n }\n\n // https://docs.astro.build/en/reference/configuration-reference/#base\n // The value of import.meta.env.BASE_URL respects your trailingSlash config\n // and will include a trailing slash\n // if you explicitly include one\n // or if trailingSlash: \"always\" is set.\n // If trailingSlash: \"never\" is set,\n // BASE_URL will not include a trailing slash,\n // even if base includes one.\n if (config.trailingSlash === 'always') {\n if (base.at(-1) !== '/') {\n base = base + '/'\n }\n } else if (config.trailingSlash === 'never') {\n if (base !== '/' && base.at(-1) === '/') {\n base = base.slice(0, -1)\n }\n }\n\n return base\n}\n","import type { AstroConfig, AstroIntegrationLogger } from 'astro'\nimport type { UpdateConfig } from './UpdateConfig'\nimport type { I18nConfig } from '../../shared/configs'\nimport { ensureValidTrailingSlashAndFormat } from './ensureValidTrailingSlashAndFormat'\nimport { createVirtualModules } from './createVirtualModules'\n\nexport async function ensureValidConfigs(\n config: AstroConfig,\n updateConfig: UpdateConfig,\n i18nConfig: I18nConfig,\n logger: AstroIntegrationLogger\n) {\n ensureValidTrailingSlashAndFormat(config, updateConfig, logger)\n createVirtualModules(config, updateConfig, i18nConfig)\n}\n","export function removeHtmlExtension(url: string) {\n return url.endsWith('.html') ? url.slice(0, -'.html'.length) : url\n}\n","import { removeHtmlExtension } from '../edge-runtime/removeHtmlExtension'\nimport type { UserFilterSitemapByDefaultLocaleConfig } from './configs'\n\n// sitemap filter https://docs.astro.build/en/guides/integrations-guide/sitemap/#filter\nexport function filterSitemapByDefaultLocale({\n defaultLocale,\n base: baseUrl = '/',\n}: UserFilterSitemapByDefaultLocaleConfig) {\n // astro `BASE_URL` always starts with `/` and respects `config.trailingSlash`\n if (baseUrl[0] !== '/') {\n baseUrl = '/' + baseUrl\n }\n\n const baseUrlWithoutTrailingSlash =\n baseUrl.at(-1) === '/' ? baseUrl.slice(0, -1) : baseUrl\n\n return function filter(page: string) {\n const pathName = new URL(page).pathname\n const pathNameWithoutHtmlExtension = removeHtmlExtension(pathName)\n\n // remove baseUrlWithoutTrailingSlash from pathNameWithoutBaseUrl\n const pathNameWithoutBaseUrl =\n baseUrl === '/'\n ? pathNameWithoutHtmlExtension\n : pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash, '')\n\n const pathNameWithoutBaseUrlStartsWithDefaultLocale =\n pathNameWithoutBaseUrl.slice(1, 3) === defaultLocale\n\n if (\n pathNameWithoutBaseUrl.length === 3 &&\n pathNameWithoutBaseUrlStartsWithDefaultLocale\n ) {\n return false\n }\n // catch all \"/en/**/*\" urls\n if (\n pathNameWithoutBaseUrl[0] === '/' &&\n pathNameWithoutBaseUrl[3] === '/' &&\n pathNameWithoutBaseUrlStartsWithDefaultLocale\n ) {\n return false\n }\n\n return true\n }\n}\n"],"mappings":"gHAAA,OAAO,SAAU,OACjB,OAAS,kBAAqB,MAE9B,OAAO,OAAQ,YACf,OAAO,OAAQ,WACf,OAAO,UAAW,QCLX,SAAS,iCAAiCA,MAAc,CAC7D,OAAOA,MAAK,WAAW,GAAG,GAAKA,MAAK,CAAC,IAAM,IAAMA,MAAK,UAAU,CA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C,MANE,yBAAuB,SAAW,GAClC,+CAMA,uBAAuB,CAAC,IAAM,KAC9B,uBAAuB,CAAC,IAAM,KAC9B,8CAMJ,EA7BO,SA8BT,CA1CgB","names":["path"]}
@@ -0,0 +1,9 @@
1
+ import type { AstroIntegration } from 'astro';
2
+ import type { UserI18nConfig } from '../shared/configs';
3
+ /**
4
+ * The i18n integration for Astro
5
+ *
6
+ * See the full [@mcendon/astro-translate](https://github.com/mcendon/astro-translate#readme) documentation
7
+ */
8
+ export declare function i18n(userI18nConfig: UserI18nConfig): AstroIntegration;
9
+ //# sourceMappingURL=integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../src/integration/integration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAA0B,MAAM,OAAO,CAAA;AAMrE,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,mBAAmB,CAAA;AAMnE;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,cAAc,EAAE,cAAc,GAAG,gBAAgB,CA0IrE"}
@@ -0,0 +1,2 @@
1
+ "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var middleware_exports={};__export(middleware_exports,{onRequest:()=>onRequest});module.exports=__toCommonJS(middleware_exports);var import_middleware=require("astro/middleware");var import_astro_translate=__toESM(require("virtual:@mcendon/astro-translate"),1),trailingSlash=import_astro_translate.default.trailingSlash,BASE_URL=import_astro_translate.default.BASE_URL?import_astro_translate.default.BASE_URL:"/",defaultLocale=import_astro_translate.default.defaultLocale,locales=import_astro_translate.default.locales,localeKeys=Object.keys(import_astro_translate.default.locales),redirectDefaultLocale=import_astro_translate.default.redirectDefaultLocale,build=import_astro_translate.default.build;function removeTrailingSlash(url){return url.at(-1)==="/"?url.slice(0,-1):url}__name(removeTrailingSlash,"removeTrailingSlash");function resolveTrailingSlash(url){let pathName=typeof url=="string"?url:url.pathname;return trailingSlash==="always"?pathName.at(-1)!=="/"&&(pathName=pathName+"/"):trailingSlash==="never"&&pathName!=="/"&&pathName.at(-1)==="/"&&(pathName=pathName.slice(0,-1)),pathName}__name(resolveTrailingSlash,"resolveTrailingSlash");function removeHtmlExtension(url){return url.endsWith(".html")?url.slice(0,-5):url}__name(removeHtmlExtension,"removeHtmlExtension");var i18nMiddleware=(0,import_middleware.defineMiddleware)((context,next)=>{if(redirectDefaultLocale===!1)return next();let status;typeof redirectDefaultLocale=="number"&&(status=redirectDefaultLocale);let{pathname:pathName,search}=new URL(context.request.url),pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),baseUrlWithoutTrailingSlash=removeTrailingSlash(BASE_URL),pathNameWithoutBaseUrl=BASE_URL==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),pathNameWithoutBaseUrlStartsWithDefaultLocale=pathNameWithoutBaseUrl.slice(1,3)===defaultLocale;return pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithDefaultLocale?context.redirect(resolveTrailingSlash(BASE_URL)+search,status):pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithDefaultLocale?context.redirect(resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl.slice(3))+search,status):next()});var onRequest=i18nMiddleware;0&&(module.exports={onRequest});
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/middleware/index.ts","../../src/edge-runtime/middleware.ts","../../src/edge-runtime/config.ts","../../src/edge-runtime/removeTrailingSlash.ts","../../src/edge-runtime/resolveTrailingSlash.ts","../../src/edge-runtime/removeHtmlExtension.ts"],"sourcesContent":["import { i18nMiddleware } from '../edge-runtime/middleware'\n\nexport const onRequest = i18nMiddleware\n","import type { ValidRedirectStatus } from 'astro'\nimport { defineMiddleware } from 'astro/middleware'\nimport {\n defaultLocale,\n redirectDefaultLocale,\n BASE_URL as baseUrl,\n} from './config'\nimport { removeTrailingSlash } from './removeTrailingSlash'\nimport { resolveTrailingSlash } from './resolveTrailingSlash'\nimport { removeHtmlExtension } from './removeHtmlExtension'\n\nexport const i18nMiddleware = defineMiddleware((context, next) => {\n if (redirectDefaultLocale === false) {\n return next()\n }\n\n let status: ValidRedirectStatus | undefined\n if (typeof redirectDefaultLocale === 'number') {\n status = redirectDefaultLocale\n }\n\n const { pathname: pathName, search } = new URL(context.request.url)\n const pathNameWithoutHtmlExtension = removeHtmlExtension(pathName)\n\n const baseUrlWithoutTrailingSlash = removeTrailingSlash(baseUrl)\n\n // remove baseUrlWithoutTrailingSlash from pathNameWithoutBaseUrl\n const pathNameWithoutBaseUrl =\n baseUrl === '/'\n ? pathNameWithoutHtmlExtension\n : pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash, '')\n\n const pathNameWithoutBaseUrlStartsWithDefaultLocale =\n pathNameWithoutBaseUrl.slice(1, 3) === defaultLocale\n\n // avoid catching urls that start with \"/en\" like \"/enigma\"\n if (\n pathNameWithoutBaseUrl.length === 3 &&\n pathNameWithoutBaseUrlStartsWithDefaultLocale\n ) {\n return context.redirect(resolveTrailingSlash(baseUrl) + search, status)\n }\n // catch all \"/en/**/*\" urls\n if (\n pathNameWithoutBaseUrl[0] === '/' &&\n pathNameWithoutBaseUrl[3] === '/' &&\n pathNameWithoutBaseUrlStartsWithDefaultLocale\n ) {\n return context.redirect(\n resolveTrailingSlash(\n baseUrlWithoutTrailingSlash + pathNameWithoutBaseUrl.slice(3)\n ) + search,\n status\n )\n }\n // otherwise, it must be a defaultLocale or other url\n return next()\n})\n","import virtualConfig from 'virtual:@mcendon/astro-translate'\n\nexport const trailingSlash = virtualConfig.trailingSlash\nexport const BASE_URL = virtualConfig.BASE_URL ? virtualConfig.BASE_URL : '/'\nexport const defaultLocale = virtualConfig.defaultLocale\nexport const locales = virtualConfig.locales\nexport const localeKeys = Object.keys(virtualConfig.locales)\nexport const redirectDefaultLocale = virtualConfig.redirectDefaultLocale\nexport const build = virtualConfig.build\n","export function removeTrailingSlash(url: string) {\n return url.at(-1) === '/' ? url.slice(0, -1) : url\n}\n","import { trailingSlash } from './config'\n\nexport function resolveTrailingSlash(url: URL | string): string {\n let pathName = typeof url === 'string' ? url : url.pathname\n\n if (trailingSlash === 'always') {\n if (pathName.at(-1) !== '/') {\n pathName = pathName + '/'\n }\n } else if (trailingSlash === 'never') {\n if (pathName !== '/' && pathName.at(-1) === '/') {\n pathName = pathName.slice(0, -1)\n }\n }\n return pathName\n}\n","export function removeHtmlExtension(url: string) {\n return url.endsWith('.html') ? url.slice(0, -'.html'.length) : url\n}\n"],"mappings":"q+BAAA,iICCA,sBAAiC,4BCDjC,2BAA0B,uDAEb,cAAgB,uBAAAA,QAAc,cAC9B,SAAW,uBAAAA,QAAc,SAAW,uBAAAA,QAAc,SAAW,IAC7D,cAAgB,uBAAAA,QAAc,cAC9B,QAAU,uBAAAA,QAAc,QACxB,WAAa,OAAO,KAAK,uBAAAA,QAAc,OAAO,EAC9C,sBAAwB,uBAAAA,QAAc,sBACtC,MAAQ,uBAAAA,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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,mCAAiB,CAAA"}
@@ -0,0 +1,2 @@
1
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{defineMiddleware}from"astro/middleware";import virtualConfig from"virtual:@mcendon/astro-translate";var trailingSlash=virtualConfig.trailingSlash,BASE_URL=virtualConfig.BASE_URL?virtualConfig.BASE_URL:"/",defaultLocale=virtualConfig.defaultLocale,locales=virtualConfig.locales,localeKeys=Object.keys(virtualConfig.locales),redirectDefaultLocale=virtualConfig.redirectDefaultLocale,build=virtualConfig.build;function removeTrailingSlash(url){return url.at(-1)==="/"?url.slice(0,-1):url}__name(removeTrailingSlash,"removeTrailingSlash");function resolveTrailingSlash(url){let pathName=typeof url=="string"?url:url.pathname;return trailingSlash==="always"?pathName.at(-1)!=="/"&&(pathName=pathName+"/"):trailingSlash==="never"&&pathName!=="/"&&pathName.at(-1)==="/"&&(pathName=pathName.slice(0,-1)),pathName}__name(resolveTrailingSlash,"resolveTrailingSlash");function removeHtmlExtension(url){return url.endsWith(".html")?url.slice(0,-5):url}__name(removeHtmlExtension,"removeHtmlExtension");var i18nMiddleware=defineMiddleware((context,next)=>{if(redirectDefaultLocale===!1)return next();let status;typeof redirectDefaultLocale=="number"&&(status=redirectDefaultLocale);let{pathname:pathName,search}=new URL(context.request.url),pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),baseUrlWithoutTrailingSlash=removeTrailingSlash(BASE_URL),pathNameWithoutBaseUrl=BASE_URL==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),pathNameWithoutBaseUrlStartsWithDefaultLocale=pathNameWithoutBaseUrl.slice(1,3)===defaultLocale;return pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithDefaultLocale?context.redirect(resolveTrailingSlash(BASE_URL)+search,status):pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithDefaultLocale?context.redirect(resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl.slice(3))+search,status):next()});var onRequest=i18nMiddleware;export{onRequest};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/edge-runtime/middleware.ts","../../src/edge-runtime/config.ts","../../src/edge-runtime/removeTrailingSlash.ts","../../src/edge-runtime/resolveTrailingSlash.ts","../../src/edge-runtime/removeHtmlExtension.ts","../../src/middleware/index.ts"],"sourcesContent":["import type { ValidRedirectStatus } from 'astro'\nimport { defineMiddleware } from 'astro/middleware'\nimport {\n defaultLocale,\n redirectDefaultLocale,\n BASE_URL as baseUrl,\n} from './config'\nimport { removeTrailingSlash } from './removeTrailingSlash'\nimport { resolveTrailingSlash } from './resolveTrailingSlash'\nimport { removeHtmlExtension } from './removeHtmlExtension'\n\nexport const i18nMiddleware = defineMiddleware((context, next) => {\n if (redirectDefaultLocale === false) {\n return next()\n }\n\n let status: ValidRedirectStatus | undefined\n if (typeof redirectDefaultLocale === 'number') {\n status = redirectDefaultLocale\n }\n\n const { pathname: pathName, search } = new URL(context.request.url)\n const pathNameWithoutHtmlExtension = removeHtmlExtension(pathName)\n\n const baseUrlWithoutTrailingSlash = removeTrailingSlash(baseUrl)\n\n // remove baseUrlWithoutTrailingSlash from pathNameWithoutBaseUrl\n const pathNameWithoutBaseUrl =\n baseUrl === '/'\n ? pathNameWithoutHtmlExtension\n : pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash, '')\n\n const pathNameWithoutBaseUrlStartsWithDefaultLocale =\n pathNameWithoutBaseUrl.slice(1, 3) === defaultLocale\n\n // avoid catching urls that start with \"/en\" like \"/enigma\"\n if (\n pathNameWithoutBaseUrl.length === 3 &&\n pathNameWithoutBaseUrlStartsWithDefaultLocale\n ) {\n return context.redirect(resolveTrailingSlash(baseUrl) + search, status)\n }\n // catch all \"/en/**/*\" urls\n if (\n pathNameWithoutBaseUrl[0] === '/' &&\n pathNameWithoutBaseUrl[3] === '/' &&\n pathNameWithoutBaseUrlStartsWithDefaultLocale\n ) {\n return context.redirect(\n resolveTrailingSlash(\n baseUrlWithoutTrailingSlash + pathNameWithoutBaseUrl.slice(3)\n ) + search,\n status\n )\n }\n // otherwise, it must be a defaultLocale or other url\n return next()\n})\n","import virtualConfig from 'virtual:@mcendon/astro-translate'\n\nexport const trailingSlash = virtualConfig.trailingSlash\nexport const BASE_URL = virtualConfig.BASE_URL ? virtualConfig.BASE_URL : '/'\nexport const defaultLocale = virtualConfig.defaultLocale\nexport const locales = virtualConfig.locales\nexport const localeKeys = Object.keys(virtualConfig.locales)\nexport const redirectDefaultLocale = virtualConfig.redirectDefaultLocale\nexport const build = virtualConfig.build\n","export function removeTrailingSlash(url: string) {\n return url.at(-1) === '/' ? url.slice(0, -1) : url\n}\n","import { trailingSlash } from './config'\n\nexport function resolveTrailingSlash(url: URL | string): string {\n let pathName = typeof url === 'string' ? url : url.pathname\n\n if (trailingSlash === 'always') {\n if (pathName.at(-1) !== '/') {\n pathName = pathName + '/'\n }\n } else if (trailingSlash === 'never') {\n if (pathName !== '/' && pathName.at(-1) === '/') {\n pathName = pathName.slice(0, -1)\n }\n }\n return pathName\n}\n","export function removeHtmlExtension(url: string) {\n return url.endsWith('.html') ? url.slice(0, -'.html'.length) : url\n}\n","import { i18nMiddleware } from '../edge-runtime/middleware'\n\nexport const onRequest = i18nMiddleware\n"],"mappings":"gHACA,OAAS,qBAAwB,mBCDjC,OAAO,kBAAmB,mCAEnB,IAAM,cAAgB,cAAc,cAC9B,SAAW,cAAc,SAAW,cAAc,SAAW,IAC7D,cAAgB,cAAc,cAC9B,QAAU,cAAc,QACxB,WAAa,OAAO,KAAK,cAAc,OAAO,EAC9C,sBAAwB,cAAc,sBACtC,MAAQ,cAAc,MCR5B,SAA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+ * @defaultValue ["pages\/\*\*\/\*"]
6
+ */
7
+ include?: string | string[];
8
+ /**
9
+ * glob pattern(s) to exclude
10
+ * @defaultValue ["pages\/api\/\*\*\/\*"]
11
+ */
12
+ exclude?: string | string[];
13
+ /**
14
+ * all language locales
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const locales = {
19
+ * en: "en-US", // the `defaultLocale` value must present in `locales` keys
20
+ * es: "es-ES",
21
+ * fr: "fr-CA",
22
+ * };
23
+ * ```
24
+ */
25
+ locales: Record<string, string>;
26
+ /**
27
+ * the default language locale
28
+ *
29
+ * the `defaultLocale` value must present in `locales` keys
30
+ *
31
+ * @example "en"
32
+ */
33
+ defaultLocale: string;
34
+ /**
35
+ * given the defaultLocale "en", whether
36
+ * "/en/about" redirects to "/about"
37
+ *
38
+ * whether the url with the default locale
39
+ * should redirect to the url without the locale
40
+ *
41
+ * if a status is given, such as 302,
42
+ * redirectDefaultLocale will be truthy,
43
+ * and all redirects will use that status
44
+ *
45
+ * @defaultValue true
46
+ */
47
+ redirectDefaultLocale?: boolean | ValidRedirectStatus;
48
+ }
49
+ export type VirtualAstroi18nautConfig = Pick<UserI18nConfig, 'defaultLocale' | 'locales' | 'redirectDefaultLocale'> & {
50
+ BASE_URL: string;
51
+ trailingSlash: AstroConfig['trailingSlash'];
52
+ build: {
53
+ format: AstroConfig['build']['format'];
54
+ };
55
+ };
56
+ export type UserFilterSitemapByDefaultLocaleConfig = Pick<UserI18nConfig, 'defaultLocale'> & {
57
+ base?: string;
58
+ };
59
+ export type I18nConfig = Required<UserI18nConfig>;
60
+ type PartialFieldsOnly<T> = {
61
+ [K in keyof T as T[K] extends Required<T>[K] ? never : K]: T[K];
62
+ };
63
+ /**
64
+ * The default values for I18nConfig
65
+ */
66
+ export declare const defaultI18nConfig: Required<PartialFieldsOnly<UserI18nConfig>>;
67
+ export {};
68
+ //# sourceMappingURL=configs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configs.d.ts","sourceRo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AAC,cAAc,CAAC,CAIzE,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { UserFilterSitemapByDefaultLocaleConfig } from './configs';
2
+ export declare function filterSitemapByDefaultLocale({ defaultLocale, base: baseUrl, }: UserFilterSitemapByDefaultLocaleConfig): (page: string) => boolean;
3
+ //# sourceMappingURL=filterSitemapByDefaultLocale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterSitemapByDefaultLocale.d.ts","sourceRoot":"","sources":["../../src/shared/filterSitemapByDefaultLocale.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sCAAsC,EAAE,MAAM,WAAW,CAAA;AAGvE,wBAAgB,4BAA4B,CAAC,EAC3C,aAAa,EACb,IAAI,EAAE,OAAa,GACpB,EAAE,sCAAsC,IAShB,MAAM,MAAM,aA8BpC"}
@@ -0,0 +1,4 @@
1
+ export { filterSitemapByDefaultLocale } from './filterSitemapByDefaultLocale';
2
+ export { defaultI18nConfig } from './configs';
3
+ export type { UserI18nConfig, UserFilterSitemapByDefaultLocaleConfig as UserFilterSitemapByDefaultLocaleConfig, VirtualAstroi18nautConfig, } from './configs';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAA;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAC7C,YAAY,EACV,cAAc,EACd,sCAAsC,IAAI,sCAAsC,EAChF,yBAAyB,GAC1B,MAAM,WAAW,CAAA"}
package/package.json ADDED
@@ -0,0 +1,98 @@
1
+ {
2
+ "name": "@mcendon/astro-translate",
3
+ "version": "1.0.0-RC1",
4
+ "private": false,
5
+ "description": "The translate integration for Astro",
6
+ "keywords": [
7
+ "astro-translate",
8
+ "astro",
9
+ "astrojs",
10
+ "withastro",
11
+ "astro-integration",
12
+ "astro-component",
13
+ "i18n",
14
+ "locales",
15
+ "defaultLocale",
16
+ "languages",
17
+ "defaultLanguage",
18
+ "defaultLang",
19
+ "translate"
20
+ ],
21
+ "homepage": "https://github.com/mcendon/astro-translate",
22
+ "bugs": "https://github.com/mcendon/astro-translate/issues",
23
+ "repository": "git@github.com:mcendon/astro-translate.git",
24
+ "license": "MIT",
25
+ "author": "Mauro Cendón Hidalgo",
26
+ "sideEffects": false,
27
+ "type": "module",
28
+ "typesVersions": {
29
+ "*": {
30
+ "*": [
31
+ "./dist/edge-runtime/index.d.ts"
32
+ ],
33
+ "integration": [
34
+ "./dist/integration/index.d.ts"
35
+ ],
36
+ "middleware": [
37
+ "./dist/middleware/index.d.ts"
38
+ ]
39
+ }
40
+ },
41
+ "exports": {
42
+ ".": {
43
+ "types": "./dist/edge-runtime/index.d.ts",
44
+ "require": "./dist/edge-runtime/index.cjs",
45
+ "import": "./dist/edge-runtime/index.js"
46
+ },
47
+ "./integration": {
48
+ "types": "./dist/integration/index.d.ts",
49
+ "require": "./dist/integration/index.cjs",
50
+ "import": "./dist/integration/index.js"
51
+ },
52
+ "./middleware": {
53
+ "types": "./dist/middleware/index.d.ts",
54
+ "require": "./dist/middleware/index.cjs",
55
+ "import": "./dist/middleware/index.js"
56
+ },
57
+ "./package.json": "./package.json"
58
+ },
59
+ "files": [
60
+ "dist"
61
+ ],
62
+ "scripts": {
63
+ "build": "tsup-node",
64
+ "watch": "tsup-node --watch",
65
+ "lint": "eslint .",
66
+ "prepare": "husky",
67
+ "prettier:fix": "prettier --write ./src"
68
+ },
69
+ "dependencies": {
70
+ "dedent": "^1.7.2",
71
+ "fast-glob": "^3.3.3",
72
+ "fs-extra": "^11.3.6",
73
+ "slash": "^5.1.0"
74
+ },
75
+ "devDependencies": {
76
+ "@eslint/js": "^10.0.1",
77
+ "@types/dedent": "^0.7.2",
78
+ "@types/fs-extra": "^11.0.4",
79
+ "@types/node": "^22.10.3",
80
+ "eslint": "^10.6.0",
81
+ "husky": "^9.1.7",
82
+ "lint-staged": "^17.0.8",
83
+ "prettier": "^3.9.4",
84
+ "tsup": "^8.3.5",
85
+ "typescript": "^6.0.3",
86
+ "typescript-eslint": "^8.62.1",
87
+ "vite": "^8.1.3"
88
+ },
89
+ "peerDependencies": {
90
+ "astro": "^7.0.0"
91
+ },
92
+ "lint-staged": {
93
+ "**/*.{js,ts}": "eslint --max-warnings 0"
94
+ },
95
+ "engines": {
96
+ "node": ">=22.12.0"
97
+ }
98
+ }