@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
package/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ MIT License
2
+
3
+ Original project jlarmstrongiv/astro-i18n-aut:
4
+ Copyright (c) 2023–present John L. Armstrong IV https://github.com/jlarmstrongiv/astro-i18n-aut
5
+
6
+ Fork project @mcendon/astro-translate:
7
+ Copyright (c) 2026-present Mauro Cendón Hidalgo https://github.com/mcendon/astro-translate
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,268 @@
1
+ # `astro-translate` The i18n integration for Astro 🧑‍🚀
2
+
3
+ <p align="center">
4
+ <a href="https://github.com/mcendon/astro-translate#readme" target="_blank">
5
+ <picture>
6
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mcendon/astro-translate/main/logos/astro-translate-dark.png">
7
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/mcendon/astro-translate/main/logos/astro-translate-light.png">
8
+ <img alt="@mcendon/astro-translate" src="https://raw.githubusercontent.com/mcendon/astro-translate/HEAD/logos/astro-translate-light.png" width="400" height="225" style="max-width: 100%;">
9
+ </picture>
10
+ </a>
11
+ </p>
12
+
13
+ <p align="center">
14
+ Built with ❤️ for all Astro crewmates 🧑‍🚀
15
+ </p>
16
+
17
+ <p align="center">
18
+ <a href="https://www.npmjs.com/package/@mcendon/astro-translate"><img src="https://img.shields.io/npm/dt/@mcendon/astro-translate.svg" alt="Total Downloads"></a>
19
+ <!-- https://github.com/@mcendon/astro-translate/@mcendon/astro-translate/releases -->
20
+ <a href="https://www.npmjs.com/package/@mcendon/astro-translate?activeTab=versions"><img src="https://img.shields.io/npm/v/@mcendon/astro-translate.svg" alt="Latest Release"></a>
21
+ <a href="https://github.com/mcendon/astro-translate/blob/main/LICENSE.md"><img src="https://img.shields.io/npm/l/@mcendon/astro-translate.svg" alt="License"></a>
22
+ </p>
23
+
24
+ ---
25
+
26
+ ## Motivation
27
+
28
+ Provide an internationalization (i18n) integration for Astro that:
29
+
30
+ - Supports the `defaultLocale`
31
+ - Avoids template file duplication
32
+ - Is adapter agnostic
33
+ - Is UI framework agnostic
34
+ - Is compatible with [`@astrojs/sitemap`](https://www.npmjs.com/package/@astrojs/sitemap)
35
+
36
+ ## Quick start
37
+
38
+ ### Install
39
+
40
+ Install via [npm](https://www.npmjs.com/package/@mcendon/astro-translate):
41
+
42
+ ```shell
43
+ npm install @mcendon/astro-translate
44
+ ```
45
+
46
+ ### Configure
47
+
48
+ In your Astro [config](https://docs.astro.build/en/guides/configuring-astro/#supported-config-file-types) file:
49
+
50
+ ```ts
51
+ import { defineConfig } from 'astro/config'
52
+ import {
53
+ i18n,
54
+ filterSitemapByDefaultLocale,
55
+ } from '@mcendon/astro-translate/integration'
56
+ import sitemap from '@astrojs/sitemap'
57
+
58
+ const defaultLocale = 'en'
59
+ const locales = {
60
+ en: 'en-US', // the `defaultLocale` value must present in `locales` keys
61
+ es: 'es-ES',
62
+ fr: 'fr-CA',
63
+ }
64
+
65
+ export default defineConfig({
66
+ site: 'https://example.com/',
67
+ trailingSlash: 'always',
68
+ build: {
69
+ format: 'directory',
70
+ },
71
+ integrations: [
72
+ i18n({
73
+ locales,
74
+ defaultLocale,
75
+ }),
76
+ sitemap({
77
+ i18n: {
78
+ locales,
79
+ defaultLocale,
80
+ },
81
+ filter: filterSitemapByDefaultLocale({ defaultLocale }),
82
+ }),
83
+ ],
84
+ })
85
+ ```
86
+
87
+ In your `.gitignore` file:
88
+
89
+ ```gitignore
90
+ astro_tmp_pages_*
91
+ ```
92
+
93
+ ### Usage
94
+
95
+ Now that you have set up the config, each `.astro` page will have additional renders with your other languages. For example, `src/pages/about.astro` will render as:
96
+
97
+ - `/about/`
98
+ - `/es/about/`
99
+ - `/fr/about/`
100
+
101
+ If you have enabled `redirectDefaultLocale` (`true` by default), redirects will be:
102
+
103
+ - `/en/about/` => `/about/`
104
+
105
+ Please note that the `getStaticPaths()` function will only run once. This limitation means that you cannot have translated urls, such as `/es/acerca-de/` for `/about/`. However, it also ensures compatibility with [`@astrojs/sitemap`](https://www.npmjs.com/package/@astrojs/sitemap).
106
+
107
+ The Astro frontmatter and page content is re-run for every translated page. For example, the `Astro.url.pathname` will be:
108
+
109
+ - `/about/`
110
+ - `/es/about/`
111
+ - `/fr/about/`
112
+
113
+ It is up to you to detect which language is being rendered. You can use Astro [content collections](https://docs.astro.build/en/guides/content-collections/) or any i18n UI framework, such as [`react-i18next`](https://www.npmjs.com/package/react-i18next), for your translations. Here is a pure `Hello World` example:
114
+
115
+ ```astro
116
+ ---
117
+ import { getLocale } from "@mcendon/astro-translate";
118
+ import Layout from "../layouts/Layout.astro";
119
+
120
+ const locale = getLocale(Astro.url);
121
+
122
+ let title: string;
123
+ switch (locale) {
124
+ case "es":
125
+ title = "¡Hola Mundo!";
126
+ break;
127
+ case "fr":
128
+ title = "Bonjour Monde!";
129
+ break;
130
+ default:
131
+ title = "Hello World!";
132
+ }
133
+ ---
134
+
135
+ <Layout title={title}>
136
+ <h1>{title}</h1>
137
+ </Layout>
138
+ ```
139
+
140
+ Several helper functions are included to make handling locales easier.
141
+
142
+ ### Astro config options
143
+
144
+ Please see the official Astro docs for more details:
145
+
146
+ - [`site`](https://docs.astro.build/en/reference/configuration-reference/#site)
147
+ - [`trailingSlash`](https://docs.astro.build/en/reference/configuration-reference/#trailingslash)
148
+ - [`format`](https://docs.astro.build/en/reference/configuration-reference/#buildformat)
149
+
150
+ You must set either:
151
+
152
+ - ```js
153
+ {
154
+ site: "https://example.com/",
155
+ trailingSlash: "always",
156
+ build: {
157
+ format: "directory",
158
+ },
159
+ }
160
+ ```
161
+
162
+ - ```js
163
+ {
164
+ site: "https://example.com",
165
+ trailingSlash: "never",
166
+ build: {
167
+ format: "file",
168
+ },
169
+ }
170
+ ```
171
+
172
+ All these options are related and must be set together. They affect whether your urls are:
173
+
174
+ - `/about/`
175
+ - `/about`
176
+
177
+ If you choose `/about/`, then `/about` will 404 and vice versa.
178
+
179
+ ### Integration options
180
+
181
+ - `locales`: A record of all language locales.
182
+ - `defaultLocale`: The default language locale. The value must present in `locales` keys.
183
+ - `redirectDefaultLocale` - Assuming the `defaultLocale: "en"`, whether `/en/about/` redirects to `/about/` (default: `308`).
184
+ - `include`: Glob pattern(s) to include (default: `["pages/**/*"]`).
185
+ - `exclude`: Glob pattern(s) to exclude (default: `["pages/api/**/*"]`).
186
+
187
+ ### Compatibility
188
+
189
+ #### Page file types
190
+
191
+ Other Astro page file types:
192
+
193
+ - ✅ `.astro`
194
+ - ❌ `.md`
195
+ - ❌ `.mdx` (with the MDX Integration installed)
196
+ - ❌ `.html`
197
+ - ❌ `.js` / `.ts` (as endpoints)
198
+
199
+ cannot be translated. If you choose to use them in the `pages` directory, please add them to the ignore glob patterns. For example:
200
+
201
+ ```js
202
+ ;['pages/api/**/*', 'pages/**/*.md']
203
+ ```
204
+
205
+ #### Excluding pages
206
+
207
+ In Astro, the [docs](https://docs.astro.build/en/core-concepts/routing/#excluding-pages) state:
208
+
209
+ > You can exclude pages or directories from being built by prefixing their names with an underscore (_). Files with the _ prefix won’t be recognized by the router and won’t be placed into the dist/ directory.
210
+ >
211
+ > You can use this to temporarily disable pages, and also to put tests, utilities, and components in the same folder as their related pages.
212
+
213
+ Unfortunately, this [excluding pages](https://docs.astro.build/en/core-concepts/routing/#excluding-pages) feature is not supported. Please only keep pages in your pages directory.
214
+
215
+ You can still exclude pages prefixed with an underscore (`_`) by adding `pages/**/_*` to the ignore glob patterns:
216
+
217
+ ```js
218
+ ;['pages/api/**/*', 'pages/**/_*']
219
+ ```
220
+
221
+ #### Markdown
222
+
223
+ For `.md` and `.mdx`, use Astro [Content](https://docs.astro.build/en/guides/content-collections/#organizing-with-subdirectories) [Collections](https://docs.astro.build/en/recipes/i18n/#use-collections-for-translated-content).
224
+
225
+ With this library and Astro Content Collections, you can keep your Markdown separate and organized in `content`, while using `pages/blog/index.astro` and `pages/blog/[slug].astro` to render all of your content, even with a `defaultLocale`! Here is an example folder structure:
226
+
227
+ ```
228
+ .
229
+ └── astro-project/
230
+ └── src/
231
+ ├── pages/
232
+ │ └── blog/
233
+ │ ├── index.astro
234
+ │ └── [id].astro
235
+ └── content/
236
+ └── blog/
237
+ ├── en/
238
+ │ ├── post-1.md
239
+ │ └── post-2.md
240
+ ├── es/
241
+ │ ├── post-1.md
242
+ │ └── post-2.md
243
+ └── fr/
244
+ ├── post-1.md
245
+ └── post-2.md
246
+ ```
247
+
248
+ #### UI frameworks
249
+
250
+ Astro does not support `.tsx` or `.jsx` as page file types.
251
+
252
+ For UI frameworks like React and Vue, use them how you [normally](https://docs.astro.build/en/core-concepts/framework-components/) would with Astro by importing them as components.
253
+
254
+ Feel free to pass the translated content `title={t('title')}` or locale `locale={locale}` as props.
255
+
256
+ #### Endpoints
257
+
258
+ By default, all pages in `pages/api/**/*` are ignored.
259
+
260
+ For `.ts` and `.js` endpoints, how you handle multiple locales is up to you. As endpoints are not user-facing and there are many different ways to use endpoints, we leave the implementation up to your preferences.
261
+
262
+ ## License
263
+
264
+ MIT Licensed
265
+
266
+ ## Contributing
267
+
268
+ PRs welcome! Thank you for your help. Read more in the [contributing guide](https://github.com/mcendon/astro-translate/blob/main/CONTRIBUTING.md) for reporting bugs and making PRs.
@@ -0,0 +1,2 @@
1
+ export declare function removeLeadingForwardSlashWindows(path: string): string;
2
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../../src/astro/internal-helpers/path.ts"],"names":[],"mappings":"AAAA,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,MAAM,UAE5D"}
@@ -0,0 +1,10 @@
1
+ export declare const trailingSlash: "always" | "never" | "ignore";
2
+ export declare const BASE_URL: string;
3
+ export declare const defaultLocale: string;
4
+ export declare const locales: Record<string, string>;
5
+ export declare const localeKeys: string[];
6
+ export declare const redirectDefaultLocale: boolean | 301 | 302 | 303 | 307 | 308 | 300 | 304 | undefined;
7
+ export declare const build: {
8
+ format: import("astro").AstroConfig["build"]["format"];
9
+ };
10
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/config.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,+BAA8B,CAAA;AACxD,eAAO,MAAM,QAAQ,QAAwD,CAAA;AAC7E,eAAO,MAAM,aAAa,QAA8B,CAAA;AACxD,eAAO,MAAM,OAAO,wBAAwB,CAAA;AAC5C,eAAO,MAAM,UAAU,UAAqC,CAAA;AAC5D,eAAO,MAAM,qBAAqB,+DAAsC,CAAA;AACxE,eAAO,MAAM,KAAK;YACs3B,oCAAqB;CADr3B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare function filterCollectionByDefaultLocale(entry: unknown): boolean;
2
+ //# sourceMappingURL=filterCollectionByDefaultLocale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterCollectionByDefaultLocale.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/filterCollectionByDefaultLocale.ts"],"names":[],"mappings":"AAEA,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,OAAO,WAY7D"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @returns url with chosen locale prefix
3
+ * * @example
4
+ * ```ts
5
+ * getAllLocaleUrls("/es/about") // { en: "/about", "es": "/es/about" }
6
+ * ```
7
+ * @example
8
+ * ```ts
9
+ * getAllLocaleUrls("/about") // { en: "/about", "es": "/es/about" }
10
+ * ```
11
+ */
12
+ export declare function getAllLocaleUrls(url: URL | string): Record<string, string>;
13
+ //# sourceMappingURL=getAllLocaleUrls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAllLocaleUrls.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/getAllLocaleUrls.ts"],"names":[],"mappings":"AASA;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmE1E"}
@@ -0,0 +1,6 @@
1
+ export declare function getCollectionParamsSlug(entries: unknown[]): {
2
+ params: {
3
+ slug: string;
4
+ };
5
+ }[];
6
+ //# sourceMappingURL=getCollectionParamsSlug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCollectionParamsSlug.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/getCollectionParamsSlug.ts"],"names":[],"mappings":"AAEA,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE;YACxB;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;IAgBjD"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @returns locale key
3
+ * @example
4
+ * ```ts
5
+ * getLocale("/es/about") // "es"
6
+ * ```
7
+ * @example
8
+ * ```ts
9
+ * getLocale("/about") // "en"
10
+ * ```
11
+ */
12
+ export declare function getLocale(url: URL | string): string;
13
+ //# sourceMappingURL=getLocale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLocale.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/getLocale.ts"],"names":[],"mappings":"AASA;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,CAoCnD"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @returns url with chosen locale prefix
3
+ * * @example
4
+ * ```ts
5
+ * getLocaleUrl("/es/about", "en") // "/about"
6
+ * ```
7
+ * * @example
8
+ * ```ts
9
+ * getLocaleUrl("/es/about", "fr") // "/fr/about"
10
+ * ```
11
+ * @example
12
+ * ```ts
13
+ * getLocaleUrl("/about", "es") // "/es/about"
14
+ * ```
15
+ */
16
+ /**
17
+ * @returns url with chosen locale prefix
18
+ * * @example
19
+ * ```ts
20
+ * getLocaleUrl("/es/about", "en") // "/about"
21
+ * ```
22
+ * * @example
23
+ * ```ts
24
+ * getLocaleUrl("/es/about", "fr") // "/fr/about"
25
+ * ```
26
+ * @example
27
+ * ```ts
28
+ * getLocaleUrl("/about", "es") // "/es/about"
29
+ * ```
30
+ */
31
+ export declare function getLocaleUrl(url: URL | string, locale: string): string;
32
+ //# sourceMappingURL=getLocaleUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLocaleUrl.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/getLocaleUrl.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;GAcG;AACH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CA0DtE"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @returns locale prefix or an empty string if defaultLocale
3
+ * @example
4
+ * ```ts
5
+ * getLocaleUrlPrefix("/es/about") // "/es"
6
+ * ```
7
+ * @example
8
+ * ```ts
9
+ * getLocale("/about") // ""
10
+ * ```
11
+ */
12
+ export declare function getLocaleUrlPrefix(url: URL | string): string;
13
+ //# sourceMappingURL=getLocaleUrlPrefix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLocaleUrlPrefix.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/getLocaleUrlPrefix.ts"],"names":[],"mappings":"AASA;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,CAmC5D"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Helper factory that takes a locale and returns a translation function.
3
+ *
4
+ * @param locale - The locale code (e.g. "en", "es")
5
+ * @returns The translation function `t`
6
+ */
7
+ export declare function getTranslateHelper(locale: string): (key: string, params?: Record<string, string | number>) => string;
8
+ //# sourceMappingURL=getTranslateHelper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getTranslateHelper.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/getTranslateHelper.ts"],"names":[],"mappings":"AAkEA;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,IAU7C,KAAK,MAAM,EACX,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,KACvC,MAAM,CAqBV"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @returns url without locale prefix, "/es/about" => "/about"
3
+ */
4
+ export declare function getUrlWithoutLocale(url: URL | string): string;
5
+ //# sourceMappingURL=getUrlWithoutLocale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUrlWithoutLocale.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/getUrlWithoutLocale.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,CAuC7D"}
@@ -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 edge_runtime_exports={};__export(edge_runtime_exports,{BASE_URL:()=>BASE_URL,build:()=>build,defaultI18nConfig:()=>defaultI18nConfig,defaultLocale:()=>defaultLocale,filterCollectionByDefaultLocale:()=>filterCollectionByDefaultLocale,getAllLocaleUrls:()=>getAllLocaleUrls,getCollectionParamsSlug:()=>getCollectionParamsSlug,getLocale:()=>getLocale,getLocaleUrl:()=>getLocaleUrl,getLocaleUrlPrefix:()=>getLocaleUrlPrefix,getTranslateHelper:()=>getTranslateHelper,getUrlWithoutLocale:()=>getUrlWithoutLocale,localeKeys:()=>localeKeys,locales:()=>locales,resolveTrailingSlash:()=>resolveTrailingSlash,trailingSlash:()=>trailingSlash});module.exports=__toCommonJS(edge_runtime_exports);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 filterCollectionByDefaultLocale(entry){return!!(typeof entry=="object"&&entry!==null&&"slug"in entry&&typeof entry.slug=="string"&&entry.slug.startsWith(defaultLocale+"/"))}__name(filterCollectionByDefaultLocale,"filterCollectionByDefaultLocale");function getCollectionParamsSlug(entries){return entries.reduce((accumulator,entry)=>(typeof entry=="object"&&entry!==null&&"slug"in entry&&typeof entry.slug=="string"&&accumulator.push({params:{slug:entry.slug.replace(defaultLocale+"/","")}}),accumulator),[])}__name(getCollectionParamsSlug,"getCollectionParamsSlug");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 removeTrailingSlash(url){return url.at(-1)==="/"?url.slice(0,-1):url}__name(removeTrailingSlash,"removeTrailingSlash");function removeHtmlExtension(url){return url.endsWith(".html")?url.slice(0,-5):url}__name(removeHtmlExtension,"removeHtmlExtension");function getAllLocaleUrls(url){let pathName=typeof url=="string"?url:url.pathname,pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),baseUrlWithoutTrailingSlash=removeTrailingSlash(BASE_URL),pathNameWithoutBaseUrl=BASE_URL==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),possibleLocaleKey=pathNameWithoutBaseUrl.slice(1,3),pathNameWithoutBaseUrlStartsWithLocale=localeKeys.filter(key=>key!==defaultLocale).includes(possibleLocaleKey);return pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithLocale?{...localeKeys.reduce((record,locale)=>(record[locale]=resolveTrailingSlash(baseUrlWithoutTrailingSlash+"/"+locale+"/"),record),{}),[defaultLocale]:resolveTrailingSlash(BASE_URL)}:pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithLocale?{...localeKeys.reduce((record,locale)=>(record[locale]=resolveTrailingSlash(baseUrlWithoutTrailingSlash+"/"+locale+pathNameWithoutBaseUrl.slice(3)),record),{}),[defaultLocale]:resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl.slice(3))}:{...localeKeys.reduce((record,locale)=>(record[locale]=resolveTrailingSlash(baseUrlWithoutTrailingSlash+"/"+locale+pathNameWithoutBaseUrl),record),{}),[defaultLocale]:resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl)}}__name(getAllLocaleUrls,"getAllLocaleUrls");function getLocale(url){let pathName=typeof url=="string"?url:url.pathname,pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),baseUrlWithoutTrailingSlash=removeTrailingSlash(BASE_URL),pathNameWithoutBaseUrl=BASE_URL==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),possibleLocaleKey=pathNameWithoutBaseUrl.slice(1,3),pathNameWithoutBaseUrlStartsWithLocale=localeKeys.filter(key=>key!==defaultLocale).includes(possibleLocaleKey);return pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithLocale||pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithLocale?possibleLocaleKey:defaultLocale}__name(getLocale,"getLocale");function getLocaleUrl(url,locale){let pathName=typeof url=="string"?url:url.pathname,pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),baseUrlWithoutTrailingSlash=removeTrailingSlash(BASE_URL),pathNameWithoutBaseUrl=BASE_URL==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),possibleLocaleKey=pathNameWithoutBaseUrl.slice(1,3),pathNameWithoutBaseUrlStartsWithLocale=localeKeys.filter(key=>key!==defaultLocale).includes(possibleLocaleKey);return pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithLocale?locale===defaultLocale?resolveTrailingSlash(BASE_URL):resolveTrailingSlash(baseUrlWithoutTrailingSlash+"/"+locale+"/"):pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithLocale?locale===defaultLocale?resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl.slice(3)):resolveTrailingSlash(baseUrlWithoutTrailingSlash+"/"+locale+pathNameWithoutBaseUrl.slice(3)):locale===defaultLocale?resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl):resolveTrailingSlash(baseUrlWithoutTrailingSlash+"/"+locale+pathNameWithoutBaseUrl)}__name(getLocaleUrl,"getLocaleUrl");function getLocaleUrlPrefix(url){let pathName=typeof url=="string"?url:url.pathname,pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),baseUrlWithoutTrailingSlash=removeTrailingSlash(BASE_URL),pathNameWithoutBaseUrl=BASE_URL==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),possibleLocaleKey=pathNameWithoutBaseUrl.slice(1,3),pathNameWithoutBaseUrlStartsWithLocale=localeKeys.filter(key=>key!==defaultLocale).includes(possibleLocaleKey);return pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithLocale||pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithLocale?"/"+possibleLocaleKey:""}__name(getLocaleUrlPrefix,"getLocaleUrlPrefix");function getUrlWithoutLocale(url){let pathName=typeof url=="string"?url:url.pathname,pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),baseUrlWithoutTrailingSlash=removeTrailingSlash(BASE_URL),pathNameWithoutBaseUrl=BASE_URL==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),possibleLocaleKey=pathNameWithoutBaseUrl.slice(1,3),pathNameWithoutBaseUrlStartsWithLocale=localeKeys.filter(key=>key!==defaultLocale).includes(possibleLocaleKey);return pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithLocale?resolveTrailingSlash(BASE_URL):pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithLocale?resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl.slice(3)):resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl)}__name(getUrlWithoutLocale,"getUrlWithoutLocale");var import_meta={};var translationsByLocale={},modules=import_meta.glob("/src/i18n/*.json",{eager:!0});for(let[filePath,module2]of Object.entries(modules)){let locale=filePath.split("/").pop()?.replace(".json","");locale&&(translationsByLocale[locale]=module2.default)}var DEFAULT_LOCALE=defaultLocale;function getTranslationValue(translations,key){if(!translations)return;if(translations[key]!==void 0)return translations[key];let parts=key.split("."),current=translations;for(let part of parts)if(current&&typeof current=="object"&&part in current)current=current[part];else return;return current}__name(getTranslationValue,"getTranslationValue");function interpolate(template,params){return!params||typeof template!="string"?template:template.replace(/\{\{\s*([^}]+?)\s*\}\}/g,(match,key)=>params[key]!==void 0?String(params[key]):match)}__name(interpolate,"interpolate");function getTranslateHelper(locale){let translations=translationsByLocale[locale];return!translations&&locale!==DEFAULT_LOCALE&&(translations=translationsByLocale[DEFAULT_LOCALE]),__name(function(key,params){let val=getTranslationValue(translations,key);if(val===void 0&&locale!==DEFAULT_LOCALE){let defaultTranslations=translationsByLocale[DEFAULT_LOCALE];val=getTranslationValue(defaultTranslations,key)}return val===void 0?key:typeof val=="string"?interpolate(val,params):key},"t")}__name(getTranslateHelper,"getTranslateHelper");var defaultI18nConfig={include:["pages/**/*"],exclude:["pages/api/**/*"],redirectDefaultLocale:308};0&&(module.exports={BASE_URL,build,defaultI18nConfig,defaultLocale,filterCollectionByDefaultLocale,getAllLocaleUrls,getCollectionParamsSlug,getLocale,getLocaleUrl,getLocaleUrlPrefix,getTranslateHelper,getUrlWithoutLocale,localeKeys,locales,resolveTrailingSlash,trailingSlash});
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/edge-runtime/index.ts","../../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":["export {\n defaultLocale,\n locales,\n localeKeys,\n trailingSlash,\n build,\n BASE_URL,\n} from './config'\nexport { filterCollectionByDefaultLocale } from './filterCollectionByDefaultLocale'\nexport { getCollectionParamsSlug } from './getCollectionParamsSlug'\nexport { getAllLocaleUrls } from './getAllLocaleUrls'\nexport { getLocale } from './getLocale'\nexport { getLocaleUrl } from './getLocaleUrl'\nexport { getLocaleUrlPrefix } from './getLocaleUrlPrefix'\nexport { getUrlWithoutLocale } from './getUrlWithoutLocale'\nexport { resolveTrailingSlash } from './resolveTrailingSlash'\nexport { getTranslateHelper } from './getTranslateHelper'\nexport { defaultI18nConfig } from '../shared'\nexport type {\n UserI18nConfig,\n UserFilterSitemapByDefaultLocaleConfig,\n} from '../shared'\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","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":"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","names":["virtualConfig","module"]}
@@ -0,0 +1,13 @@
1
+ export { defaultLocale, locales, localeKeys, trailingSlash, build, BASE_URL, } from './config';
2
+ export { filterCollectionByDefaultLocale } from './filterCollectionByDefaultLocale';
3
+ export { getCollectionParamsSlug } from './getCollectionParamsSlug';
4
+ export { getAllLocaleUrls } from './getAllLocaleUrls';
5
+ export { getLocale } from './getLocale';
6
+ export { getLocaleUrl } from './getLocaleUrl';
7
+ export { getLocaleUrlPrefix } from './getLocaleUrlPrefix';
8
+ export { getUrlWithoutLocale } from './getUrlWithoutLocale';
9
+ export { resolveTrailingSlash } from './resolveTrailingSlash';
10
+ export { getTranslateHelper } from './getTranslateHelper';
11
+ export { defaultI18nConfig } from '../shared';
12
+ export type { UserI18nConfig, UserFilterSitemapByDefaultLocaleConfig, } from '../shared';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/edge-runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,OAAO,EACP,UAAU,EACV,aAAa,EACb,KAAK,EACL,QAAQ,GACT,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAA;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAC7C,YAAY,EACV,cAAc,EACd,sCAAsC,GACvC,MAAM,WAAW,CAAA"}
@@ -0,0 +1,2 @@
1
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});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 filterCollectionByDefaultLocale(entry){return!!(typeof entry=="object"&&entry!==null&&"slug"in entry&&typeof entry.slug=="string"&&entry.slug.startsWith(defaultLocale+"/"))}__name(filterCollectionByDefaultLocale,"filterCollectionByDefaultLocale");function getCollectionParamsSlug(entries){return entries.reduce((accumulator,entry)=>(typeof entry=="object"&&entry!==null&&"slug"in entry&&typeof entry.slug=="string"&&accumulator.push({params:{slug:entry.slug.replace(defaultLocale+"/","")}}),accumulator),[])}__name(getCollectionParamsSlug,"getCollectionParamsSlug");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 removeTrailingSlash(url){return url.at(-1)==="/"?url.slice(0,-1):url}__name(removeTrailingSlash,"removeTrailingSlash");function removeHtmlExtension(url){return url.endsWith(".html")?url.slice(0,-5):url}__name(removeHtmlExtension,"removeHtmlExtension");function getAllLocaleUrls(url){let pathName=typeof url=="string"?url:url.pathname,pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),baseUrlWithoutTrailingSlash=removeTrailingSlash(BASE_URL),pathNameWithoutBaseUrl=BASE_URL==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),possibleLocaleKey=pathNameWithoutBaseUrl.slice(1,3),pathNameWithoutBaseUrlStartsWithLocale=localeKeys.filter(key=>key!==defaultLocale).includes(possibleLocaleKey);return pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithLocale?{...localeKeys.reduce((record,locale)=>(record[locale]=resolveTrailingSlash(baseUrlWithoutTrailingSlash+"/"+locale+"/"),record),{}),[defaultLocale]:resolveTrailingSlash(BASE_URL)}:pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithLocale?{...localeKeys.reduce((record,locale)=>(record[locale]=resolveTrailingSlash(baseUrlWithoutTrailingSlash+"/"+locale+pathNameWithoutBaseUrl.slice(3)),record),{}),[defaultLocale]:resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl.slice(3))}:{...localeKeys.reduce((record,locale)=>(record[locale]=resolveTrailingSlash(baseUrlWithoutTrailingSlash+"/"+locale+pathNameWithoutBaseUrl),record),{}),[defaultLocale]:resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl)}}__name(getAllLocaleUrls,"getAllLocaleUrls");function getLocale(url){let pathName=typeof url=="string"?url:url.pathname,pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),baseUrlWithoutTrailingSlash=removeTrailingSlash(BASE_URL),pathNameWithoutBaseUrl=BASE_URL==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),possibleLocaleKey=pathNameWithoutBaseUrl.slice(1,3),pathNameWithoutBaseUrlStartsWithLocale=localeKeys.filter(key=>key!==defaultLocale).includes(possibleLocaleKey);return pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithLocale||pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithLocale?possibleLocaleKey:defaultLocale}__name(getLocale,"getLocale");function getLocaleUrl(url,locale){let pathName=typeof url=="string"?url:url.pathname,pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),baseUrlWithoutTrailingSlash=removeTrailingSlash(BASE_URL),pathNameWithoutBaseUrl=BASE_URL==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),possibleLocaleKey=pathNameWithoutBaseUrl.slice(1,3),pathNameWithoutBaseUrlStartsWithLocale=localeKeys.filter(key=>key!==defaultLocale).includes(possibleLocaleKey);return pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithLocale?locale===defaultLocale?resolveTrailingSlash(BASE_URL):resolveTrailingSlash(baseUrlWithoutTrailingSlash+"/"+locale+"/"):pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithLocale?locale===defaultLocale?resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl.slice(3)):resolveTrailingSlash(baseUrlWithoutTrailingSlash+"/"+locale+pathNameWithoutBaseUrl.slice(3)):locale===defaultLocale?resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl):resolveTrailingSlash(baseUrlWithoutTrailingSlash+"/"+locale+pathNameWithoutBaseUrl)}__name(getLocaleUrl,"getLocaleUrl");function getLocaleUrlPrefix(url){let pathName=typeof url=="string"?url:url.pathname,pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),baseUrlWithoutTrailingSlash=removeTrailingSlash(BASE_URL),pathNameWithoutBaseUrl=BASE_URL==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),possibleLocaleKey=pathNameWithoutBaseUrl.slice(1,3),pathNameWithoutBaseUrlStartsWithLocale=localeKeys.filter(key=>key!==defaultLocale).includes(possibleLocaleKey);return pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithLocale||pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithLocale?"/"+possibleLocaleKey:""}__name(getLocaleUrlPrefix,"getLocaleUrlPrefix");function getUrlWithoutLocale(url){let pathName=typeof url=="string"?url:url.pathname,pathNameWithoutHtmlExtension=removeHtmlExtension(pathName),baseUrlWithoutTrailingSlash=removeTrailingSlash(BASE_URL),pathNameWithoutBaseUrl=BASE_URL==="/"?pathNameWithoutHtmlExtension:pathNameWithoutHtmlExtension.replace(baseUrlWithoutTrailingSlash,""),possibleLocaleKey=pathNameWithoutBaseUrl.slice(1,3),pathNameWithoutBaseUrlStartsWithLocale=localeKeys.filter(key=>key!==defaultLocale).includes(possibleLocaleKey);return pathNameWithoutBaseUrl.length===3&&pathNameWithoutBaseUrlStartsWithLocale?resolveTrailingSlash(BASE_URL):pathNameWithoutBaseUrl[0]==="/"&&pathNameWithoutBaseUrl[3]==="/"&&pathNameWithoutBaseUrlStartsWithLocale?resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl.slice(3)):resolveTrailingSlash(baseUrlWithoutTrailingSlash+pathNameWithoutBaseUrl)}__name(getUrlWithoutLocale,"getUrlWithoutLocale");var translationsByLocale={},modules=import.meta.glob("/src/i18n/*.json",{eager:!0});for(let[filePath,module]of Object.entries(modules)){let locale=filePath.split("/").pop()?.replace(".json","");locale&&(translationsByLocale[locale]=module.default)}var DEFAULT_LOCALE=defaultLocale;function getTranslationValue(translations,key){if(!translations)return;if(translations[key]!==void 0)return translations[key];let parts=key.split("."),current=translations;for(let part of parts)if(current&&typeof current=="object"&&part in current)current=current[part];else return;return current}__name(getTranslationValue,"getTranslationValue");function interpolate(template,params){return!params||typeof template!="string"?template:template.replace(/\{\{\s*([^}]+?)\s*\}\}/g,(match,key)=>params[key]!==void 0?String(params[key]):match)}__name(interpolate,"interpolate");function getTranslateHelper(locale){let translations=translationsByLocale[locale];return!translations&&locale!==DEFAULT_LOCALE&&(translations=translationsByLocale[DEFAULT_LOCALE]),__name(function(key,params){let val=getTranslationValue(translations,key);if(val===void 0&&locale!==DEFAULT_LOCALE){let defaultTranslations=translationsByLocale[DEFAULT_LOCALE];val=getTranslationValue(defaultTranslations,key)}return val===void 0?key:typeof val=="string"?interpolate(val,params):key},"t")}__name(getTranslateHelper,"getTranslateHelper");var defaultI18nConfig={include:["pages/**/*"],exclude:["pages/api/**/*"],redirectDefaultLocale:308};export{BASE_URL,build,defaultI18nConfig,defaultLocale,filterCollectionByDefaultLocale,getAllLocaleUrls,getCollectionParamsSlug,getLocale,getLocaleUrl,getLocaleUrlPrefix,getTranslateHelper,getUrlWithoutLocale,localeKeys,locales,resolveTrailingSlash,trailingSlash};
2
+ //# sourceMappingURL=index.js.map