@i18n-micro/astro 1.1.0 → 1.2.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,4 +1,4 @@
1
- import { Translations, Params } from '@i18n-micro/types';
1
+ import { Params, Translations } from '@i18n-micro/types';
2
2
  /**
3
3
  * Состояние i18n для клиентских островов
4
4
  */
@@ -1,6 +1,6 @@
1
- export { translate, hasTranslation } from './core';
2
1
  export type { I18nState } from './core';
3
- export { provideI18n, useAstroI18n as useAstroI18nVue } from './vue';
4
- export { I18nProvider, useAstroI18n as useAstroI18nReact } from './react';
2
+ export { hasTranslation, translate } from './core';
5
3
  export { I18nProvider as I18nProviderPreact, useAstroI18n as useAstroI18nPreact } from './preact';
4
+ export { I18nProvider, useAstroI18n as useAstroI18nReact } from './react';
6
5
  export { createI18nStore, useAstroI18n as useAstroI18nSvelte } from './svelte';
6
+ export { provideI18n, useAstroI18n as useAstroI18nVue } from './vue';
@@ -1,17 +1,17 @@
1
1
  import { h as s, t as o } from "../core-D32Y48CN.js";
2
- import { provideI18n as a, useAstroI18n as n } from "./vue.js";
2
+ import { I18nProvider as a, useAstroI18n as n } from "./preact.js";
3
3
  import { I18nProvider as u, useAstroI18n as A } from "./react.js";
4
- import { I18nProvider as f, useAstroI18n as i } from "./preact.js";
5
- import { createI18nStore as v, useAstroI18n as x } from "./svelte.js";
4
+ import { createI18nStore as f, useAstroI18n as i } from "./svelte.js";
5
+ import { provideI18n as v, useAstroI18n as x } from "./vue.js";
6
6
  export {
7
7
  u as I18nProvider,
8
- f as I18nProviderPreact,
9
- v as createI18nStore,
8
+ a as I18nProviderPreact,
9
+ f as createI18nStore,
10
10
  s as hasTranslation,
11
- a as provideI18n,
11
+ v as provideI18n,
12
12
  o as translate,
13
- i as useAstroI18nPreact,
13
+ n as useAstroI18nPreact,
14
14
  A as useAstroI18nReact,
15
- x as useAstroI18nSvelte,
16
- n as useAstroI18nVue
15
+ i as useAstroI18nSvelte,
16
+ x as useAstroI18nVue
17
17
  };
@@ -1,7 +1,7 @@
1
+ import { CleanTranslation, Params, TranslationKey } from '@i18n-micro/types';
1
2
  import { ComponentChildren } from 'preact';
2
3
  import { I18nClientProps } from '../utils';
3
4
  import { I18nState } from './core';
4
- import { Params, TranslationKey, CleanTranslation } from '@i18n-micro/types';
5
5
  /**
6
6
  * Провайдер для i18n в Preact островах
7
7
  */
