@i18n-micro/astro 1.2.1 → 1.3.1

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.
@@ -1,6 +1,6 @@
1
1
  import { Params, Translations } from '@i18n-micro/types';
2
2
  /**
3
- * Состояние i18n для клиентских островов
3
+ * I18n state for client islands
4
4
  */
5
5
  export interface I18nState {
6
6
  locale: string;
@@ -9,7 +9,7 @@ export interface I18nState {
9
9
  currentRoute: string;
10
10
  }
11
11
  /**
12
- * Чистая функция для получения перевода из состояния
12
+ * Pure function to get a translation from state
13
13
  *
14
14
  * Note: This is a simplified version optimized for client-side islands.
15
15
  * It supports basic translation lookup, interpolation, and fallback to general translations.
@@ -18,6 +18,6 @@ export interface I18nState {
18
18
  */
19
19
  export declare function translate(state: I18nState, key: string, params?: Params, defaultValue?: string | null, routeName?: string): string | number | boolean | Translations | null;
20
20
  /**
21
- * Проверяет наличие перевода в состоянии
21
+ * Checks if a translation exists in the state
22
22
  */
23
23
  export declare function hasTranslation(state: I18nState, key: string, routeName?: string): boolean;
@@ -3,12 +3,12 @@ import { Writable } from 'svelte/store';
3
3
  import { I18nClientProps } from '../utils';
4
4
  import { I18nState } from './core';
5
5
  /**
6
- * Создает Svelte store для i18n состояния
6
+ * Creates a Svelte store for i18n state
7
7
  */
8
8
  export declare function createI18nStore(props: I18nClientProps): Writable<I18nState>;
9
9
  /**
10
- * Хук для использования i18n в Svelte компонентах
11
- * Используйте в <script> блоке компонента
10
+ * Hook for using i18n in Svelte components
11
+ * Use in the component's <script> block
12
12
  */
13
13
  export declare function useAstroI18n(store: Writable<I18nState>): {
14
14
  store: Writable<I18nState>;
@@ -13,7 +13,7 @@ function F(o) {
13
13
  function P(o) {
14
14
  const n = () => v(o), c = (t, e, r, a) => S(n(), t, e, r, a);
15
15
  return {
16
- // Store для реактивности в шаблонах (используйте $i18nStore в шаблонах)
16
+ // Store for reactivity in templates (use $i18nStore in templates)
17
17
  store: o,
18
18
  // Translation methods
19
19
  t: c,
@@ -38,7 +38,7 @@ function P(o) {
38
38
  return l.formatRelativeTime(t, r.locale, e);
39
39
  },
40
40
  has: (t, e) => L(n(), t, e),
41
- // Геттеры для текущего состояния (для использования в скриптах)
41
+ // Getters for current state (for use in scripts)
42
42
  get locale() {
43
43
  return n().locale;
44
44
  },
@@ -3,12 +3,12 @@ import { Ref } from 'vue';
3
3
  import { I18nClientProps } from '../utils';
4
4
  import { I18nState } from './core';
5
5
  /**
6
- * Инициализирует i18n провайдер для Vue острова
7
- * Вызывайте в корневом компоненте острова
6
+ * Initializes the i18n provider for a Vue island
7
+ * Call in the island's root component
8
8
  */
9
9
  export declare function provideI18n(props: I18nClientProps): Ref<I18nState>;
10
10
  /**
11
- * Хук для использования i18n в Vue компонентах
11
+ * Hook for using i18n in Vue components
12
12
  */
13
13
  export declare function useAstroI18n(): {
14
14
  t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation;
@@ -30,6 +30,5 @@ export declare class AstroI18n extends BaseI18n {
30
30
  addTranslations(locale: string, translations: Translations, merge?: boolean): void;
31
31
  addRouteTranslations(locale: string, routeName: string, translations: Translations, merge?: boolean): void;
32
32
  mergeTranslations(locale: string, routeName: string, translations: Translations): void;
33
- mergeGlobalTranslations(locale: string, translations: Translations): void;
34
33
  clearCache(): void;
35
34
  }
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("@i18n-micro/core"),b=require("node:fs"),I=require("node:path");class j extends T.BaseI18n{constructor(e){const s=e._storage||{translations:new Map};if(super({storage:s,plural:e.plural,missingWarn:e.missingWarn,missingHandler:e.missingHandler}),this.initialMessages={},this.storage=s,this._locale=e.locale,this._fallbackLocale=e.fallbackLocale||e.locale,this._currentRoute="general",e.messages){this.initialMessages={...e.messages};for(const[a,i]of Object.entries(e.messages))this.helper.loadTranslations(a,i)}}cloneStorage(e){const s=new Map;for(const[a,i]of e.translations)s.set(a,{...i});return{translations:s}}clone(e){const s=this.cloneStorage(this.storage);return new j({locale:e||this._locale,fallbackLocale:this._fallbackLocale,plural:this.pluralFunc,missingWarn:this.missingWarn,missingHandler:this.missingHandler,_storage:s})}get locale(){return this._locale}set locale(e){this._locale=e}get fallbackLocale(){return this._fallbackLocale}set fallbackLocale(e){this._fallbackLocale=e}setRoute(e){this._currentRoute=e}getLocale(){return this._locale}getFallbackLocale(){return this._fallbackLocale}getRoute(){return this._currentRoute}getRouteTranslations(e,s){const a=`${e}:${s}`;return this.storage.translations.get(a)??null}addTranslations(e,s,a=!0){super.loadTranslationsCore(e,s,a)}addRouteTranslations(e,s,a,i=!0){super.loadRouteTranslationsCore(e,s,a,i)}mergeTranslations(e,s,a){this.helper.mergeTranslation(e,s,a,!0)}mergeGlobalTranslations(e,s){this.helper.mergeGlobalTranslation(e,s,!0)}clearCache(){const e={...this.initialMessages};if(super.clearCache(),Object.keys(e).length>0)for(const[s,a]of Object.entries(e))this.helper.loadTranslations(s,a)}}let $=null;function D(){return $}function C(n){const{locale:e,fallbackLocale:s,translationDir:a,routingStrategy:i}=n;return $=i||null,{name:"@i18n-micro/astro",hooks:{"astro:config:setup":c=>{const{updateConfig:f}=c,t="virtual:i18n-micro/config",l=`\0${t}`,r={defaultLocale:e,fallbackLocale:s||e,locales:n.locales||[],localeCodes:(n.locales||[]).map(o=>o.code),translationDir:a||null,autoDetect:n.autoDetect??!0,redirectToDefault:n.redirectToDefault??!1,localeCookie:n.localeCookie===null?null:n.localeCookie||"i18n-locale",missingWarn:n.missingWarn??!1};f({vite:{plugins:[{name:"vite-plugin-i18n-micro-config",resolveId(o){if(o===t)return l},load(o){if(o===l)return`export const config = ${JSON.stringify(r)}`}}]}})},"astro:config:done":c=>{const{injectTypes:f}=c;f({filename:"i18n-micro-env.d.ts",content:`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("@i18n-micro/core"),S=require("node:fs"),k=require("node:path");class j extends w.BaseI18n{constructor(e){const s=e._storage||{translations:new Map};if(super({storage:s,plural:e.plural,missingWarn:e.missingWarn,missingHandler:e.missingHandler}),this.initialMessages={},this.storage=s,this._locale=e.locale,this._fallbackLocale=e.fallbackLocale||e.locale,this._currentRoute="index",e.messages){this.initialMessages={...e.messages};for(const[a,i]of Object.entries(e.messages))this.helper.loadTranslations(a,i)}}cloneStorage(e){const s=new Map;for(const[a,i]of e.translations)s.set(a,{...i});return{translations:s}}clone(e){const s=this.cloneStorage(this.storage);return new j({locale:e||this._locale,fallbackLocale:this._fallbackLocale,plural:this.pluralFunc,missingWarn:this.missingWarn,missingHandler:this.missingHandler,_storage:s})}get locale(){return this._locale}set locale(e){this._locale=e}get fallbackLocale(){return this._fallbackLocale}set fallbackLocale(e){this._fallbackLocale=e}setRoute(e){this._currentRoute=e}getLocale(){return this._locale}getFallbackLocale(){return this._fallbackLocale}getRoute(){return this._currentRoute}getRouteTranslations(e,s){const a=`${e}:${s}`;return this.storage.translations.get(a)??null}addTranslations(e,s,a=!0){super.loadTranslationsCore(e,s,a)}addRouteTranslations(e,s,a,i=!0){super.loadRouteTranslationsCore(e,s,a,i)}mergeTranslations(e,s,a){this.helper.mergeTranslation(e,s,a,!0)}clearCache(){const e={...this.initialMessages};if(super.clearCache(),Object.keys(e).length>0)for(const[s,a]of Object.entries(e))this.helper.loadTranslations(s,a)}}let I=null;function D(){return I}function C(t){const{locale:e,fallbackLocale:s,translationDir:a,routingStrategy:i}=t;return I=i||null,{name:"@i18n-micro/astro",hooks:{"astro:config:setup":c=>{const{updateConfig:u}=c,n="virtual:i18n-micro/config",l=`\0${n}`,r={defaultLocale:e,fallbackLocale:s||e,locales:t.locales||[],localeCodes:(t.locales||[]).map(o=>o.code),translationDir:a||null,autoDetect:t.autoDetect??!0,redirectToDefault:t.redirectToDefault??!1,localeCookie:t.localeCookie===null?null:t.localeCookie||"i18n-locale",missingWarn:t.missingWarn??!1};u({vite:{plugins:[{name:"vite-plugin-i18n-micro-config",resolveId(o){if(o===n)return l},load(o){if(o===l)return`export const config = ${JSON.stringify(r)}`}}]}})},"astro:config:done":c=>{const{injectTypes:u}=c;u({filename:"i18n-micro-env.d.ts",content:`
2
2
  /// <reference types="@i18n-micro/astro/env" />
3
3
 
4
4
  declare module 'virtual:i18n-micro/config' {
@@ -14,4 +14,4 @@
14
14
  missingWarn: boolean | null;
15
15
  }
16
16
  }
17
- `})}}}}function N(n){return new j(n)}function F(n){const{translationDir:e,rootDir:s=process.cwd(),disablePageLocales:a=!1}=n,i=I.resolve(s,e);if(!b.existsSync(i))return console.warn(`[i18n] Translation directory not found: ${i}`),{general:{},routes:{}};const c={},f={},t=(l,r="")=>{if(!b.existsSync(l))return;const o=b.readdirSync(l);for(const u of o){const h=I.join(l,u);if(b.statSync(h).isDirectory())u==="pages"&&!a?t(h,""):r||a?t(h,r):t(h,u);else if(u.endsWith(".json")){const m=u.replace(".json","");try{const g=b.readFileSync(h,"utf-8"),p=JSON.parse(g);r&&!a?(f[r]||(f[r]={}),f[r][m]=p):c[m]=p}catch(g){console.error(`[i18n] Failed to load translation file: ${h}`,g)}}}};return t(i),{general:c,routes:f}}function q(n,e){const{general:s,routes:a}=F(e);for(const[i,c]of Object.entries(s))n.addTranslations(i,c,!1);for(const[i,c]of Object.entries(a))for(const[f,t]of Object.entries(c))n.addRouteTranslations(f,i,t,!1)}function M(n){const{i18n:e,defaultLocale:s,locales:a,localeObjects:i,autoDetect:c=!0,redirectToDefault:f=!1,routingStrategy:t}=n,l=t||D();return async(r,o)=>{if(r.locals.locale&&r.locals.i18n)return o();const u=r.url,h=u.pathname;if(!l){const S=e.clone(s),O=h==="/"||h===""?"index":h.split("/").filter(Boolean).join("-");return S.setRoute(O),r.locals.i18n=S,r.locals.locale=s,r.locals.defaultLocale=s,r.locals.locales=i||a.map(_=>({code:_})),r.locals.currentUrl=u,o()}const d={...l,getCurrentPath:()=>h,getRoute:()=>({fullPath:u.pathname+u.search,query:Object.fromEntries(u.searchParams)})},g=h.split("/").filter(Boolean)[0],p=g!==void 0&&a.includes(g);let P;p&&g?P=g:d.getLocaleFromPath?P=d.getLocaleFromPath(h,s,a):P=s;const L=e.clone(P),y=d.getRouteName?d.getRouteName(h,a):"general";return L.setRoute(y),r.locals.i18n=L,r.locals.locale=P,r.locals.defaultLocale=s,r.locals.locales=i||a.map(S=>({code:S})),r.locals.currentUrl=u,r.locals.routingStrategy=d,o()}}function A(n){const e=[],s=n.split(",");for(const a of s){const[i,c="1.0"]=a.trim().split(";q=");if(Number.parseFloat(c)>0&&i){const t=i.split("-")[0]?.toLowerCase();t&&(e.push(t),i!==t&&e.push(i.toLowerCase()))}}return e}function W(n,e,s,a,i,c="i18n-locale"){const f=D();let t=a;if(f?.getLocaleFromPath)t=f.getLocaleFromPath(n,a,i);else{const r=n.split("/").filter(Boolean)[0];r&&i.includes(r)&&(t=r)}if(c!==null&&t===a&&e.get(c)){const l=e.get(c)?.value;l&&i.includes(l)&&(t=l)}if(t===a)try{const l=s.get("accept-language");if(l){const r=A(l);for(const o of r)if(i.includes(o)){t=o;break}}}catch{}return t}function z(n,e,s){const a=n.map(o=>o.code),i=(o,u=[])=>{const h=o.replace(/^\//,"").replace(/\/$/,"");if(!h)return"index";const d=h.split("/").filter(Boolean),m=d[0];return m&&u.includes(m)&&d.shift(),d.length===0?"index":d.join("-")},c=(o,u="en",h=[])=>{const m=o.split("/").filter(Boolean)[0];return m&&h.includes(m)?m:u},f=(o,u,h=[],d)=>{const m=o.split("/").filter(Boolean),g=m[0];return g&&h.includes(g)&&m.shift(),(u!==d||d===void 0)&&m.unshift(u),`/${m.join("/")}`},t=(o,u,h=[],d)=>{const g=(o.replace(/^\//,"").replace(/\/$/,"")||"").split("/").filter(Boolean),p=g[0];return p&&h.includes(p)&&g.shift(),(u!==d||d===void 0)&&g.unshift(u),`/${g.join("/")}`};return{getCurrentPath:()=>s?s().pathname:typeof window<"u"?window.location.pathname:"/",getRouteName:i,getLocaleFromPath:c,switchLocalePath:f,localizePath:t,removeLocaleFromPath:(o,u=[])=>{const h=o.split("/").filter(Boolean),d=h[0];return d&&u.includes(d)&&h.shift(),`/${h.join("/")}`},resolvePath:(o,u)=>{const h=typeof o=="string"?o:o.path||"/";return t(h,u,a,e)},getRoute:()=>{if(s){const o=s();return{fullPath:o.pathname+o.search,query:Object.fromEntries(o.searchParams)}}if(typeof window<"u"){const o=new URL(window.location.href);return{fullPath:o.pathname+o.search,query:Object.fromEntries(o.searchParams)}}return{fullPath:"/",query:{}}},push:o=>{typeof window<"u"&&(window.location.href=o.path)},replace:o=>{typeof window<"u"&&window.location.replace(o.path)}}}function H(n,e=[]){const s=n.replace(/^\//,"").replace(/\/$/,"");if(!s)return"index";const a=s.split("/").filter(Boolean),i=a[0];return i&&e.includes(i)&&a.shift(),a.length===0?"index":a.join("-")}function G(n,e="en",s=[]){const i=n.split("/").filter(Boolean)[0];return i&&s.includes(i)?i:e}function U(n,e,s=[],a){const i=n.split("/").filter(Boolean),c=i[0];return c&&s.includes(c)&&i.shift(),(e!==a||a===void 0)&&i.unshift(e),`/${i.join("/")}`}function E(n,e,s=[],a){const c=(n.replace(/^\//,"").replace(/\/$/,"")||"").split("/").filter(Boolean),f=c[0];return f&&s.includes(f)&&c.shift(),(e!==a||a===void 0)&&c.unshift(e),`/${c.join("/")}`}function J(n,e=[]){const s=n.split("/").filter(Boolean),a=s[0];return a&&e.includes(a)&&s.shift(),`/${s.join("/")}`}function v(n){const e=n.locals.i18n;if(!e)throw new Error("i18n instance not found. Make sure i18n middleware is configured.");return e}function w(n){return n.locals.locale||"en"}function R(n){return n.locals.defaultLocale||"en"}function k(n){return n.locals.locales||[]}function B(n){return n.locals.routingStrategy||null}function V(n){const e=v(n),s=w(n),a=R(n),i=k(n),c=i.map(t=>t.code),f=B(n);return{locale:s,defaultLocale:a,locales:i,t:(t,l,r,o)=>e.t(t,l,r,o),ts:(t,l,r,o)=>e.ts(t,l,r,o),tc:(t,l,r)=>e.tc(t,l,r),tn:(t,l)=>e.tn(t,l),td:(t,l)=>e.td(t,l),tdr:(t,l)=>e.tdr(t,l),has:(t,l)=>e.has(t,l),getRoute:()=>e.getRoute(),getRouteName:t=>{const l=t||n.url.pathname;if(f?.getRouteName)return f.getRouteName(l,c);const r=l.replace(/^\//,"").replace(/\/$/,"");if(!r)return"index";const o=r.split("/").filter(Boolean),u=o[0];return u&&c.includes(u)&&o.shift(),o.length===0?"index":o.join("-")},getLocaleFromPath:t=>{const l=t||n.url.pathname;if(f?.getLocaleFromPath)return f.getLocaleFromPath(l,a,c);const o=l.split("/").filter(Boolean)[0];return o&&c.includes(o)?o:a},switchLocalePath:t=>{if(f?.switchLocalePath)return f.switchLocalePath(n.url.pathname,t,c,a);const l=n.url.pathname.split("/").filter(Boolean),r=l[0];return r&&c.includes(r)&&l.shift(),t!==a&&l.unshift(t),`/${l.join("/")}`},localizePath:(t,l)=>{if(f?.localizePath)return f.localizePath(t,l||s,c,a);const o=(t.replace(/^\//,"").replace(/\/$/,"")||"").split("/").filter(Boolean),u=o[0];return u&&c.includes(u)&&o.shift(),l&&l!==a&&o.unshift(l),`/${o.join("/")}`},getI18n:()=>e,getBasePath:t=>{const o=(t||n.url).pathname.split("/").filter(Boolean),u=o[0];return u&&c.includes(u)&&o.shift(),o.length>0?`/${o.join("/")}`:"/"},addTranslations:(t,l,r=!0)=>{e.addTranslations(t,l,r)},addRouteTranslations:(t,l,r,o=!0)=>{e.addRouteTranslations(t,l,r,o)},mergeTranslations:(t,l,r)=>{e.mergeTranslations(t,l,r)},mergeGlobalTranslations:(t,l)=>{e.mergeGlobalTranslations(t,l)},clearCache:()=>{e.clearCache()}}}function K(n,e={}){const{baseUrl:s="/",addDirAttribute:a=!0,addSeoAttributes:i=!0}=e,c=w(n),f=R(n),t=k(n),l=t.find(g=>g.code===c);if(!l)return{htmlAttrs:{},link:[],meta:[]};const r=l.iso||c,o=l.dir||"auto",u={htmlAttrs:{lang:r,...a?{dir:o}:{}},link:[],meta:[]};if(!i)return u;const h=`${s}${n.url.pathname}`;u.link.push({rel:"canonical",href:h});const d=B(n),m=t.map(g=>g.code);for(const g of t){if(g.code===c)continue;let p=n.url.pathname;if(d?.switchLocalePath)p=d.switchLocalePath(n.url.pathname,g.code,m,f);else{const L=n.url.pathname.split("/").filter(Boolean),y=L[0];y&&m.includes(y)&&L.shift(),g.code!==f&&L.unshift(g.code),p=`/${L.join("/")}`}const P=`${s}${p}`;u.link.push({rel:"alternate",href:P,hreflang:g.code}),g.iso&&g.iso!==g.code&&u.link.push({rel:"alternate",href:P,hreflang:g.iso})}u.meta.push({property:"og:locale",content:r}),u.meta.push({property:"og:url",content:h});for(const g of t)g.code!==c&&u.meta.push({property:"og:locale:alternate",content:g.iso||g.code});return u}function Q(n,e,s){const a=e.split(".");let i=n;for(let f=0;f<a.length-1;f++){const t=a[f];i[t]||(i[t]={}),i=i[t]}const c=a[a.length-1];c!==void 0&&(i[c]=s)}function X(n,e){const s=v(n),a=w(n),i=R(n),c=s.getRoute(),f={};if(e&&e.length>0){const t={};for(const l of e){const r=s.t(l,void 0,void 0,c);r!=null&&r!==l&&Q(t,l,r)}Object.keys(t).length>0&&(f[c]=t)}else{const t=s.getRouteTranslations(a,c);t&&(f[c]=t)}return{locale:a,fallbackLocale:i,currentRoute:c,translations:f}}Object.defineProperty(exports,"FormatService",{enumerable:!0,get:()=>T.FormatService});Object.defineProperty(exports,"defaultPlural",{enumerable:!0,get:()=>T.defaultPlural});Object.defineProperty(exports,"interpolate",{enumerable:!0,get:()=>T.interpolate});exports.AstroI18n=j;exports.createAstroRouterAdapter=z;exports.createI18n=N;exports.createI18nMiddleware=M;exports.detectLocale=W;exports.getDefaultLocale=R;exports.getI18n=v;exports.getI18nProps=X;exports.getLocale=w;exports.getLocaleFromPath=G;exports.getLocales=k;exports.getRouteName=H;exports.i18nIntegration=C;exports.loadTranslationsFromDir=F;exports.loadTranslationsIntoI18n=q;exports.localizePath=E;exports.removeLocaleFromPath=J;exports.switchLocalePath=U;exports.useI18n=V;exports.useLocaleHead=K;
17
+ `})}}}}function N(t){return new j(t)}function F(t){const{translationDir:e,rootDir:s=process.cwd(),disablePageLocales:a=!1}=t,i=k.resolve(s,e);if(!S.existsSync(i))return console.warn(`[i18n] Translation directory not found: ${i}`),{root:{},routes:{}};const c={},u={},n=(l,r="")=>{if(!S.existsSync(l))return;const o=S.readdirSync(l);for(const g of o){const f=k.join(l,g);if(S.statSync(f).isDirectory())g==="pages"&&!a?n(f,""):r||a?n(f,r):n(f,g);else if(g.endsWith(".json")){const m=g.replace(".json","");try{const p=S.readFileSync(f,"utf-8"),h=JSON.parse(p);r&&!a?(u[r]||(u[r]={}),u[r][m]=h):c[m]=h}catch(p){console.error(`[i18n] Failed to load translation file: ${f}`,p)}}}};return n(i),{root:c,routes:u}}function q(t,e){const{root:s,routes:a}=F(e);for(const[i,c]of Object.entries(s))t.addTranslations(i,c,!1);for(const[i,c]of Object.entries(a))for(const[u,n]of Object.entries(c)){const l=s[u]||{};t.addRouteTranslations(u,i,{...l,...n},!1)}}function M(t){const{i18n:e,defaultLocale:s,locales:a,localeObjects:i,autoDetect:c=!0,redirectToDefault:u=!1,routingStrategy:n}=t,l=n||D();return async(r,o)=>{if(r.locals.locale&&r.locals.i18n)return o();const g=r.url,f=g.pathname;if(!l){const b=e.clone(s),O=f==="/"||f===""?"index":f.split("/").filter(Boolean).join("-");return b.setRoute(O),r.locals.i18n=b,r.locals.locale=s,r.locals.defaultLocale=s,r.locals.locales=i||a.map(_=>({code:_})),r.locals.currentUrl=g,o()}const d={...l,getCurrentPath:()=>f,getRoute:()=>({fullPath:g.pathname+g.search,query:Object.fromEntries(g.searchParams)})},p=f.split("/").filter(Boolean)[0],h=p!==void 0&&a.includes(p);let P;h&&p?P=p:d.getLocaleFromPath?P=d.getLocaleFromPath(f,s,a):P=s;const L=e.clone(P),y=d.getRouteName?d.getRouteName(f,a):"index";return L.setRoute(y),r.locals.i18n=L,r.locals.locale=P,r.locals.defaultLocale=s,r.locals.locales=i||a.map(b=>({code:b})),r.locals.currentUrl=g,r.locals.routingStrategy=d,o()}}function A(t){const e=[],s=t.split(",");for(const a of s){const[i,c="1.0"]=a.trim().split(";q=");if(Number.parseFloat(c)>0&&i){const n=i.split("-")[0]?.toLowerCase();n&&(e.push(n),i!==n&&e.push(i.toLowerCase()))}}return e}function W(t,e,s,a,i,c="i18n-locale"){const u=D();let n=a;if(u?.getLocaleFromPath)n=u.getLocaleFromPath(t,a,i);else{const r=t.split("/").filter(Boolean)[0];r&&i.includes(r)&&(n=r)}if(c!==null&&n===a&&e.get(c)){const l=e.get(c)?.value;l&&i.includes(l)&&(n=l)}if(n===a)try{const l=s.get("accept-language");if(l){const r=A(l);for(const o of r)if(i.includes(o)){n=o;break}}}catch{}return n}function z(t,e,s){const a=t.map(o=>o.code),i=(o,g=[])=>{const f=o.replace(/^\//,"").replace(/\/$/,"");if(!f)return"index";const d=f.split("/").filter(Boolean),m=d[0];return m&&g.includes(m)&&d.shift(),d.length===0?"index":d.join("-")},c=(o,g="en",f=[])=>{const m=o.split("/").filter(Boolean)[0];return m&&f.includes(m)?m:g},u=(o,g,f=[],d)=>{const m=o.split("/").filter(Boolean),p=m[0];return p&&f.includes(p)&&m.shift(),(g!==d||d===void 0)&&m.unshift(g),`/${m.join("/")}`},n=(o,g,f=[],d)=>{const p=(o.replace(/^\//,"").replace(/\/$/,"")||"").split("/").filter(Boolean),h=p[0];return h&&f.includes(h)&&p.shift(),(g!==d||d===void 0)&&p.unshift(g),`/${p.join("/")}`};return{getCurrentPath:()=>s?s().pathname:typeof window<"u"?window.location.pathname:"/",getRouteName:i,getLocaleFromPath:c,switchLocalePath:u,localizePath:n,removeLocaleFromPath:(o,g=[])=>{const f=o.split("/").filter(Boolean),d=f[0];return d&&g.includes(d)&&f.shift(),`/${f.join("/")}`},resolvePath:(o,g)=>{const f=typeof o=="string"?o:o.path||"/";return n(f,g,a,e)},getRoute:()=>{if(s){const o=s();return{fullPath:o.pathname+o.search,query:Object.fromEntries(o.searchParams)}}if(typeof window<"u"){const o=new URL(window.location.href);return{fullPath:o.pathname+o.search,query:Object.fromEntries(o.searchParams)}}return{fullPath:"/",query:{}}},push:o=>{typeof window<"u"&&(window.location.href=o.path)},replace:o=>{typeof window<"u"&&window.location.replace(o.path)}}}function H(t,e=[]){const s=t.replace(/^\//,"").replace(/\/$/,"");if(!s)return"index";const a=s.split("/").filter(Boolean),i=a[0];return i&&e.includes(i)&&a.shift(),a.length===0?"index":a.join("-")}function U(t,e="en",s=[]){const i=t.split("/").filter(Boolean)[0];return i&&s.includes(i)?i:e}function E(t,e,s=[],a){const i=t.split("/").filter(Boolean),c=i[0];return c&&s.includes(c)&&i.shift(),(e!==a||a===void 0)&&i.unshift(e),`/${i.join("/")}`}function J(t,e,s=[],a){const c=(t.replace(/^\//,"").replace(/\/$/,"")||"").split("/").filter(Boolean),u=c[0];return u&&s.includes(u)&&c.shift(),(e!==a||a===void 0)&&c.unshift(e),`/${c.join("/")}`}function V(t,e=[]){const s=t.split("/").filter(Boolean),a=s[0];return a&&e.includes(a)&&s.shift(),`/${s.join("/")}`}function v(t){const e=t.locals.i18n;if(!e)throw new Error("i18n instance not found. Make sure i18n middleware is configured.");return e}function R(t){return t.locals.locale||"en"}function T(t){return t.locals.defaultLocale||"en"}function $(t){return t.locals.locales||[]}function B(t){return t.locals.routingStrategy||null}function G(t){const e=v(t),s=R(t),a=T(t),i=$(t),c=i.map(n=>n.code),u=B(t);return{locale:s,defaultLocale:a,locales:i,t:(n,l,r,o)=>e.t(n,l,r,o),ts:(n,l,r,o)=>e.ts(n,l,r,o),tc:(n,l,r)=>e.tc(n,l,r),tn:(n,l)=>e.tn(n,l),td:(n,l)=>e.td(n,l),tdr:(n,l)=>e.tdr(n,l),has:(n,l)=>e.has(n,l),getRoute:()=>e.getRoute(),getRouteName:n=>{const l=n||t.url.pathname;if(u?.getRouteName)return u.getRouteName(l,c);const r=l.replace(/^\//,"").replace(/\/$/,"");if(!r)return"index";const o=r.split("/").filter(Boolean),g=o[0];return g&&c.includes(g)&&o.shift(),o.length===0?"index":o.join("-")},getLocaleFromPath:n=>{const l=n||t.url.pathname;if(u?.getLocaleFromPath)return u.getLocaleFromPath(l,a,c);const o=l.split("/").filter(Boolean)[0];return o&&c.includes(o)?o:a},switchLocalePath:n=>{if(u?.switchLocalePath)return u.switchLocalePath(t.url.pathname,n,c,a);const l=t.url.pathname.split("/").filter(Boolean),r=l[0];return r&&c.includes(r)&&l.shift(),n!==a&&l.unshift(n),`/${l.join("/")}`},localizePath:(n,l)=>{if(u?.localizePath)return u.localizePath(n,l||s,c,a);const o=(n.replace(/^\//,"").replace(/\/$/,"")||"").split("/").filter(Boolean),g=o[0];return g&&c.includes(g)&&o.shift(),l&&l!==a&&o.unshift(l),`/${o.join("/")}`},getI18n:()=>e,getBasePath:n=>{const o=(n||t.url).pathname.split("/").filter(Boolean),g=o[0];return g&&c.includes(g)&&o.shift(),o.length>0?`/${o.join("/")}`:"/"},addTranslations:(n,l,r=!0)=>{e.addTranslations(n,l,r)},addRouteTranslations:(n,l,r,o=!0)=>{e.addRouteTranslations(n,l,r,o)},mergeTranslations:(n,l,r)=>{e.mergeTranslations(n,l,r)},clearCache:()=>{e.clearCache()}}}function K(t,e={}){const{baseUrl:s="/",addDirAttribute:a=!0,addSeoAttributes:i=!0}=e,c=R(t),u=T(t),l=$(t).filter(h=>!h.disabled),r=l.find(h=>h.code===c);if(!r)return{htmlAttrs:{},link:[],meta:[]};const o=r.iso||c,g=r.dir||"auto",f={htmlAttrs:{lang:o,...a?{dir:g}:{}},link:[],meta:[]};if(!i)return f;const d=`${s}${t.url.pathname}`;f.link.push({rel:"canonical",href:d});const m=B(t),p=l.map(h=>h.code);for(const h of l){let P=t.url.pathname;if(m?.switchLocalePath)P=m.switchLocalePath(t.url.pathname,h.code,p,u);else{const y=t.url.pathname.split("/").filter(Boolean),b=y[0];b&&p.includes(b)&&y.shift(),h.code!==u&&y.unshift(h.code),P=`/${y.join("/")}`}const L=`${s}${P}`;f.link.push({rel:"alternate",href:L,hreflang:h.code}),h.iso&&h.iso!==h.code&&f.link.push({rel:"alternate",href:L,hreflang:h.iso})}{let h=t.url.pathname;if(m?.switchLocalePath)h=m.switchLocalePath(t.url.pathname,u,p,u);else{const P=t.url.pathname.split("/").filter(Boolean),L=P[0];L&&p.includes(L)&&P.shift(),h=`/${P.join("/")}`}f.link.push({rel:"alternate",href:`${s}${h}`,hreflang:"x-default"})}f.meta.push({property:"og:locale",content:o}),f.meta.push({property:"og:url",content:d});for(const h of l)h.code!==c&&f.meta.push({property:"og:locale:alternate",content:h.iso||h.code});return f}function Q(t,e,s){const a=e.split(".");let i=t;for(let u=0;u<a.length-1;u++){const n=a[u];i[n]||(i[n]={}),i=i[n]}const c=a[a.length-1];c!==void 0&&(i[c]=s)}function X(t,e){const s=v(t),a=R(t),i=T(t),c=s.getRoute(),u={};if(e&&e.length>0){const n={};for(const l of e){const r=s.t(l,void 0,void 0,c);r!=null&&r!==l&&Q(n,l,r)}Object.keys(n).length>0&&(u[c]=n)}else{const n=s.getRouteTranslations(a,c);n&&(u[c]=n)}return{locale:a,fallbackLocale:i,currentRoute:c,translations:u}}Object.defineProperty(exports,"FormatService",{enumerable:!0,get:()=>w.FormatService});Object.defineProperty(exports,"defaultPlural",{enumerable:!0,get:()=>w.defaultPlural});Object.defineProperty(exports,"interpolate",{enumerable:!0,get:()=>w.interpolate});exports.AstroI18n=j;exports.createAstroRouterAdapter=z;exports.createI18n=N;exports.createI18nMiddleware=M;exports.detectLocale=W;exports.getDefaultLocale=T;exports.getI18n=v;exports.getI18nProps=X;exports.getLocale=R;exports.getLocaleFromPath=U;exports.getLocales=$;exports.getRouteName=H;exports.i18nIntegration=C;exports.loadTranslationsFromDir=F;exports.loadTranslationsIntoI18n=q;exports.localizePath=J;exports.removeLocaleFromPath=V;exports.switchLocalePath=E;exports.useI18n=G;exports.useLocaleHead=K;