@i18n-micro/astro 1.3.13 → 1.3.18

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.
@@ -0,0 +1 @@
1
+ let e=require("@i18n-micro/core");function t(e,t){if(e===null||typeof t!=`string`)return null;let n=e;if(e[t])n=e[t];else{let e=t.toString().split(`.`);for(let t of e)if(n&&typeof n==`object`&&n&&t in n)n=n[t];else return null}return n??null}function n(n,r,i,a,o){if(!r)return a||r||``;let s=o||n.currentRoute,c=null;return n.translations[s]&&(c=t(n.translations[s],r)),c||=a===void 0?r:a||r,typeof c==`string`&&i?(0,e.interpolate)(c,i):c}function r(e,n,r){let i=r||e.currentRoute,a=e.translations[i];if(a){let e=t(a,n);if(e!==null&&typeof e!=`object`)return!0}return!1}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return r}});
@@ -0,0 +1,28 @@
1
+ import { interpolate as e } from "@i18n-micro/core";
2
+ //#region src/client/core.ts
3
+ function t(e, t) {
4
+ if (e === null || typeof t != "string") return null;
5
+ let n = e;
6
+ if (e[t]) n = e[t];
7
+ else {
8
+ let e = t.toString().split(".");
9
+ for (let t of e) if (n && typeof n == "object" && n && t in n) n = n[t];
10
+ else return null;
11
+ }
12
+ return n ?? null;
13
+ }
14
+ function n(n, r, i, a, o) {
15
+ if (!r) return a || r || "";
16
+ let s = o || n.currentRoute, c = null;
17
+ return n.translations[s] && (c = t(n.translations[s], r)), c ||= a === void 0 ? r : a || r, typeof c == "string" && i ? e(c, i) : c;
18
+ }
19
+ function r(e, n, r) {
20
+ let i = r || e.currentRoute, a = e.translations[i];
21
+ if (a) {
22
+ let e = t(a, n);
23
+ if (e !== null && typeof e != "object") return !0;
24
+ }
25
+ return !1;
26
+ }
27
+ //#endregion
28
+ export { n, r as t };
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("@i18n-micro/core"),J=require("node:async_hooks"),R=require("node:fs"),$=require("node:path"),M=require("@i18n-micro/utils/parse-path"),Z=require("@i18n-micro/utils/accept-language");class v extends j.BaseI18n{constructor(t){const a=t._storage||{translations:new Map};if(super({storage:a,plural:t.plural,missingWarn:t.missingWarn,missingHandler:t.missingHandler,numberFormats:t.numberFormats,datetimeFormats:t.datetimeFormats}),this.initialMessages={},this.storage=a,this._locale=t.locale,this._fallbackLocale=t.fallbackLocale||t.locale,this._currentRoute="index",t.messages){this.initialMessages={...t.messages};for(const[r,c]of Object.entries(t.messages))this.helper.loadTranslations(r,c)}}cloneStorage(t){const a=new Map;for(const[r,c]of t.translations)a.set(r,{...c});return{translations:a}}clone(t){const a=this.cloneStorage(this.storage);return new v({locale:t||this._locale,fallbackLocale:this._fallbackLocale,plural:this.pluralFunc,missingWarn:this.missingWarn,missingHandler:this.missingHandler,numberFormats:this.formatter.getNumberFormats(),datetimeFormats:this.formatter.getDateTimeFormats(),_storage:a})}get locale(){return this._locale}set locale(t){this._locale=t}get fallbackLocale(){return this._fallbackLocale}set fallbackLocale(t){this._fallbackLocale=t}setRoute(t){this._currentRoute=t}getLocale(){return this._locale}getFallbackLocale(){return this._fallbackLocale}getRoute(){return this._currentRoute}getRouteTranslations(t,a){const r=`${t}:${a}`;return this.storage.translations.get(r)??null}addTranslations(t,a,r=!0){super.loadTranslationsCore(t,a,r)}addRouteTranslations(t,a,r,c=!0){super.loadRouteTranslationsCore(t,a,r,c)}mergeTranslations(t,a,r){this.helper.mergeTranslation(t,a,r,!0)}clearCache(){const t={...this.initialMessages};if(super.clearCache(),Object.keys(t).length>0)for(const[a,r]of Object.entries(t))this.helper.loadTranslations(a,r)}}let q=null;const W=new J.AsyncLocalStorage;function C(){const e=W.getStore();return e!==void 0?e:q}function U(e){q=e}function H(e,t){return W.run(e,t)}function K(e){const{locale:t,fallbackLocale:a,translationDir:r,routingStrategy:c}=e;return U(c||null),{name:"@i18n-micro/astro",hooks:{"astro:config:setup":u=>{const{updateConfig:i}=u,o="virtual:i18n-micro/config",s=`\0${o}`,l={defaultLocale:t,fallbackLocale:a||t,locales:e.locales||[],localeCodes:(e.locales||[]).map(n=>n.code),translationDir:r||null,autoDetect:e.autoDetect??!0,redirectToDefault:e.redirectToDefault??!1,localeCookie:e.localeCookie===null?null:e.localeCookie||"i18n-locale",missingWarn:e.missingWarn??!1};i({vite:{plugins:[{name:"vite-plugin-i18n-micro-config",resolveId(n){if(n===o)return s},load(n){if(n===s)return`export const config = ${JSON.stringify(l)}`}}]}})},"astro:config:done":u=>{const{injectTypes:i}=u;i({filename:"i18n-micro-env.d.ts",content:`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@i18n-micro/core"),t=require("node:async_hooks"),n=require("node:fs"),r=require("node:path"),i=require("@i18n-micro/utils/parse-path"),a=require("@i18n-micro/utils/accept-language");var o=class t extends e.BaseI18n{constructor(e){let t=e._storage||{translations:new Map};if(super({storage:t,plural:e.plural,missingWarn:e.missingWarn,missingHandler:e.missingHandler,numberFormats:e.numberFormats,datetimeFormats:e.datetimeFormats}),this.initialMessages={},this.storage=t,this._locale=e.locale,this._fallbackLocale=e.fallbackLocale||e.locale,this._currentRoute=`index`,e.messages){this.initialMessages={...e.messages};for(let[t,n]of Object.entries(e.messages))this.helper.loadTranslations(t,n)}}cloneStorage(e){let t=new Map;for(let[n,r]of e.translations)t.set(n,{...r});return{translations:t}}clone(e){let n=this.cloneStorage(this.storage);return new t({locale:e||this._locale,fallbackLocale:this._fallbackLocale,plural:this.pluralFunc,missingWarn:this.missingWarn,missingHandler:this.missingHandler,numberFormats:this.formatter.getNumberFormats(),datetimeFormats:this.formatter.getDateTimeFormats(),_storage:n})}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,t){let n=`${e}:${t}`;return this.storage.translations.get(n)??null}addTranslations(e,t,n=!0){super.loadTranslationsCore(e,t,n)}addRouteTranslations(e,t,n,r=!0){super.loadRouteTranslationsCore(e,t,n,r)}mergeTranslations(e,t,n){this.helper.mergeTranslation(e,t,n,!0)}clearCache(){let e={...this.initialMessages};if(super.clearCache(),Object.keys(e).length>0)for(let[t,n]of Object.entries(e))this.helper.loadTranslations(t,n)}},s=null,c=new t.AsyncLocalStorage;function l(){let e=c.getStore();return e===void 0?s:e}function u(e){s=e}function d(e,t){return c.run(e,t)}function f(e){let{locale:t,fallbackLocale:n,translationDir:r,routingStrategy:i}=e;return u(i||null),{name:`@i18n-micro/astro`,hooks:{"astro:config:setup":i=>{let{updateConfig:a}=i,o=`virtual:i18n-micro/config`,s=`\0${o}`,c={defaultLocale:t,fallbackLocale:n||t,locales:e.locales||[],localeCodes:(e.locales||[]).map(e=>e.code),translationDir:r||null,autoDetect:e.autoDetect??!0,redirectToDefault:e.redirectToDefault??!1,localeCookie:e.localeCookie===null?null:e.localeCookie||`i18n-locale`,missingWarn:e.missingWarn??!1};a({vite:{plugins:[{name:`vite-plugin-i18n-micro-config`,resolveId(e){if(e===o)return s},load(e){if(e===s)return`export const config = ${JSON.stringify(c)}`}}]}})},"astro:config:done":e=>{let{injectTypes:t}=e;t({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 Q(e){return new v(e)}function z(e,t){if(R.existsSync(e))for(const a of R.readdirSync(e)){const r=$.join(e,a);if(R.statSync(r).isDirectory()){z(r,t);continue}a.endsWith(".json")&&t(r)}}function E(e){const{translationDir:t,rootDir:a=process.cwd(),disablePageLocales:r=!1}=e,c=$.resolve(a,t);if(!R.existsSync(c))return console.warn(`[i18n] Translation directory not found: ${c}`),{root:{},routes:{}};const u={root:{},routes:{}};return z(c,i=>{const o=$.relative(c,i).split($.sep).join("/");try{const s=R.readFileSync(i,"utf-8"),l=JSON.parse(s);M.storeLoadedTranslationFile(u,o,l,r)}catch(s){console.error(`[i18n] Failed to load translation file: ${i}`,s)}}),u}function X(e,t){const{root:a,routes:r}=E(t);for(const[c,u]of Object.entries(a))e.addTranslations(c,u,!1);for(const[c,u]of Object.entries(r))for(const[i,o]of Object.entries(u))e.addRouteTranslations(i,c,M.mergeRouteTranslationsWithRoot(a[i],o),!1)}function Y(e){const{i18n:t,defaultLocale:a,locales:r,localeObjects:c,autoDetect:u=!0,redirectToDefault:i=!1,routingStrategy:o}=e,s=o||C();return async(l,n)=>{if(l.locals.locale&&l.locals.i18n)return n();const f=l.url,d=f.pathname;if(!s){const w=t.clone(a),g=d==="/"||d===""?"index":d.split("/").filter(Boolean).join("-");return w.setRoute(g),l.locals.i18n=w,l.locals.locale=a,l.locals.defaultLocale=a,l.locals.locales=c||r.map(L=>({code:L})),l.locals.currentUrl=f,n()}const h={...s,getCurrentPath:()=>d,getRoute:()=>({fullPath:f.pathname+f.search,query:Object.fromEntries(f.searchParams)})},m=d.split("/").filter(Boolean)[0],b=m!==void 0&&r.includes(m);let P;b&&m?P=m:h.getLocaleFromPath?P=h.getLocaleFromPath(d,a,r):P=a;const y=t.clone(P),T=h.getRouteName?h.getRouteName(d,r):"index";return y.setRoute(T),l.locals.i18n=y,l.locals.locale=P,l.locals.defaultLocale=a,l.locals.locales=c||r.map(w=>({code:w})),l.locals.currentUrl=f,l.locals.routingStrategy=h,H(h,()=>n())}}function ee(e,t,a,r,c,u="i18n-locale",i){const o=i??C();let s=r;if(o?.getLocaleFromPath)s=o.getLocaleFromPath(e,r,c);else{const n=e.split("/").filter(Boolean)[0];n&&c.includes(n)&&(s=n)}if(u!==null&&s===r&&t.get(u)){const l=t.get(u)?.value;l&&c.includes(l)&&(s=l)}if(s===r)try{const l=Z.detectLocaleFromAcceptLanguage(a.get("accept-language")??void 0,c);l&&(s=l)}catch{}return s}function te(e,t,a){const r=e.map(n=>n.code),c=(n,f=[])=>{const d=n.replace(/^\//,"").replace(/\/$/,"");if(!d)return"index";const h=d.split("/").filter(Boolean),p=h[0];return p&&f.includes(p)&&h.shift(),h.length===0?"index":h.join("-")},u=(n,f="en",d=[])=>{const p=n.split("/").filter(Boolean)[0];return p&&d.includes(p)?p:f},i=(n,f,d=[],h)=>{const p=n.split("/").filter(Boolean),m=p[0];return m&&d.includes(m)&&p.shift(),(f!==h||h===void 0)&&p.unshift(f),`/${p.join("/")}`},o=(n,f,d=[],h)=>{const m=(n.replace(/^\//,"").replace(/\/$/,"")||"").split("/").filter(Boolean),b=m[0];return b&&d.includes(b)&&m.shift(),(f!==h||h===void 0)&&m.unshift(f),`/${m.join("/")}`};return{getCurrentPath:()=>a?a().pathname:typeof window<"u"?window.location.pathname:"/",getRouteName:c,getLocaleFromPath:u,switchLocalePath:i,localizePath:o,removeLocaleFromPath:(n,f=[])=>{const d=n.split("/").filter(Boolean),h=d[0];return h&&f.includes(h)&&d.shift(),`/${d.join("/")}`},resolvePath:(n,f)=>{const d=typeof n=="string"?n:n.path||"/";return o(d,f,r,t)},getRoute:()=>{if(a){const n=a();return{fullPath:n.pathname+n.search,query:Object.fromEntries(n.searchParams)}}if(typeof window<"u"){const n=new URL(window.location.href);return{fullPath:n.pathname+n.search,query:Object.fromEntries(n.searchParams)}}return{fullPath:"/",query:{}}},push:n=>{typeof window<"u"&&(window.location.href=n.path)},replace:n=>{typeof window<"u"&&window.location.replace(n.path)}}}function I(e){return e.iso?.trim()||String(e.code)}function N(e){const t=e.match(/^([A-Za-z]{2,3})(?:[-_](.+))?$/);return t?{language:t[1],region:t[2]}:{language:e}}function ne(e,t={}){const{hreflangBaseLanguage:a=!1}=t;if(!a)return e.map(i=>{const o=String(i.code);return{hreflang:I(i),localeCode:o}});const r=new Map;for(const i of e){const o=String(i.code),s=I(i),{language:l,region:n}=N(s);l&&n&&!r.has(l)&&r.set(l,o),r.set(s,o)}const c=new Set,u=[];for(const i of e){const o=String(i.code),s=I(i),{language:l,region:n}=N(s);l&&n&&r.get(l)===o&&!c.has(l)&&(c.add(l),u.push({hreflang:l,localeCode:o})),c.has(s)||(c.add(s),u.push({hreflang:s,localeCode:o}))}return u}function _(e){const t=e.og?.trim();if(t)return t;const a=e.iso?.trim();if(!a)return null;const r=a.indexOf("_");if(r>0){const u=a.slice(0,r),i=a.slice(r+1);if(u.length>=2&&i.length===2)return`${u.toLowerCase()}_${i.toUpperCase()}`}const c=a.indexOf("-");if(c>0){const u=a.slice(0,c),i=a.slice(c+1);if(u.length>=2&&i.length===2&&/^[A-Za-z]{2}$/.test(i))return`${u.toLowerCase()}_${i.toUpperCase()}`}return null}function A(e,t={}){if(_(e)!==null||t.missingWarn===!1||process.env.NODE_ENV==="production")return;const a=t.tag??"og:locale",r=String(e.code??"unknown"),c=e.iso?`, iso: '${e.iso}'`:"";console.warn(`[i18n] Cannot derive ${a} for locale '${r}'${c}. Set locale.og (e.g. 'en_US') or use iso with a 2-letter region (e.g. 'en-US').`)}function O(e){const t=e.locals.i18n;if(!t)throw new Error("i18n instance not found. Make sure i18n middleware is configured.");return t}function F(e){return e.locals.locale||"en"}function k(e){return e.locals.defaultLocale||"en"}function D(e){return e.locals.locales||[]}function x(e){return e.locals.routingStrategy||null}function G(e){const t=O(e),a=F(e),r=k(e),c=D(e),u=c.map(o=>o.code),i=x(e);return{locale:a,defaultLocale:r,locales:c,t:(o,s,l,n)=>t.t(o,s,l,n),ts:(o,s,l,n)=>t.ts(o,s,l,n),tc:(o,s,l)=>t.tc(o,s,l),tn:t.tn.bind(t),td:t.td.bind(t),tdr:t.tdr.bind(t),has:(o,s)=>t.has(o,s),getRoute:()=>t.getRoute(),getRouteName:o=>{const s=o||e.url.pathname;if(i?.getRouteName)return i.getRouteName(s,u);const l=s.replace(/^\//,"").replace(/\/$/,"");if(!l)return"index";const n=l.split("/").filter(Boolean),f=n[0];return f&&u.includes(f)&&n.shift(),n.length===0?"index":n.join("-")},getLocaleFromPath:o=>{const s=o||e.url.pathname;if(i?.getLocaleFromPath)return i.getLocaleFromPath(s,r,u);const n=s.split("/").filter(Boolean)[0];return n&&u.includes(n)?n:r},switchLocalePath:o=>{if(i?.switchLocalePath)return i.switchLocalePath(e.url.pathname,o,u,r);const s=e.url.pathname.split("/").filter(Boolean),l=s[0];return l&&u.includes(l)&&s.shift(),o!==r&&s.unshift(o),`/${s.join("/")}`},localizePath:(o,s)=>{if(i?.localizePath)return i.localizePath(o,s||a,u,r);const n=(o.replace(/^\//,"").replace(/\/$/,"")||"").split("/").filter(Boolean),f=n[0];return f&&u.includes(f)&&n.shift(),s&&s!==r&&n.unshift(s),`/${n.join("/")}`},getI18n:()=>t,getBasePath:o=>{const n=(o||e.url).pathname.split("/").filter(Boolean),f=n[0];return f&&u.includes(f)&&n.shift(),n.length>0?`/${n.join("/")}`:"/"},addTranslations:(o,s,l=!0)=>{t.addTranslations(o,s,l)},addRouteTranslations:(o,s,l,n=!0)=>{t.addRouteTranslations(o,s,l,n)},mergeTranslations:(o,s,l)=>{t.mergeTranslations(o,s,l)},clearCache:()=>{t.clearCache()}}}function V(e){const t=e.locals.currentUrl??e.url;return G(e).getBasePath(t)}function oe(e){const{locale:t}=e.params,a=D(e).map(c=>c.code);if(!t||!a.includes(t))return new Response(null,{status:404});const r=e.locals.i18n;return r&&(r.locale=t,e.locals.locale=t),V(e)}function ae(e,t={}){const{baseUrl:a="/",addDirAttribute:r=!0,addSeoAttributes:c=!0,hreflangBaseLanguage:u=!1}=t,i=F(e),o=k(e),l=D(e).filter(g=>!g.disabled),n=l.filter(g=>g.seo!==!1),f=l.find(g=>g.code===i);if(!f)return{htmlAttrs:{},link:[],meta:[]};const d=f.iso||i,h=_(f),p=f.dir||"auto",m={htmlAttrs:{lang:d,...r?{dir:p}:{}},link:[],meta:[]};if(!c)return m;const b=`${a}${e.url.pathname}`;m.link.push({rel:"canonical",href:b});const P=x(e),y=l.map(g=>g.code),T=new Map;for(const g of n){let L=e.url.pathname;if(P?.switchLocalePath)L=P.switchLocalePath(e.url.pathname,g.code,y,o);else{const S=e.url.pathname.split("/").filter(Boolean),B=S[0];B&&y.includes(B)&&S.shift(),g.code!==o&&S.unshift(g.code),L=`/${S.join("/")}`}T.set(String(g.code),`${a}${L}`)}for(const{hreflang:g,localeCode:L}of ne(n,{hreflangBaseLanguage:u})){const S=T.get(L);S&&m.link.push({rel:"alternate",href:S,hreflang:g})}if(l.find(g=>g.code===o)?.seo!==!1){let g=e.url.pathname;if(P?.switchLocalePath)g=P.switchLocalePath(e.url.pathname,o,y,o);else{const L=e.url.pathname.split("/").filter(Boolean),S=L[0];S&&y.includes(S)&&L.shift(),g=`/${L.join("/")}`}m.link.push({rel:"alternate",href:`${a}${g}`,hreflang:"x-default"})}h?m.meta.push({property:"og:locale",content:h}):A(f,{tag:"og:locale"}),m.meta.push({property:"og:url",content:b});for(const g of n){if(g.code===i)continue;const L=_(g);if(!L){A(g,{tag:"og:locale:alternate"});continue}m.meta.push({property:"og:locale:alternate",content:L})}return m}function re(e,t,a){const r=t.split(".");let c=e;for(let i=0;i<r.length-1;i++){const o=r[i];c[o]||(c[o]={}),c=c[o]}const u=r[r.length-1];u!==void 0&&(c[u]=a)}function le(e,t){const a=O(e),r=F(e),c=k(e),u=a.getRoute(),i={};if(t&&t.length>0){const o={};for(const s of t){const l=a.t(s,void 0,void 0,u);l!=null&&l!==s&&re(o,s,l)}Object.keys(o).length>0&&(i[u]=o)}else{const o=a.getRouteTranslations(r,u);o&&(i[u]=o)}return{locale:r,fallbackLocale:c,currentRoute:u,translations:i}}Object.defineProperty(exports,"FormatService",{enumerable:!0,get:()=>j.FormatService});Object.defineProperty(exports,"defaultPlural",{enumerable:!0,get:()=>j.defaultPlural});Object.defineProperty(exports,"interpolate",{enumerable:!0,get:()=>j.interpolate});exports.AstroI18n=v;exports.createAstroRouterAdapter=te;exports.createI18n=Q;exports.createI18nMiddleware=Y;exports.detectLocale=ee;exports.getDefaultLocale=k;exports.getGlobalRoutingStrategy=C;exports.getI18n=O;exports.getI18nProps=le;exports.getLocale=F;exports.getLocaleRewritePath=V;exports.getLocales=D;exports.i18nIntegration=K;exports.loadTranslationsFromDir=E;exports.loadTranslationsIntoI18n=X;exports.prepareLocaleRewrite=oe;exports.runWithRoutingStrategy=H;exports.setGlobalRoutingStrategy=U;exports.useI18n=G;exports.useLocaleHead=ae;
17
+ `})}}}}function p(e){return new o(e)}function m(e,t){if((0,n.existsSync)(e))for(let i of(0,n.readdirSync)(e)){let a=(0,r.join)(e,i);if((0,n.statSync)(a).isDirectory()){m(a,t);continue}i.endsWith(`.json`)&&t(a)}}function h(e){let{translationDir:t,rootDir:a=process.cwd(),disablePageLocales:o=!1}=e,s=(0,r.resolve)(a,t);if(!(0,n.existsSync)(s))return console.warn(`[i18n] Translation directory not found: ${s}`),{root:{},routes:{}};let c={root:{},routes:{}};return m(s,e=>{let t=(0,r.relative)(s,e).split(r.sep).join(`/`);try{let r=(0,n.readFileSync)(e,`utf-8`),a=JSON.parse(r);(0,i.storeLoadedTranslationFile)(c,t,a,o)}catch(t){console.error(`[i18n] Failed to load translation file: ${e}`,t)}}),c}function g(e,t){let{root:n,routes:r}=h(t);for(let[t,r]of Object.entries(n))e.addTranslations(t,r,!1);for(let[t,a]of Object.entries(r))for(let[r,o]of Object.entries(a))e.addRouteTranslations(r,t,(0,i.mergeRouteTranslationsWithRoot)(n[r],o),!1)}function _(e){let{i18n:t,defaultLocale:n,locales:r,localeObjects:i,autoDetect:a=!0,redirectToDefault:o=!1,routingStrategy:s}=e,c=s||l();return async(e,a)=>{if(e.locals.locale&&e.locals.i18n)return a();let o=e.url,s=o.pathname;if(!c){let c=t.clone(n),l=s===`/`||s===``?`index`:s.split(`/`).filter(Boolean).join(`-`);return c.setRoute(l),e.locals.i18n=c,e.locals.locale=n,e.locals.defaultLocale=n,e.locals.locales=i||r.map(e=>({code:e})),e.locals.currentUrl=o,a()}let l={...c,getCurrentPath:()=>s,getRoute:()=>({fullPath:o.pathname+o.search,query:Object.fromEntries(o.searchParams)})},u=s.split(`/`).filter(Boolean)[0],f=u!==void 0&&r.includes(u),p;p=f&&u?u:l.getLocaleFromPath?l.getLocaleFromPath(s,n,r):n;let m=t.clone(p),h=l.getRouteName?l.getRouteName(s,r):`index`;return m.setRoute(h),e.locals.i18n=m,e.locals.locale=p,e.locals.defaultLocale=n,e.locals.locales=i||r.map(e=>({code:e})),e.locals.currentUrl=o,e.locals.routingStrategy=l,d(l,()=>a())}}function v(e,t,n,r,i,o=`i18n-locale`,s){let c=s??l(),u=r;if(c?.getLocaleFromPath)u=c.getLocaleFromPath(e,r,i);else{let t=e.split(`/`).filter(Boolean)[0];t&&i.includes(t)&&(u=t)}if(o!==null&&u===r&&t.get(o)){let e=t.get(o)?.value;e&&i.includes(e)&&(u=e)}if(u===r)try{let e=(0,a.detectLocaleFromAcceptLanguage)(n.get(`accept-language`)??void 0,i);e&&(u=e)}catch{}return u}function y(e,t,n){let r=e.map(e=>e.code),i=(e,t=[])=>{let n=e.replace(/^\//,``).replace(/\/$/,``);if(!n)return`index`;let r=n.split(`/`).filter(Boolean),i=r[0];return i&&t.includes(i)&&r.shift(),r.length===0?`index`:r.join(`-`)},a=(e,t=`en`,n=[])=>{let r=e.split(`/`).filter(Boolean)[0];return r&&n.includes(r)?r:t},o=(e,t,n=[],r)=>{let i=e.split(`/`).filter(Boolean),a=i[0];return a&&n.includes(a)&&i.shift(),(t!==r||r===void 0)&&i.unshift(t),`/${i.join(`/`)}`},s=(e,t,n=[],r)=>{let i=(e.replace(/^\//,``).replace(/\/$/,``)||``).split(`/`).filter(Boolean),a=i[0];return a&&n.includes(a)&&i.shift(),(t!==r||r===void 0)&&i.unshift(t),`/${i.join(`/`)}`};return{getCurrentPath:()=>n?n().pathname:typeof window<`u`?window.location.pathname:`/`,getRouteName:i,getLocaleFromPath:a,switchLocalePath:o,localizePath:s,removeLocaleFromPath:(e,t=[])=>{let n=e.split(`/`).filter(Boolean),r=n[0];return r&&t.includes(r)&&n.shift(),`/${n.join(`/`)}`},resolvePath:(e,n)=>{let i=typeof e==`string`?e:e.path||`/`;return s(i,n,r,t)},getRoute:()=>{if(n){let e=n();return{fullPath:e.pathname+e.search,query:Object.fromEntries(e.searchParams)}}if(typeof window<`u`){let e=new URL(window.location.href);return{fullPath:e.pathname+e.search,query:Object.fromEntries(e.searchParams)}}return{fullPath:`/`,query:{}}},push:e=>{typeof window<`u`&&(window.location.href=e.path)},replace:e=>{typeof window<`u`&&window.location.replace(e.path)}}}function b(e){return e.iso?.trim()||String(e.code)}function x(e){let t=e.match(/^([A-Za-z]{2,3})(?:[-_](.+))?$/);return t?{language:t[1],region:t[2]}:{language:e}}function S(e,t={}){let{hreflangBaseLanguage:n=!1}=t;if(!n)return e.map(e=>{let t=String(e.code);return{hreflang:b(e),localeCode:t}});let r=new Map;for(let t of e){let e=String(t.code),n=b(t),{language:i,region:a}=x(n);i&&a&&!r.has(i)&&r.set(i,e),r.set(n,e)}let i=new Set,a=[];for(let t of e){let e=String(t.code),n=b(t),{language:o,region:s}=x(n);o&&s&&r.get(o)===e&&!i.has(o)&&(i.add(o),a.push({hreflang:o,localeCode:e})),i.has(n)||(i.add(n),a.push({hreflang:n,localeCode:e}))}return a}function C(e){let t=e.og?.trim();if(t)return t;let n=e.iso?.trim();if(!n)return null;let r=n.indexOf(`_`);if(r>0){let e=n.slice(0,r),t=n.slice(r+1);if(e.length>=2&&t.length===2)return`${e.toLowerCase()}_${t.toUpperCase()}`}let i=n.indexOf(`-`);if(i>0){let e=n.slice(0,i),t=n.slice(i+1);if(e.length>=2&&t.length===2&&/^[A-Za-z]{2}$/.test(t))return`${e.toLowerCase()}_${t.toUpperCase()}`}return null}function w(e,t={}){if(C(e)!==null||t.missingWarn===!1||process.env.NODE_ENV===`production`)return;let n=t.tag??`og:locale`,r=String(e.code??`unknown`),i=e.iso?`, iso: '${e.iso}'`:``;console.warn(`[i18n] Cannot derive ${n} for locale '${r}'${i}. Set locale.og (e.g. 'en_US') or use iso with a 2-letter region (e.g. 'en-US').`)}function T(e){let t=e.locals.i18n;if(!t)throw Error(`i18n instance not found. Make sure i18n middleware is configured.`);return t}function E(e){return e.locals.locale||`en`}function D(e){return e.locals.defaultLocale||`en`}function O(e){return e.locals.locales||[]}function k(e){return e.locals.routingStrategy||null}function A(e){let t=T(e),n=E(e),r=D(e),i=O(e),a=i.map(e=>e.code),o=k(e);return{locale:n,defaultLocale:r,locales:i,t:(e,n,r,i)=>t.t(e,n,r,i),ts:(e,n,r,i)=>t.ts(e,n,r,i),tc:(e,n,r)=>t.tc(e,n,r),tn:t.tn.bind(t),td:t.td.bind(t),tdr:t.tdr.bind(t),has:(e,n)=>t.has(e,n),getRoute:()=>t.getRoute(),getRouteName:t=>{let n=t||e.url.pathname;if(o?.getRouteName)return o.getRouteName(n,a);let r=n.replace(/^\//,``).replace(/\/$/,``);if(!r)return`index`;let i=r.split(`/`).filter(Boolean),s=i[0];return s&&a.includes(s)&&i.shift(),i.length===0?`index`:i.join(`-`)},getLocaleFromPath:t=>{let n=t||e.url.pathname;if(o?.getLocaleFromPath)return o.getLocaleFromPath(n,r,a);let i=n.split(`/`).filter(Boolean)[0];return i&&a.includes(i)?i:r},switchLocalePath:t=>{if(o?.switchLocalePath)return o.switchLocalePath(e.url.pathname,t,a,r);let n=e.url.pathname.split(`/`).filter(Boolean),i=n[0];return i&&a.includes(i)&&n.shift(),t!==r&&n.unshift(t),`/${n.join(`/`)}`},localizePath:(e,t)=>{if(o?.localizePath)return o.localizePath(e,t||n,a,r);let i=(e.replace(/^\//,``).replace(/\/$/,``)||``).split(`/`).filter(Boolean),s=i[0];return s&&a.includes(s)&&i.shift(),t&&t!==r&&i.unshift(t),`/${i.join(`/`)}`},getI18n:()=>t,getBasePath:t=>{let n=(t||e.url).pathname.split(`/`).filter(Boolean),r=n[0];return r&&a.includes(r)&&n.shift(),n.length>0?`/${n.join(`/`)}`:`/`},addTranslations:(e,n,r=!0)=>{t.addTranslations(e,n,r)},addRouteTranslations:(e,n,r,i=!0)=>{t.addRouteTranslations(e,n,r,i)},mergeTranslations:(e,n,r)=>{t.mergeTranslations(e,n,r)},clearCache:()=>{t.clearCache()}}}function j(e){let t=e.locals.currentUrl??e.url;return A(e).getBasePath(t)}function M(e){let{locale:t}=e.params,n=O(e).map(e=>e.code);if(!t||!n.includes(t))return new Response(null,{status:404});let r=e.locals.i18n;return r&&(r.locale=t,e.locals.locale=t),j(e)}function N(e,t={}){let{baseUrl:n=`/`,addDirAttribute:r=!0,addSeoAttributes:i=!0,hreflangBaseLanguage:a=!1}=t,o=E(e),s=D(e),c=O(e).filter(e=>!e.disabled),l=c.filter(e=>e.seo!==!1),u=c.find(e=>e.code===o);if(!u)return{htmlAttrs:{},link:[],meta:[]};let d=u.iso||o,f=C(u),p=u.dir||`auto`,m={htmlAttrs:{lang:d,...r?{dir:p}:{}},link:[],meta:[]};if(!i)return m;let h=`${n}${e.url.pathname}`;m.link.push({rel:`canonical`,href:h});let g=k(e),_=c.map(e=>e.code),v=new Map;for(let t of l){let r=e.url.pathname;if(g?.switchLocalePath)r=g.switchLocalePath(e.url.pathname,t.code,_,s);else{let n=e.url.pathname.split(`/`).filter(Boolean),i=n[0];i&&_.includes(i)&&n.shift(),t.code!==s&&n.unshift(t.code),r=`/${n.join(`/`)}`}v.set(String(t.code),`${n}${r}`)}for(let{hreflang:e,localeCode:t}of S(l,{hreflangBaseLanguage:a})){let n=v.get(t);n&&m.link.push({rel:`alternate`,href:n,hreflang:e})}if(c.find(e=>e.code===s)?.seo!==!1){let t=e.url.pathname;if(g?.switchLocalePath)t=g.switchLocalePath(e.url.pathname,s,_,s);else{let n=e.url.pathname.split(`/`).filter(Boolean),r=n[0];r&&_.includes(r)&&n.shift(),t=`/${n.join(`/`)}`}m.link.push({rel:`alternate`,href:`${n}${t}`,hreflang:`x-default`})}f?m.meta.push({property:`og:locale`,content:f}):w(u,{tag:`og:locale`}),m.meta.push({property:`og:url`,content:h});for(let e of l){if(e.code===o)continue;let t=C(e);if(!t){w(e,{tag:`og:locale:alternate`});continue}m.meta.push({property:`og:locale:alternate`,content:t})}return m}function P(e,t,n){let r=t.split(`.`),i=e;for(let e=0;e<r.length-1;e++){let t=r[e];i[t]||(i[t]={}),i=i[t]}let a=r[r.length-1];a!==void 0&&(i[a]=n)}function F(e,t){let n=T(e),r=E(e),i=D(e),a=n.getRoute(),o={};if(t&&t.length>0){let e={};for(let r of t){let t=n.t(r,void 0,void 0,a);t!=null&&t!==r&&P(e,r,t)}Object.keys(e).length>0&&(o[a]=e)}else{let e=n.getRouteTranslations(r,a);e&&(o[a]=e)}return{locale:r,fallbackLocale:i,currentRoute:a,translations:o}}exports.AstroI18n=o,Object.defineProperty(exports,"FormatService",{enumerable:!0,get:function(){return e.FormatService}}),exports.createAstroRouterAdapter=y,exports.createI18n=p,exports.createI18nMiddleware=_,Object.defineProperty(exports,"defaultPlural",{enumerable:!0,get:function(){return e.defaultPlural}}),exports.detectLocale=v,exports.getDefaultLocale=D,exports.getGlobalRoutingStrategy=l,exports.getI18n=T,exports.getI18nProps=F,exports.getLocale=E,exports.getLocaleRewritePath=j,exports.getLocales=O,exports.i18nIntegration=f,Object.defineProperty(exports,"interpolate",{enumerable:!0,get:function(){return e.interpolate}}),exports.loadTranslationsFromDir=h,exports.loadTranslationsIntoI18n=g,exports.prepareLocaleRewrite=M,exports.runWithRoutingStrategy=d,exports.setGlobalRoutingStrategy=u,exports.useI18n=A,exports.useLocaleHead=N;