@@ -1,33 +1,48 @@
1
- import { createContext as g, createElement as w } from "preact";
2
- import { useState as x, useContext as L, useMemo as a } from "preact/hooks";
3
- import { t as P, h as S } from "../core-D32Y48CN.js";
4
- import { FormatService as C, defaultPlural as A } from "@i18n-micro/core";
5
- const s = new C(), i = g(null), F = ({ children: t, value: o }) => {
6
- const [l] = x(() => ({
1
+ import { FormatService as g, defaultPlural as w } from "@i18n-micro/core";
2
+ import { createContext as x, createElement as L } from "preact";
3
+ import { useState as P, useContext as S, useMemo as a } from "preact/hooks";
4
+ import { t as C, h as A } from "../core-D32Y48CN.js";
5
+ const s = new g(), i = x(null), F = ({ children: t, value: o }) => {
6
+ const [l] = P(() => ({
7
7
  locale: o.locale,
8
8
  fallbackLocale: o.fallbackLocale,
9
9
  translations: o.translations,
10
10
  currentRoute: o.currentRoute
11
11
  }));
12
- return w(i.Provider, { value: l }, t);
12
+ return L(i.Provider, { value: l }, t);
13
13
  };
14
14
  function M() {
15
- const t = L(i);
15
+ const t = S(i);
16
16
  if (!t)
17
17
  throw new Error("useAstroI18n must be used within an I18nProvider");
18
- const o = a(() => (r, e, n, c) => P(t, r, e, n, c), [t]), l = a(() => (r, e, n, c) => o(r, e, n, c)?.toString() ?? n ?? r, [o]), m = a(() => (r, e, n) => {
19
- const { count: c, ...u } = typeof e == "number" ? { count: e } : e;
20
- if (c === void 0)
21
- return n ?? r;
22
- const d = (v, I, h) => o(v, I, h);
23
- return A(
24
- r,
25
- Number.parseInt(c.toString(), 10),
26
- u,
27
- t.locale,
28
- d
29
- ) ?? n ?? r;
30
- }, [o, t]), f = a(() => (r, e) => s.formatNumber(r, t.locale, e), [t.locale]), b = a(() => (r, e) => s.formatDate(r, t.locale, e), [t.locale]), p = a(() => (r, e) => s.formatRelativeTime(r, t.locale, e), [t.locale]), R = a(() => (r, e) => S(t, r, e), [t]);
18
+ const o = a(
19
+ () => (r, e, n, c) => C(t, r, e, n, c),
20
+ [t]
21
+ ), l = a(
22
+ () => (r, e, n, c) => o(r, e, n, c)?.toString() ?? n ?? r,
23
+ [o]
24
+ ), m = a(
25
+ () => (r, e, n) => {
26
+ const { count: c, ...u } = typeof e == "number" ? { count: e } : e;
27
+ if (c === void 0)
28
+ return n ?? r;
29
+ const d = (v, I, h) => o(v, I, h);
30
+ return w(r, Number.parseInt(c.toString(), 10), u, t.locale, d) ?? n ?? r;
31
+ },
32
+ [o, t]
33
+ ), f = a(
34
+ () => (r, e) => s.formatNumber(r, t.locale, e),
35
+ [t.locale]
36
+ ), b = a(
37
+ () => (r, e) => s.formatDate(r, t.locale, e),
38
+ [t.locale]
39
+ ), p = a(
40
+ () => (r, e) => s.formatRelativeTime(r, t.locale, e),
41
+ [t.locale]
42
+ ), R = a(
43
+ () => (r, e) => A(t, r, e),
44
+ [t]
45
+ );
31
46
  return {
32
47
  // Translation methods
33
48
  t: o,
@@ -1,6 +1,6 @@
1
+ import { CleanTranslation, Params, TranslationKey } from '@i18n-micro/types';
1
2
  import { default as React } from 'react';
2
3
  import { I18nClientProps } from '../utils';
3
- import { Params, TranslationKey, CleanTranslation } from '@i18n-micro/types';
4
4
  /**
5
5
  * Провайдер для i18n в React островах
6
6
  */
@@ -1,33 +1,48 @@
1
- import g, { createContext as w, useState as x, useContext as L, useMemo as a } from "react";
2
- import { t as P, h as S } from "../core-D32Y48CN.js";
3
- import { FormatService as C, defaultPlural as A } from "@i18n-micro/core";
4
- const s = new C(), i = w(null);
1
+ import { FormatService as g, defaultPlural as w } from "@i18n-micro/core";
2
+ import x, { createContext as L, useState as P, useContext as S, useMemo as a } from "react";
3
+ import { t as C, h as A } from "../core-D32Y48CN.js";
4
+ const s = new g(), i = L(null);
5
5
  function D({ children: t, value: o }) {
6
- const [l] = x(() => ({
6
+ const [l] = P(() => ({
7
7
  locale: o.locale,
8
8
  fallbackLocale: o.fallbackLocale,
9
9
  translations: o.translations,
10
10
  currentRoute: o.currentRoute
11
11
  }));
12
- return g.createElement(i.Provider, { value: l }, t);
12
+ return x.createElement(i.Provider, { value: l }, t);
13
13
  }
14
14
  function F() {
15
- const t = L(i);
15
+ const t = S(i);
16
16
  if (!t)
17
17
  throw new Error("useAstroI18n must be used within an I18nProvider");
18
- const o = a(() => (e, r, n, c) => P(t, e, r, n, c), [t]), l = a(() => (e, r, n, c) => o(e, r, n, c)?.toString() ?? n ?? e, [o]), m = a(() => (e, r, n) => {
19
- const { count: c, ...u } = typeof r == "number" ? { count: r } : r;
20
- if (c === void 0)
21
- return n ?? e;
22
- const d = (v, I, h) => o(v, I, h);
23
- return A(
24
- e,
25
- Number.parseInt(c.toString(), 10),
26
- u,
27
- t.locale,
28
- d
29
- ) ?? n ?? e;
30
- }, [o, t]), f = a(() => (e, r) => s.formatNumber(e, t.locale, r), [t.locale]), b = a(() => (e, r) => s.formatDate(e, t.locale, r), [t.locale]), R = a(() => (e, r) => s.formatRelativeTime(e, t.locale, r), [t.locale]), p = a(() => (e, r) => S(t, e, r), [t]);
18
+ const o = a(
19
+ () => (e, r, n, c) => C(t, e, r, n, c),
20
+ [t]
21
+ ), l = a(
22
+ () => (e, r, n, c) => o(e, r, n, c)?.toString() ?? n ?? e,
23
+ [o]
24
+ ), m = a(
25
+ () => (e, r, n) => {
26
+ const { count: c, ...u } = typeof r == "number" ? { count: r } : r;
27
+ if (c === void 0)
28
+ return n ?? e;
29
+ const d = (v, I, h) => o(v, I, h);
30
+ return w(e, Number.parseInt(c.toString(), 10), u, t.locale, d) ?? n ?? e;
31
+ },
32
+ [o, t]
33
+ ), f = a(
34
+ () => (e, r) => s.formatNumber(e, t.locale, r),
35
+ [t.locale]
36
+ ), b = a(
37
+ () => (e, r) => s.formatDate(e, t.locale, r),
38
+ [t.locale]
39
+ ), R = a(
40
+ () => (e, r) => s.formatRelativeTime(e, t.locale, r),
41
+ [t.locale]
42
+ ), p = a(
43
+ () => (e, r) => A(t, e, r),
44
+ [t]
45
+ );
31
46
  return {
32
47
  // Translation methods
33
48
  t: o,
@@ -1,7 +1,7 @@
1
+ import { CleanTranslation, Params, TranslationKey } from '@i18n-micro/types';
1
2
  import { Writable } from 'svelte/store';
2
3
  import { I18nClientProps } from '../utils';
3
4
  import { I18nState } from './core';
4
- import { Params, TranslationKey, CleanTranslation } from '@i18n-micro/types';
5
5
  /**
6
6
  * Создает Svelte store для i18n состояния
7
7
  */
@@ -1,9 +1,9 @@
1
- import { writable as R, get as b } from "svelte/store";
2
- import { h as d, t as v } from "../core-D32Y48CN.js";
3
- import { FormatService as L, defaultPlural as S } from "@i18n-micro/core";
4
- const l = new L();
1
+ import { FormatService as R, defaultPlural as b } from "@i18n-micro/core";
2
+ import { writable as d, get as v } from "svelte/store";
3
+ import { h as L, t as S } from "../core-D32Y48CN.js";
4
+ const l = new R();
5
5
  function F(o) {
6
- return R({
6
+ return d({
7
7
  locale: o.locale,
8
8
  fallbackLocale: o.fallbackLocale,
9
9
  translations: o.translations,
@@ -11,7 +11,7 @@ function F(o) {
11
11
  });
12
12
  }
13
13
  function P(o) {
14
- const n = () => b(o), c = (t, e, r, a) => v(n(), t, e, r, a);
14
+ const n = () => v(o), c = (t, e, r, a) => S(n(), t, e, r, a);
15
15
  return {
16
16
  // Store для реактивности в шаблонах (используйте $i18nStore в шаблонах)
17
17
  store: o,
@@ -23,13 +23,7 @@ function P(o) {
23
23
  if (u === void 0)
24
24
  return r ?? t;
25
25
  const i = (m, f, g) => c(m, f, g);
26
- return S(
27
- t,
28
- Number.parseInt(u.toString(), 10),
29
- s,
30
- a.locale,
31
- i
32
- ) ?? r ?? t;
26
+ return b(t, Number.parseInt(u.toString(), 10), s, a.locale, i) ?? r ?? t;
33
27
  },
34
28
  tn: (t, e) => {
35
29
  const r = n();
@@ -43,7 +37,7 @@ function P(o) {
43
37
  const r = n();
44
38
  return l.formatRelativeTime(t, r.locale, e);
45
39
  },
46
- has: (t, e) => d(n(), t, e),
40
+ has: (t, e) => L(n(), t, e),
47
41
  // Геттеры для текущего состояния (для использования в скриптах)
48
42
  get locale() {
49
43
  return n().locale;
@@ -1,7 +1,7 @@
1
+ import { CleanTranslation, Params, TranslationKey } from '@i18n-micro/types';
1
2
  import { Ref } from 'vue';
2
3
  import { I18nClientProps } from '../utils';
3
4
  import { I18nState } from './core';
4
- import { Params, TranslationKey, CleanTranslation } from '@i18n-micro/types';
5
5
  /**
6
6
  * Инициализирует i18n провайдер для Vue острова
7
7
  * Вызывайте в корневом компоненте острова
@@ -1,5 +1,5 @@
1
- import { h as wt, t as yt } from "../core-D32Y48CN.js";
2
- import { FormatService as St, defaultPlural as Ot } from "@i18n-micro/core";
1
+ import { FormatService as wt, defaultPlural as yt } from "@i18n-micro/core";
2
+ import { h as St, t as Ot } from "../core-D32Y48CN.js";
3
3
  // @__NO_SIDE_EFFECTS__
4
4
  function Rt(e) {
5
5
  const t = /* @__PURE__ */ Object.create(null);
@@ -214,11 +214,11 @@ function Je(e) {
214
214
  n !== e && (e.prevSub = n, n && (n.nextSub = e)), process.env.NODE_ENV !== "production" && e.dep.subsHead === void 0 && (e.dep.subsHead = e), e.dep.subs = e;
215
215
  }
216
216
  }
217
- const Ne = /* @__PURE__ */ new WeakMap(), $ = Symbol(
217
+ const Ne = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ Symbol(
218
218
  process.env.NODE_ENV !== "production" ? "Object iterate" : ""
219
- ), we = Symbol(
219
+ ), we = /* @__PURE__ */ Symbol(
220
220
  process.env.NODE_ENV !== "production" ? "Map keys iterate" : ""
221
- ), G = Symbol(
221
+ ), G = /* @__PURE__ */ Symbol(
222
222
  process.env.NODE_ENV !== "production" ? "Array iterate" : ""
223
223
  );
224
224
  function v(e, t, n) {
@@ -1120,7 +1120,7 @@ function at(e, t) {
1120
1120
  }
1121
1121
  le().requestIdleCallback;
1122
1122
  le().cancelIdleCallback;
1123
- const xn = Symbol.for("v-ndc"), Vn = {};
1123
+ const xn = /* @__PURE__ */ Symbol.for("v-ndc"), Vn = {};
1124
1124
  process.env.NODE_ENV !== "production" && (Vn.ownKeys = (e) => (V(
1125
1125
  "Avoid app logic that relies on enumerating keys on a component instance. The keys will be empty in production mode to avoid performance overhead."
1126
1126
  ), Reflect.ownKeys(e)));
@@ -1143,7 +1143,7 @@ function Cn(e, t, n = !1) {
1143
1143
  process.env.NODE_ENV !== "production" && V(`injection "${String(e)}" not found.`);
1144
1144
  } else process.env.NODE_ENV !== "production" && V("inject() can only be used inside setup() or functional components.");
1145
1145
  }
1146
- const An = {}, lt = (e) => Object.getPrototypeOf(e) === An, Mn = (e) => e.__isSuspense, ut = Symbol.for("v-fgt"), Pn = Symbol.for("v-txt"), $n = Symbol.for("v-cmt");
1146
+ const An = {}, lt = (e) => Object.getPrototypeOf(e) === An, Mn = (e) => e.__isSuspense, ut = /* @__PURE__ */ Symbol.for("v-fgt"), Pn = /* @__PURE__ */ Symbol.for("v-txt"), $n = /* @__PURE__ */ Symbol.for("v-cmt");
1147
1147
  function Fn(e) {
1148
1148
  return e ? e.__v_isVNode === !0 : !1;
1149
1149
  }
@@ -1492,7 +1492,7 @@ function Jn() {
1492
1492
  Yn();
1493
1493
  }
1494
1494
  process.env.NODE_ENV !== "production" && Jn();
1495
- const me = new St(), Et = Symbol("i18n-astro");
1495
+ const me = new wt(), Et = /* @__PURE__ */ Symbol("i18n-astro");
1496
1496
  function Gn(e) {
1497
1497
  const t = sn({
1498
1498
  locale: e.locale,
@@ -1506,7 +1506,7 @@ function Qn() {
1506
1506
  const e = Cn(Et);
1507
1507
  if (!e)
1508
1508
  throw new Error("useAstroI18n must be used within a component that calls provideI18n");
1509
- const t = (a, u, d, l) => yt(e.value, a, u, d, l);
1509
+ const t = (a, u, d, l) => Ot(e.value, a, u, d, l);
1510
1510
  return {
1511
1511
  // Translation methods
1512
1512
  t,
@@ -1516,18 +1516,12 @@ function Qn() {
1516
1516
  if (l === void 0)
1517
1517
  return d ?? a;
1518
1518
  const g = (P, bt, Nt) => t(P, bt, Nt);
1519
- return Ot(
1520
- a,
1521
- Number.parseInt(l.toString(), 10),
1522
- f,
1523
- e.value.locale,
1524
- g
1525
- ) ?? d ?? a;
1519
+ return yt(a, Number.parseInt(l.toString(), 10), f, e.value.locale, g) ?? d ?? a;
1526
1520
  },
1527
1521
  tn: (a, u) => me.formatNumber(a, e.value.locale, u),
1528
1522
  td: (a, u) => me.formatDate(a, e.value.locale, u),
1529
1523
  tdr: (a, u) => me.formatRelativeTime(a, e.value.locale, u),
1530
- has: (a, u) => wt(e.value, a, u),
1524
+ has: (a, u) => St(e.value, a, u),
1531
1525
  // Reactive locale state
1532
1526
  locale: ve({
1533
1527
  get: () => e.value.locale,
@@ -1,5 +1,5 @@
1
- import { BaseI18n, TranslationCache } from '@i18n-micro/core';
2
- import { Translations, PluralFunc } from '@i18n-micro/types';
1
+ import { BaseI18n, TranslationStorage } from '@i18n-micro/core';
2
+ import { PluralFunc, Translations } from '@i18n-micro/types';
3
3
  export interface AstroI18nOptions {
4
4
  locale: string;
5
5
  fallbackLocale?: string;
@@ -7,40 +7,25 @@ export interface AstroI18nOptions {
7
7
  plural?: PluralFunc;
8
8
  missingWarn?: boolean;
9
9
  missingHandler?: (locale: string, key: string, routeName: string) => void;
10
- _cache?: TranslationCache;
10
+ _storage?: TranslationStorage;
11
11
  }
12
12
  export declare class AstroI18n extends BaseI18n {
13
13
  private _locale;
14
14
  private _fallbackLocale;
15
15
  private _currentRoute;
16
- readonly cache: TranslationCache;
16
+ readonly storage: TranslationStorage;
17
17
  private initialMessages;
18
18
  constructor(options: AstroI18nOptions);
19
- /**
20
- * Clone cache with shallow copy to prevent memory leaks
21
- * Each request-scoped instance gets its own cache structure,
22
- * but can read from the global cache (read-only access to existing translations)
23
- */
24
- private cloneCache;
25
- /**
26
- * Create a request-scoped instance with isolated cache
27
- * Prevents memory leaks by isolating per-request translations from global cache
28
- */
19
+ private cloneStorage;
29
20
  clone(newLocale?: string): AstroI18n;
30
21
  get locale(): string;
31
22
  set locale(val: string);
32
23
  get fallbackLocale(): string;
33
24
  set fallbackLocale(val: string);
34
- get currentRoute(): string;
35
25
  setRoute(routeName: string): void;
36
26
  getLocale(): string;
37
27
  getFallbackLocale(): string;
38
28
  getRoute(): string;
39
- /**
40
- * Get route-specific translations for a given locale and route
41
- * This method encapsulates the cache key format, making it safe to use
42
- * without direct cache access
43
- */
44
29
  getRouteTranslations(locale: string, routeName: string): Translations | null;
45
30
  addTranslations(locale: string, translations: Translations, merge?: boolean): void;
46
31
  addRouteTranslations(locale: string, routeName: string, translations: Translations, merge?: boolean): void;
package/dist/env.d.ts CHANGED
@@ -13,5 +13,3 @@ declare global {
13
13
  }
14
14
  }
15
15
  }
16
-
17
- export {}
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("@i18n-micro/core"),y=require("node:fs"),I=require("node:path");class j extends S.BaseI18n{constructor(e){const r=e._cache||{generalLocaleCache:{},routeLocaleCache:{},dynamicTranslationsCaches:[],serverTranslationCache:{}};if(super({cache:r,plural:e.plural,missingWarn:e.missingWarn,missingHandler:e.missingHandler}),this.initialMessages={},this.cache=r,this._locale=e.locale,this._fallbackLocale=e.fallbackLocale||e.locale,this._currentRoute="general",e.messages){this.initialMessages={...e.messages};for(const[n,l]of Object.entries(e.messages))this.helper.loadTranslations(n,l)}}cloneCache(e){const r=t=>typeof t=="object"&&t!==null&&"value"in t?t.value:t,n=r(e.generalLocaleCache),l=r(e.routeLocaleCache),i=r(e.dynamicTranslationsCaches),f=r(e.serverTranslationCache);return{generalLocaleCache:{...n},routeLocaleCache:{...l},dynamicTranslationsCaches:[...i],serverTranslationCache:{...f}}}clone(e){const r=this.cloneCache(this.cache);return new j({locale:e||this._locale,fallbackLocale:this._fallbackLocale,plural:this.pluralFunc,missingWarn:this.missingWarn,missingHandler:this.missingHandler,_cache:r})}get locale(){return this._locale}set locale(e){this._locale=e}get fallbackLocale(){return this._fallbackLocale}set fallbackLocale(e){this._fallbackLocale=e}get currentRoute(){return this._currentRoute}setRoute(e){this._currentRoute=e}getLocale(){return this._locale}getFallbackLocale(){return this._fallbackLocale}getRoute(){return this._currentRoute}getRouteTranslations(e,r){const n=`${e}:${r}`,l=this.cache.routeLocaleCache;return l&&typeof l=="object"&&!Array.isArray(l)&&l[n]||null}addTranslations(e,r,n=!0){super.loadTranslationsCore(e,r,n)}addRouteTranslations(e,r,n,l=!0){super.loadRouteTranslationsCore(e,r,n,l)}mergeTranslations(e,r,n){this.helper.mergeTranslation(e,r,n,!0)}mergeGlobalTranslations(e,r){this.helper.mergeGlobalTranslation(e,r,!0)}clearCache(){const e={...this.initialMessages};if(super.clearCache(),Object.keys(e).length>0)for(const[r,n]of Object.entries(e))this.helper.loadTranslations(r,n)}}let k=null;function $(){return k}function N(a){const{locale:e,fallbackLocale:r,translationDir:n,routingStrategy:l}=a;return k=l||null,{name:"@i18n-micro/astro",hooks:{"astro:config:setup":i=>{const{updateConfig:f}=i,t="virtual:i18n-micro/config",s="\0"+t,c={defaultLocale:e,fallbackLocale:r||e,locales:a.locales||[],localeCodes:(a.locales||[]).map(o=>o.code),translationDir:n||null,autoDetect:a.autoDetect??!0,redirectToDefault:a.redirectToDefault??!1,localeCookie:a.localeCookie||"i18n-locale",missingWarn:a.missingWarn??!1};f({vite:{plugins:[{name:"vite-plugin-i18n-micro-config",resolveId(o){if(o===t)return s},load(o){if(o===s)return`export const config = ${JSON.stringify(c)}`}}]}})},"astro:config:done":i=>{const{injectTypes:f}=i;f({filename:"i18n-micro-env.d.ts",content:`
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:`
2
2
  /// <reference types="@i18n-micro/astro/env" />
3
3
 
4
4
  declare module 'virtual:i18n-micro/config' {
@@ -10,8 +10,8 @@
10
10
  translationDir: string | null;
11
11
  autoDetect: boolean;
12
12
  redirectToDefault: boolean;
13
- localeCookie: string;
14
- missingWarn: boolean;
13
+ localeCookie: string | null;
14
+ missingWarn: boolean | null;
15
15
  }
16
16
  }
17
- `})}}}}function O(a){return new j(a)}function q(a){const{i18n:e,defaultLocale:r,locales:n,localeObjects:l,autoDetect:i=!0,redirectToDefault:f=!1,routingStrategy:t}=a,s=t||$();return async(c,o)=>{if(c.locals.locale&&c.locals.i18n)return o();const u=c.url,h=u.pathname;if(!s){const T=e.clone(r),B=h==="/"||h===""?"index":h.split("/").filter(Boolean).join("-");return T.setRoute(B),c.locals.i18n=T,c.locals.locale=r,c.locals.defaultLocale=r,c.locals.locales=l||n.map(_=>({code:_})),c.locals.currentUrl=u,o()}const d={...s,getCurrentPath:()=>h,getRoute:()=>({fullPath:u.pathname+u.search,query:Object.fromEntries(u.searchParams)})},g=h.split("/").filter(Boolean)[0],p=g!==void 0&&n.includes(g);let L;p&&g?L=g:d.getLocaleFromPath?L=d.getLocaleFromPath(h,r,n):L=r;const P=e.clone(L),b=d.getRouteName?d.getRouteName(h,n):"general";return P.setRoute(b),c.locals.i18n=P,c.locals.locale=L,c.locals.defaultLocale=r,c.locals.locales=l||n.map(T=>({code:T})),c.locals.currentUrl=u,c.locals.routingStrategy=d,o()}}function A(a){const e=[],r=a.split(",");for(const n of r){const[l,i="1.0"]=n.trim().split(";q=");if(Number.parseFloat(i)>0&&l){const t=l.split("-")[0]?.toLowerCase();t&&(e.push(t),l!==t&&e.push(l.toLowerCase()))}}return e}function M(a,e,r,n,l,i="i18n-locale"){const f=$();let t=n;if(f?.getLocaleFromPath)t=f.getLocaleFromPath(a,n,l);else{const c=a.split("/").filter(Boolean)[0];c&&l.includes(c)&&(t=c)}if(t===n&&e.get(i)){const s=e.get(i)?.value;s&&l.includes(s)&&(t=s)}if(t===n)try{const s=r.get("accept-language");if(s){const c=A(s);for(const o of c)if(l.includes(o)){t=o;break}}}catch{}return t}function C(a){const e=a.locals.i18n;if(!e)throw new Error("i18n instance not found. Make sure i18n middleware is configured.");return e}function R(a){return a.locals.locale||"en"}function v(a){return a.locals.defaultLocale||"en"}function w(a){return a.locals.locales||[]}function D(a){return a.locals.routingStrategy||null}function W(a){const e=C(a),r=R(a),n=v(a),l=w(a),i=l.map(t=>t.code),f=D(a);return{locale:r,defaultLocale:n,locales:l,t:(t,s,c,o)=>e.t(t,s,c,o),ts:(t,s,c,o)=>e.ts(t,s,c,o),tc:(t,s,c)=>e.tc(t,s,c),tn:(t,s)=>e.tn(t,s),td:(t,s)=>e.td(t,s),tdr:(t,s)=>e.tdr(t,s),has:(t,s)=>e.has(t,s),getRoute:()=>e.getRoute(),getRouteName:t=>{const s=t||a.url.pathname;if(f?.getRouteName)return f.getRouteName(s,i);const c=s.replace(/^\//,"").replace(/\/$/,"");if(!c)return"index";const o=c.split("/").filter(Boolean),u=o[0];return u&&i.includes(u)&&o.shift(),o.length===0?"index":o.join("-")},getLocaleFromPath:t=>{const s=t||a.url.pathname;if(f?.getLocaleFromPath)return f.getLocaleFromPath(s,n,i);const o=s.split("/").filter(Boolean)[0];return o&&i.includes(o)?o:n},switchLocalePath:t=>{if(f?.switchLocalePath)return f.switchLocalePath(a.url.pathname,t,i,n);const s=a.url.pathname.split("/").filter(Boolean),c=s[0];return c&&i.includes(c)&&s.shift(),t!==n&&s.unshift(t),`/${s.join("/")}`},localizePath:(t,s)=>{if(f?.localizePath)return f.localizePath(t,s||r,i,n);const o=(t.replace(/^\//,"").replace(/\/$/,"")||"").split("/").filter(Boolean),u=o[0];return u&&i.includes(u)&&o.shift(),s&&s!==n&&o.unshift(s),`/${o.join("/")}`},getI18n:()=>e,getBasePath:t=>{const o=(t||a.url).pathname.split("/").filter(Boolean),u=o[0];return u&&i.includes(u)&&o.shift(),o.length>0?`/${o.join("/")}`:"/"},addTranslations:(t,s,c=!0)=>{e.addTranslations(t,s,c)},addRouteTranslations:(t,s,c,o=!0)=>{e.addRouteTranslations(t,s,c,o)},mergeTranslations:(t,s,c)=>{e.mergeTranslations(t,s,c)},mergeGlobalTranslations:(t,s)=>{e.mergeGlobalTranslations(t,s)},clearCache:()=>{e.clearCache()}}}function z(a,e={}){const{baseUrl:r="/",addDirAttribute:n=!0,addSeoAttributes:l=!0}=e,i=R(a),f=v(a),t=w(a),s=t.find(g=>g.code===i);if(!s)return{htmlAttrs:{},link:[],meta:[]};const c=s.iso||i,o=s.dir||"auto",u={htmlAttrs:{lang:c,...n?{dir:o}:{}},link:[],meta:[]};if(!l)return u;const h=`${r}${a.url.pathname}`;u.link.push({rel:"canonical",href:h});const d=D(a),m=t.map(g=>g.code);for(const g of t){if(g.code===i)continue;let p=a.url.pathname;if(d?.switchLocalePath)p=d.switchLocalePath(a.url.pathname,g.code,m,f);else{const P=a.url.pathname.split("/").filter(Boolean),b=P[0];b&&m.includes(b)&&P.shift(),g.code!==f&&P.unshift(g.code),p=`/${P.join("/")}`}const L=`${r}${p}`;u.link.push({rel:"alternate",href:L,hreflang:g.code}),g.iso&&g.iso!==g.code&&u.link.push({rel:"alternate",href:L,hreflang:g.iso})}u.meta.push({property:"og:locale",content:c}),u.meta.push({property:"og:url",content:h});for(const g of t)g.code!==i&&u.meta.push({property:"og:locale:alternate",content:g.iso||g.code});return u}function H(a,e,r){const n=e.split(".");let l=a;for(let i=0;i<n.length-1;i++)l[n[i]]||(l[n[i]]={}),l=l[n[i]];l[n[n.length-1]]=r}function G(a,e){const r=C(a),n=R(a),l=v(a),i=r.getRoute(),f={};if(e&&e.length>0){const t={};for(const s of e){const c=r.t(s,void 0,void 0,i);c!=null&&c!==s&&H(t,s,c)}Object.keys(t).length>0&&(f[i]=t)}else{const t=r.getRouteTranslations(n,i);t&&(f[i]=t)}return{locale:n,fallbackLocale:l,currentRoute:i,translations:f}}function U(a,e,r){const n=a.map(o=>o.code),l=(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("-")},i=(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:()=>r?r().pathname:typeof window<"u"?window.location.pathname:"/",getRouteName:l,getLocaleFromPath:i,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,n,e)},getRoute:()=>{if(r){const o=r();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 E(a,e=[]){const r=a.replace(/^\//,"").replace(/\/$/,"");if(!r)return"index";const n=r.split("/").filter(Boolean),l=n[0];return l&&e.includes(l)&&n.shift(),n.length===0?"index":n.join("-")}function J(a,e="en",r=[]){const l=a.split("/").filter(Boolean)[0];return l&&r.includes(l)?l:e}function K(a,e,r=[],n){const l=a.split("/").filter(Boolean),i=l[0];return i&&r.includes(i)&&l.shift(),(e!==n||n===void 0)&&l.unshift(e),`/${l.join("/")}`}function Q(a,e,r=[],n){const i=(a.replace(/^\//,"").replace(/\/$/,"")||"").split("/").filter(Boolean),f=i[0];return f&&r.includes(f)&&i.shift(),(e!==n||n===void 0)&&i.unshift(e),`/${i.join("/")}`}function X(a,e=[]){const r=a.split("/").filter(Boolean),n=r[0];return n&&e.includes(n)&&r.shift(),`/${r.join("/")}`}function F(a){const{translationDir:e,rootDir:r=process.cwd(),disablePageLocales:n=!1}=a,l=I.resolve(r,e);if(!y.existsSync(l))return console.warn(`[i18n] Translation directory not found: ${l}`),{general:{},routes:{}};const i={},f={},t=(s,c="")=>{if(!y.existsSync(s))return;const o=y.readdirSync(s);for(const u of o){const h=I.join(s,u);if(y.statSync(h).isDirectory())u==="pages"&&!n?t(h,""):c||n?t(h,c):t(h,u);else if(u.endsWith(".json")){const m=u.replace(".json","");try{const g=y.readFileSync(h,"utf-8"),p=JSON.parse(g);c&&!n?(f[c]||(f[c]={}),f[c][m]=p):i[m]=p}catch(g){console.error(`[i18n] Failed to load translation file: ${h}`,g)}}}};return t(l),{general:i,routes:f}}function Y(a,e){const{general:r,routes:n}=F(e);for(const[l,i]of Object.entries(r))a.addTranslations(l,i,!1);for(const[l,i]of Object.entries(n))for(const[f,t]of Object.entries(i))a.addRouteTranslations(f,l,t,!1)}Object.defineProperty(exports,"FormatService",{enumerable:!0,get:()=>S.FormatService});Object.defineProperty(exports,"defaultPlural",{enumerable:!0,get:()=>S.defaultPlural});Object.defineProperty(exports,"interpolate",{enumerable:!0,get:()=>S.interpolate});exports.AstroI18n=j;exports.createAstroRouterAdapter=U;exports.createI18n=O;exports.createI18nMiddleware=q;exports.detectLocale=M;exports.getDefaultLocale=v;exports.getI18n=C;exports.getI18nProps=G;exports.getLocale=R;exports.getLocaleFromPath=J;exports.getLocales=w;exports.getRouteName=E;exports.i18nIntegration=N;exports.loadTranslationsFromDir=F;exports.loadTranslationsIntoI18n=Y;exports.localizePath=Q;exports.removeLocaleFromPath=X;exports.switchLocalePath=K;exports.useI18n=W;exports.useLocaleHead=z;
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;
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- export { i18nIntegration, createI18n } from './integration';
1
+ export { defaultPlural, FormatService, interpolate } from '@i18n-micro/core';
2
+ export type { CleanTranslation, Getter, Locale, LocaleCode, Params, PluralFunc, Translations, } from '@i18n-micro/types';
2
3
  export { AstroI18n, type AstroI18nOptions } from './composer';
3
- export { createI18nMiddleware, detectLocale } from './middleware';
4
- export type { I18nMiddlewareOptions } from './middleware';
5
- export { useI18n, getI18n, getLocale, getDefaultLocale, getLocales, useLocaleHead, getI18nProps, } from './utils';
6
- export type { LocaleHeadOptions, LocaleHeadResult, I18nClientProps } from './utils';
7
- export type { I18nRoutingStrategy } from './router/types';
8
- export { createAstroRouterAdapter } from './router/adapter';
9
- export { getRouteName, getLocaleFromPath, switchLocalePath, localizePath, removeLocaleFromPath, } from './routing';
10
- export type { Translations, Params, PluralFunc, Getter, Locale, LocaleCode, CleanTranslation, } from '@i18n-micro/types';
11
- export { interpolate, FormatService, defaultPlural } from '@i18n-micro/core';
12
4
  export type { I18nIntegrationOptions } from './integration';
5
+ export { createI18n, i18nIntegration } from './integration';
6
+ export type { LoadedTranslations, LoadTranslationsOptions } from './load-translations';
13
7
  export { loadTranslationsFromDir, loadTranslationsIntoI18n, } from './load-translations';
14
- export type { LoadTranslationsOptions, LoadedTranslations } from './load-translations';
8
+ export type { I18nMiddlewareOptions } from './middleware';
9
+ export { createI18nMiddleware, detectLocale } from './middleware';
10
+ export { createAstroRouterAdapter } from './router/adapter';
11
+ export type { I18nRoutingStrategy } from './router/types';
12
+ export { getLocaleFromPath, getRouteName, localizePath, removeLocaleFromPath, switchLocalePath, } from './routing';
13
+ export type { I18nClientProps, LocaleHeadOptions, LocaleHeadResult } from './utils';
14
+ export { getDefaultLocale, getI18n, getI18nProps, getLocale, getLocales, useI18n, useLocaleHead, } from './utils';