@i18n-micro/astro 1.3.25 → 2.0.0
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.
- package/LICENSE +1 -1
- package/README.md +8 -64
- package/dist/auto-middleware.d.ts +1 -0
- package/dist/client/core.d.cts +86 -0
- package/dist/client/core.d.ts +71 -8
- package/dist/client/index.d.cts +2 -6
- package/dist/client/index.d.ts +2 -6
- package/dist/client/index.js +1 -6
- package/dist/client/preact.d.ts +12 -23
- package/dist/client/preact.js +13 -37
- package/dist/client/react.d.ts +14 -21
- package/dist/client/react.js +12 -37
- package/dist/client/svelte.d.ts +14 -14
- package/dist/client/svelte.js +17 -47
- package/dist/client/vue.d.ts +15 -15
- package/dist/client/vue.js +37 -2
- package/dist/composer.d.cts +16 -0
- package/dist/composer.d.ts +10 -30
- package/dist/core-CgrgdmGy.cjs +1 -0
- package/dist/core-DTAcn2yF.js +72 -0
- package/dist/env.d.ts +8 -2
- package/dist/index.cjs +11 -3
- package/dist/index.d.cts +10 -13
- package/dist/index.d.ts +10 -13
- package/dist/index.mjs +171 -482
- package/dist/integration.d.cts +26 -0
- package/dist/integration.d.ts +14 -15
- package/dist/middleware-BT3OA5YL.cjs +1 -0
- package/dist/middleware-Ch8E0iV_.js +257 -0
- package/dist/middleware.d.cts +34 -0
- package/dist/middleware.d.ts +17 -8
- package/dist/middleware.js +23 -0
- package/dist/node.d.ts +26 -0
- package/dist/node.js +22 -0
- package/dist/request.d.ts +69 -0
- package/dist/router/adapter.d.cts +9 -0
- package/dist/router/adapter.d.ts +5 -4
- package/dist/router/types.d.cts +66 -0
- package/dist/router/types.d.ts +3 -2
- package/dist/utils.d.cts +112 -0
- package/dist/utils.d.ts +39 -35
- package/dist/virtual.d.ts +21 -0
- package/package.json +28 -15
- package/src/auto-middleware.ts +26 -0
- package/src/client/core.ts +124 -59
- package/src/client/index.ts +2 -11
- package/src/client/preact.tsx +12 -127
- package/src/client/react.tsx +11 -123
- package/src/client/svelte.ts +6 -69
- package/src/client/vue.ts +22 -77
- package/src/components/i18n-link.astro +2 -59
- package/src/components/i18n-switcher.astro +46 -149
- package/src/components/i18n-t.astro +6 -54
- package/src/composer.ts +25 -115
- package/src/env.d.ts +7 -0
- package/src/index.ts +1 -6
- package/src/integration.ts +113 -52
- package/src/middleware.ts +174 -120
- package/src/node.ts +51 -0
- package/src/request.ts +177 -0
- package/src/router/adapter.ts +47 -149
- package/src/router/types.ts +3 -2
- package/src/utils.ts +149 -323
- package/src/virtual.d.ts +21 -0
- package/dist/components/index.d.cts +0 -0
- package/dist/components/index.d.ts +0 -0
- package/dist/core-DwkpOV-H.cjs +0 -1
- package/dist/core-VSnkGRWR.js +0 -28
- package/dist/load-translations.d.ts +0 -43
- package/dist/routing-context.d.ts +0 -4
- package/dist/vue-BNiEwZr2.cjs +0 -5
- package/dist/vue-CWHjIOiS.js +0 -1724
- package/src/components/index.ts +0 -11
- package/src/load-translations.ts +0 -106
- package/src/routing-context.ts +0 -23
package/dist/client/vue.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { I18nState } from './core';
|
|
1
|
+
import { MaybeRefOrGetter, Ref } from 'vue';
|
|
2
|
+
import { I18nClientProps } from '../utils.js';
|
|
3
|
+
import { I18nState } from './core.js';
|
|
5
4
|
/**
|
|
6
|
-
* Initializes the i18n provider for a Vue island
|
|
7
|
-
*
|
|
5
|
+
* Initializes the i18n provider for a Vue island. Call in the island's root component, with a
|
|
6
|
+
* getter (`() => props.i18n`) so an island kept by `transition:persist` follows its new props.
|
|
7
|
+
* `shallowRef`: translations are never edited in place, and deep tracking costs 11× on every `t`.
|
|
8
8
|
*/
|
|
9
|
-
export declare function provideI18n(props: I18nClientProps): Ref<I18nState>;
|
|
9
|
+
export declare function provideI18n(props: MaybeRefOrGetter<I18nClientProps>): Ref<I18nState>;
|
|
10
10
|
/**
|
|
11
11
|
* Hook for using i18n in Vue components
|
|
12
12
|
*/
|
|
13
13
|
export declare function useAstroI18n(): {
|
|
14
|
-
t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation;
|
|
15
|
-
ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeName?: string) => string;
|
|
16
|
-
tc: (key: TranslationKey, count: number | Params, defaultValue?: string) => string;
|
|
17
|
-
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
18
|
-
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
19
|
-
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
20
|
-
has: (key: TranslationKey, routeName?: string) => boolean;
|
|
21
14
|
locale: import('vue').WritableComputedRef<string, string>;
|
|
22
15
|
fallbackLocale: import('vue').ComputedRef<string>;
|
|
23
16
|
currentRoute: import('vue').WritableComputedRef<string, string>;
|
|
24
17
|
setLocale: (locale: string) => void;
|
|
25
|
-
setRoute: (
|
|
18
|
+
setRoute: (currentRoute: string) => void;
|
|
19
|
+
t: (key: import('@i18n-micro/types').TranslationKey, params?: import('@i18n-micro/types').Params, defaultValue?: string | null, routeName?: string) => import('@i18n-micro/types').CleanTranslation;
|
|
20
|
+
ts: (key: import('@i18n-micro/types').TranslationKey, params?: import('@i18n-micro/types').Params, defaultValue?: string, routeName?: string) => string;
|
|
21
|
+
tc: (key: import('@i18n-micro/types').TranslationKey, count: number | import('@i18n-micro/types').Params, defaultValue?: string) => string;
|
|
22
|
+
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
23
|
+
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
24
|
+
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
25
|
+
has: (key: import('@i18n-micro/types').TranslationKey, routeName?: string) => boolean;
|
|
26
26
|
getRoute: () => string;
|
|
27
27
|
};
|
package/dist/client/vue.js
CHANGED
|
@@ -1,2 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { a as e, t } from "../core-DTAcn2yF.js";
|
|
2
|
+
import { computed as n, inject as r, provide as i, shallowRef as a, toValue as o, watch as s } from "vue";
|
|
3
|
+
// src/client/vue.ts
|
|
4
|
+
var c = Symbol("i18n-astro");
|
|
5
|
+
function l(e) {
|
|
6
|
+
let t = a(o(e));
|
|
7
|
+
return s(() => o(e), (e) => {
|
|
8
|
+
t.value = e;
|
|
9
|
+
}), i(c, t), t;
|
|
10
|
+
}
|
|
11
|
+
function u() {
|
|
12
|
+
let i = r(c);
|
|
13
|
+
if (!i) throw Error("useAstroI18n must be used within a component that calls provideI18n");
|
|
14
|
+
let a = (t) => {
|
|
15
|
+
i.value = e(i.value, t);
|
|
16
|
+
}, o = (e) => {
|
|
17
|
+
i.value = {
|
|
18
|
+
...i.value,
|
|
19
|
+
currentRoute: e
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
...t(() => i.value),
|
|
24
|
+
locale: n({
|
|
25
|
+
get: () => i.value.locale,
|
|
26
|
+
set: a
|
|
27
|
+
}),
|
|
28
|
+
fallbackLocale: n(() => i.value.fallbackLocale),
|
|
29
|
+
currentRoute: n({
|
|
30
|
+
get: () => i.value.currentRoute,
|
|
31
|
+
set: o
|
|
32
|
+
}),
|
|
33
|
+
setLocale: a,
|
|
34
|
+
setRoute: o
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export { l as provideI18n, u as useAstroI18n };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { I18n, I18nOptions } from '@i18n-micro/runtime';
|
|
2
|
+
import { Translations } from '@i18n-micro/types';
|
|
3
|
+
export type AstroI18nOptions = I18nOptions;
|
|
4
|
+
/** The runtime instance, plus what Astro pages use on top: per-route reads and a reset that keeps `messages`. */
|
|
5
|
+
export declare class AstroI18n extends I18n {
|
|
6
|
+
private initialMessages;
|
|
7
|
+
private initialRouteMessages;
|
|
8
|
+
constructor(options: AstroI18nOptions);
|
|
9
|
+
/** Dictionaries loaded after the constructor that `clearCache` keeps too: a directory read at runtime. */
|
|
10
|
+
keepMessages(messages: Record<string, Translations>, routeMessages: Record<string, Record<string, Translations>>): void;
|
|
11
|
+
/** The `localeIso` option: what an island needs to plural in another locale. */
|
|
12
|
+
getLocaleIso(): Record<string, string>;
|
|
13
|
+
getRouteTranslations(locale: string, routeName: string): Translations | null;
|
|
14
|
+
mergeTranslations(locale: string, routeName: string, translations: Translations): void;
|
|
15
|
+
clearCache(): void;
|
|
16
|
+
}
|
package/dist/composer.d.ts
CHANGED
|
@@ -1,36 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
messages?: Record<string, Translations>;
|
|
7
|
-
plural?: PluralFunc;
|
|
8
|
-
missingWarn?: boolean;
|
|
9
|
-
missingHandler?: (locale: string, key: string, routeName: string) => void;
|
|
10
|
-
numberFormats?: NumberFormatsConfig;
|
|
11
|
-
datetimeFormats?: DateTimeFormatsConfig;
|
|
12
|
-
_storage?: TranslationStorage;
|
|
13
|
-
}
|
|
14
|
-
export declare class AstroI18n extends BaseI18n {
|
|
15
|
-
private _locale;
|
|
16
|
-
private _fallbackLocale;
|
|
17
|
-
private _currentRoute;
|
|
18
|
-
readonly storage: TranslationStorage;
|
|
1
|
+
import { I18n, I18nOptions } from '@i18n-micro/runtime';
|
|
2
|
+
import { Translations } from '@i18n-micro/types';
|
|
3
|
+
export type AstroI18nOptions = I18nOptions;
|
|
4
|
+
/** The runtime instance, plus what Astro pages use on top: per-route reads and a reset that keeps `messages`. */
|
|
5
|
+
export declare class AstroI18n extends I18n {
|
|
19
6
|
private initialMessages;
|
|
7
|
+
private initialRouteMessages;
|
|
20
8
|
constructor(options: AstroI18nOptions);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
get fallbackLocale(): string;
|
|
26
|
-
set fallbackLocale(val: string);
|
|
27
|
-
setRoute(routeName: string): void;
|
|
28
|
-
getLocale(): string;
|
|
29
|
-
getFallbackLocale(): string;
|
|
30
|
-
getRoute(): string;
|
|
9
|
+
/** Dictionaries loaded after the constructor that `clearCache` keeps too: a directory read at runtime. */
|
|
10
|
+
keepMessages(messages: Record<string, Translations>, routeMessages: Record<string, Record<string, Translations>>): void;
|
|
11
|
+
/** The `localeIso` option: what an island needs to plural in another locale. */
|
|
12
|
+
getLocaleIso(): Record<string, string>;
|
|
31
13
|
getRouteTranslations(locale: string, routeName: string): Translations | null;
|
|
32
|
-
addTranslations(locale: string, translations: Translations, merge?: boolean): void;
|
|
33
|
-
addRouteTranslations(locale: string, routeName: string, translations: Translations, merge?: boolean): void;
|
|
34
14
|
mergeTranslations(locale: string, routeName: string, translations: Translations): void;
|
|
35
15
|
clearCache(): void;
|
|
36
16
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=require("@i18n-micro/core");function t(t,n,r){let i=r||t.currentRoute,a=Object.prototype.hasOwnProperty.call(t.translations,i)?t.translations[i]:void 0;return(0,e.resolveTranslation)(a,n)??null}function n(n,r,i,a,o){if(!r)return``;let s=t(n,r,o)??(a||r);return typeof s==`object`?(0,e.convertible)(s):typeof s==`string`&&i?(0,e.interpolate)(s,i):s}function r(n,r,i,a){let{count:o,...s}=typeof i==`number`?{count:i}:i;return o==null?a??r:(0,e.defaultPlural)(r,Number(o),s,n.pluralLocale??n.locale,(r,i,a)=>{let o=t(n,r);return o===null?a===void 0?void 0:a||r:i&&typeof o==`string`?(0,e.interpolate)(o,i):o})??a??r}function i(e,n,r){return t(e,n,r)!==null}var a=(t,n)=>({...t,locale:n,pluralLocale:t.localeIso&&(0,e.ownValue)(t.localeIso,n)}),o=new e.FormatService,s=e=>e.pluralLocale??e.locale;function c(t){let a=(e,r,i,a)=>n(t(),e,r,i,a);return{t:a,ts:(t,n,r,i)=>(0,e.textOf)(a(t,n,r,i))??r??t,tc:(e,n,i)=>r(t(),e,n,i),tn:(e,n)=>o.formatNumber(e,s(t()),n),td:(e,n)=>o.formatDate(e,s(t()),n),tdr:(e,n)=>o.formatRelativeTime(e,s(t()),n),has:(e,n)=>i(t(),e,n),getRoute:()=>t().currentRoute}}function l(e){let{createContext:t,createElement:n,useCallback:r,useContext:i,useMemo:o,useState:s}=e,l=t(null);function u({children:e,value:t}){let[r,i]=s(t),[a,c]=s(t);a!==t&&(c(t),i(t));let u=o(()=>({state:r,setState:i}),[r]);return n(l.Provider,{value:u},e)}function d(){let e=i(l);if(!e)throw Error(`useAstroI18n must be used within an I18nProvider`);let{state:t,setState:n}=e,s=o(()=>c(()=>t),[t]),u=r(e=>n(t=>a(t,e)),[n]),d=r(e=>n(t=>({...t,currentRoute:e})),[n]);return{...s,locale:t.locale,fallbackLocale:t.fallbackLocale,currentRoute:t.currentRoute,setLocale:u,setRoute:d}}return{I18nProvider:u,useAstroI18n:d}}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return c}});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { FormatService as e, convertible as t, defaultPlural as n, interpolate as r, ownValue as i, resolveTranslation as a, textOf as o } from "@i18n-micro/core";
|
|
2
|
+
// src/client/core.ts
|
|
3
|
+
function s(e, t, n) {
|
|
4
|
+
let r = n || e.currentRoute, i = Object.prototype.hasOwnProperty.call(e.translations, r) ? e.translations[r] : void 0;
|
|
5
|
+
return a(i, t) ?? null;
|
|
6
|
+
}
|
|
7
|
+
function c(e, n, i, a, o) {
|
|
8
|
+
if (!n) return "";
|
|
9
|
+
let c = s(e, n, o) ?? (a || n);
|
|
10
|
+
return typeof c == "object" ? t(c) : typeof c == "string" && i ? r(c, i) : c;
|
|
11
|
+
}
|
|
12
|
+
function l(e, t, i, a) {
|
|
13
|
+
let { count: o, ...c } = typeof i == "number" ? { count: i } : i;
|
|
14
|
+
return o == null ? a ?? t : n(t, Number(o), c, e.pluralLocale ?? e.locale, (t, n, i) => {
|
|
15
|
+
let a = s(e, t);
|
|
16
|
+
return a === null ? i === void 0 ? void 0 : i || t : n && typeof a == "string" ? r(a, n) : a;
|
|
17
|
+
}) ?? a ?? t;
|
|
18
|
+
}
|
|
19
|
+
function u(e, t, n) {
|
|
20
|
+
return s(e, t, n) !== null;
|
|
21
|
+
}
|
|
22
|
+
var d = (e, t) => ({
|
|
23
|
+
...e,
|
|
24
|
+
locale: t,
|
|
25
|
+
pluralLocale: e.localeIso && i(e.localeIso, t)
|
|
26
|
+
}), f = /*#__PURE__*/ new e(), p = (e) => e.pluralLocale ?? e.locale;
|
|
27
|
+
function m(e) {
|
|
28
|
+
let t = (t, n, r, i) => c(e(), t, n, r, i);
|
|
29
|
+
return {
|
|
30
|
+
t,
|
|
31
|
+
ts: (e, n, r, i) => o(t(e, n, r, i)) ?? r ?? e,
|
|
32
|
+
tc: (t, n, r) => l(e(), t, n, r),
|
|
33
|
+
tn: (t, n) => f.formatNumber(t, p(e()), n),
|
|
34
|
+
td: (t, n) => f.formatDate(t, p(e()), n),
|
|
35
|
+
tdr: (t, n) => f.formatRelativeTime(t, p(e()), n),
|
|
36
|
+
has: (t, n) => u(e(), t, n),
|
|
37
|
+
getRoute: () => e().currentRoute
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function h(e) {
|
|
41
|
+
let { createContext: t, createElement: n, useCallback: r, useContext: i, useMemo: a, useState: o } = e, s = t(null);
|
|
42
|
+
function c({ children: e, value: t }) {
|
|
43
|
+
let [r, i] = o(t), [c, l] = o(t);
|
|
44
|
+
c !== t && (l(t), i(t));
|
|
45
|
+
let u = a(() => ({
|
|
46
|
+
state: r,
|
|
47
|
+
setState: i
|
|
48
|
+
}), [r]);
|
|
49
|
+
return n(s.Provider, { value: u }, e);
|
|
50
|
+
}
|
|
51
|
+
function l() {
|
|
52
|
+
let e = i(s);
|
|
53
|
+
if (!e) throw Error("useAstroI18n must be used within an I18nProvider");
|
|
54
|
+
let { state: t, setState: n } = e, o = a(() => m(() => t), [t]), c = r((e) => n((t) => d(t, e)), [n]), l = r((e) => n((t) => ({
|
|
55
|
+
...t,
|
|
56
|
+
currentRoute: e
|
|
57
|
+
})), [n]);
|
|
58
|
+
return {
|
|
59
|
+
...o,
|
|
60
|
+
locale: t.locale,
|
|
61
|
+
fallbackLocale: t.fallbackLocale,
|
|
62
|
+
currentRoute: t.currentRoute,
|
|
63
|
+
setLocale: c,
|
|
64
|
+
setRoute: l
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
I18nProvider: c,
|
|
69
|
+
useAstroI18n: l
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export { d as a, c as i, h as n, u as r, m as t };
|
package/dist/env.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { AstroI18n } from './composer';
|
|
1
|
+
import { AstroI18n } from './composer.js';
|
|
2
2
|
import { Locale } from '@i18n-micro/types';
|
|
3
|
-
import {
|
|
3
|
+
import { MiddlewareHandler } from 'astro';
|
|
4
|
+
import { I18nRoutingStrategy } from './router/types.js';
|
|
4
5
|
declare global {
|
|
5
6
|
namespace App {
|
|
6
7
|
interface Locals {
|
|
@@ -8,8 +9,13 @@ declare global {
|
|
|
8
9
|
locale: string
|
|
9
10
|
defaultLocale: string
|
|
10
11
|
locales: Locale[]
|
|
12
|
+
/** The page's URL: the original one after `Astro.rewrite`, the page's one in a server island. */
|
|
11
13
|
currentUrl: URL
|
|
12
14
|
routingStrategy?: I18nRoutingStrategy
|
|
15
|
+
/** Astro's `base`, no trailing slash. */
|
|
16
|
+
i18nBase?: string
|
|
17
|
+
/** The middleware that handled this request. */
|
|
18
|
+
i18nHandler?: MiddlewareHandler
|
|
13
19
|
}
|
|
14
20
|
}
|
|
15
21
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./middleware-BT3OA5YL.cjs");let t=require("@i18n-micro/core"),n=require("@i18n-micro/utils/active-locales"),r=require("@i18n-micro/utils/app-path"),i=require("@i18n-micro/utils/locale-head");var a=[`messages`,`plural`,`missingHandler`,`routingStrategy`],o=`virtual:i18n-micro/config`,s=`virtual:i18n-micro/messages`,c=e=>`\0${e}`,l=`@i18n-micro/astro/node`;function u(e,t){let r=e.locales||[];return{defaultLocale:e.locale,fallbackLocale:e.fallbackLocale||e.locale,locales:r,localeCodes:(0,n.getEnabledLocaleCodes)(r),translationDir:e.translationDir||null,autoDetect:e.autoDetect??!0,redirectToDefault:e.redirectToDefault??!1,localeCookie:e.localeCookie===null?null:e.localeCookie||`i18n-locale`,missingWarn:e.missingWarn??!1,base:t===`/`?``:t}}function d(e,t){let n=`export const config = ${JSON.stringify(u(e,t.base))}`,i=[],a=async n=>{let{translationDir:r,disablePageLocales:a}=e;if(!r)return`export const messages = {"root":{},"routes":{}}`;let{readTranslationDir:o}=await import(l),{messages:s,files:c}=o({translationDir:r,rootDir:t.root,disablePageLocales:a});i=c;for(let e of c)n(e);return`export const messages = ${JSON.stringify(s)}`};return{name:`vite-plugin-i18n-micro-config`,resolveId(e){return e===o||e===s?c(e):void 0},load(e){return e===c(o)?n:e===c(s)?a(e=>this.addWatchFile(e)):void 0},configureServer(t){let n=e.translationDir&&`/${e.translationDir.replace(/^\.?\/+|\/+$/g,``)}/`;n&&t.watcher.on(`add`,e=>{e.endsWith(`.json`)&&(0,r.forwardSlashes)(e).includes(n)&&i[0]&&t.watcher.emit(`change`,i[0])})}}}function f(e,t){let r=(0,n.getEnabledLocaleCodes)(e.locales);return e.middleware!==!1||t.i18n||!r.includes(e.locale)?{}:{i18n:{locales:r,defaultLocale:e.locale,routing:`manual`}}}function p(e){let t=a.find(t=>e[t]!==void 0);if(t)throw Error(`[i18n-micro] i18nIntegration no longer takes "${t}": pass it to createI18n / createI18nMiddleware in src/middleware.ts`);return{name:`@i18n-micro/astro`,hooks:{"astro:config:setup":t=>{let{updateConfig:n,addMiddleware:r,config:i}=t;n({...f(e,i),vite:{ssr:{noExternal:[`@i18n-micro/astro`]},plugins:[d(e,i)]}}),e.middleware!==!1&&r({order:`pre`,entrypoint:`@i18n-micro/astro/middleware`})},"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' {
|
|
@@ -11,7 +11,15 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
11
11
|
autoDetect: boolean;
|
|
12
12
|
redirectToDefault: boolean;
|
|
13
13
|
localeCookie: string | null;
|
|
14
|
-
missingWarn: boolean
|
|
14
|
+
missingWarn: boolean;
|
|
15
|
+
base: string;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
declare module 'virtual:i18n-micro/messages' {
|
|
20
|
+
export const messages: {
|
|
21
|
+
root: Record<string, import('@i18n-micro/types').Translations>;
|
|
22
|
+
routes: Record<string, Record<string, import('@i18n-micro/types').Translations>>;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`})}}}}function m(t){return new e.o(t)}function h(e){let t=e.locals.i18n;if(!t)throw Error(`i18n instance not found. Make sure i18n middleware is configured.`);return t}function g(e){return e.locals.locale??h(e).getLocale()}function _(e){return e.locals.defaultLocale??h(e).getFallbackLocale()}function v(e){return e.locals.locales||[]}function y(t){let{locals:i}=t,a=i.i18nBase??``,o=_(t),s=v(t);return{base:a,defaultLocale:o,codes:(0,n.getEnabledLocaleCodes)(s),strategy:i.routingStrategy??e.r(s,o),path:(0,r.withoutAppBaseURL)((i.currentUrl??t.url).pathname,a)}}function b(t){let n=h(t),i=g(t),a=_(t),o=v(t),s=y(t),{strategy:c,codes:l,base:u,path:d}=s,f=e=>(0,r.withoutAppBaseURL)(e,u);return{locale:i,defaultLocale:a,locales:o,t:n.t.bind(n),ts:n.ts.bind(n),tc:n.tc.bind(n),tn:n.tn.bind(n),td:n.td.bind(n),tdr:n.tdr.bind(n),has:n.has.bind(n),getRoute:n.getRoute.bind(n),getRouteName:e=>e===void 0?n.getRoute():c.getRouteName(f(e),l),getLocaleFromPath:e=>c.getLocaleFromPath(e===void 0?d:f(e),a,l),switchLocalePath:t=>e.a(c.switchLocalePath(d,t,l,a),u),localizePath:(t,n)=>e.i(t,n||i,s),getI18n:()=>n,getBasePath:e=>c.removeLocaleFromPath(e?f(e.pathname):d,l),addTranslations:n.addTranslations.bind(n),addRouteTranslations:n.addRouteTranslations.bind(n),mergeTranslations:n.mergeTranslations.bind(n),clearCache:n.clearCache.bind(n)}}function x(e){return b(e).getBasePath(e.locals.currentUrl??e.url)}function S(e){let{locale:t}=e.params;if(!t||!(0,n.getEnabledLocaleCodes)(v(e)).includes(t))return new Response(null,{status:404});let r=e.locals.i18n;return r&&(r.locale=t,e.locals.locale=t),x(e)}function C(t,r={}){let{addDirAttribute:a,addSeoAttributes:o,hreflangBaseLanguage:s}=r,c=r.baseUrl??t.site?.origin??``,{base:l,defaultLocale:u,codes:d,strategy:f,path:p}=y(t),m=g(t),h=(0,n.getEnabledLocales)(v(t)),_=h.find(e=>e.code===m);if(!_)return{htmlAttrs:{},link:[],meta:[]};let b=t=>(0,i.joinBase)(c,e.a(f.switchLocalePath(p,t,d,u),l)),x=h.find(e=>e.code===u);return(0,i.buildLocaleHead)({locale:_,seoLocales:h.filter(e=>e.seo!==!1),hrefOf:b,canonical:(0,i.joinBase)(c,e.a(p,l)),xDefault:x&&x.seo!==!1?b(u):void 0,addDirAttribute:a,addSeoAttributes:o,hreflangBaseLanguage:s})}function w(e,n){let r={};for(let i of n){let n=(0,t.getByPath)(e,i);n!=null&&(r=(0,t.setTranslationAtKey)(r,i,n))}return r}var T=2e4,E=new WeakSet;function D(e){try{return JSON.stringify(e).length}catch{return 0}}function O(e){if((0,t.isProduction)()||E.has(e))return;E.add(e);let n=D(e);n>T&&console.warn(`[i18n-micro] getI18nProps() without keys puts ${n} bytes in every island's props: pass the keys the island uses.`)}function k(e,t){let n=h(e),r=n.getRoute(),i=n.resolveTranslations(r);t?.length||O(i);let a=n.getLocaleIso();return{locale:g(e),pluralLocale:n.pluralLocale(),...Object.keys(a).length>0&&{localeIso:a},fallbackLocale:n.getFallbackLocale(),currentRoute:r,translations:{[r]:t&&t.length>0?w(i,t):i}}}exports.AstroI18n=e.o,Object.defineProperty(exports,"FormatService",{enumerable:!0,get:function(){return t.FormatService}}),exports.createAstroRouterAdapter=e.r,exports.createI18n=m,exports.createI18nMiddleware=e.t,Object.defineProperty(exports,"defaultPlural",{enumerable:!0,get:function(){return t.defaultPlural}}),exports.detectLocale=e.n,exports.getDefaultLocale=_,exports.getI18n=h,exports.getI18nProps=k,exports.getLocale=g,exports.getLocaleRewritePath=x,exports.getLocales=v,exports.i18nIntegration=p,Object.defineProperty(exports,"interpolate",{enumerable:!0,get:function(){return t.interpolate}}),Object.defineProperty(exports,"localeIsoMap",{enumerable:!0,get:function(){return t.localeIsoMap}}),exports.prepareLocaleRewrite=S,exports.useI18n=b,exports.useLocaleHead=C;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
export { defaultPlural, FormatService, interpolate } from '@i18n-micro/core';
|
|
1
|
+
export { defaultPlural, FormatService, interpolate, localeIsoMap } from '@i18n-micro/core';
|
|
2
2
|
export type { CleanTranslation, Getter, Locale, LocaleCode, Params, PluralFunc, Translations } from '@i18n-micro/types';
|
|
3
|
-
export { AstroI18n, type AstroI18nOptions } from './composer';
|
|
4
|
-
export type { I18nIntegrationOptions } from './integration';
|
|
5
|
-
export { createI18n, i18nIntegration } from './integration';
|
|
6
|
-
export {
|
|
7
|
-
export
|
|
8
|
-
export {
|
|
9
|
-
export type {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export type { I18nRoutingStrategy } from './router/types';
|
|
13
|
-
export type { I18nClientProps, LocaleHeadOptions, LocaleHeadResult } from './utils';
|
|
14
|
-
export { getDefaultLocale, getI18n, getI18nProps, getLocale, getLocaleRewritePath, getLocales, prepareLocaleRewrite, useI18n, useLocaleHead, } from './utils';
|
|
3
|
+
export { AstroI18n, type AstroI18nOptions } from './composer.cjs';
|
|
4
|
+
export type { I18nIntegrationOptions } from './integration.cjs';
|
|
5
|
+
export { createI18n, i18nIntegration } from './integration.cjs';
|
|
6
|
+
export type { I18nMiddlewareOptions } from './middleware.cjs';
|
|
7
|
+
export { createI18nMiddleware, detectLocale } from './middleware.cjs';
|
|
8
|
+
export { createAstroRouterAdapter } from './router/adapter.cjs';
|
|
9
|
+
export type { I18nRoutingStrategy } from './router/types.cjs';
|
|
10
|
+
export type { I18nClientProps, LocaleHeadOptions, LocaleHeadResult } from './utils.cjs';
|
|
11
|
+
export { getDefaultLocale, getI18n, getI18nProps, getLocale, getLocaleRewritePath, getLocales, prepareLocaleRewrite, useI18n, useLocaleHead, } from './utils.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
export { defaultPlural, FormatService, interpolate } from '@i18n-micro/core';
|
|
1
|
+
export { defaultPlural, FormatService, interpolate, localeIsoMap } from '@i18n-micro/core';
|
|
2
2
|
export type { CleanTranslation, Getter, Locale, LocaleCode, Params, PluralFunc, Translations } from '@i18n-micro/types';
|
|
3
|
-
export { AstroI18n, type AstroI18nOptions } from './composer';
|
|
4
|
-
export type { I18nIntegrationOptions } from './integration';
|
|
5
|
-
export { createI18n, i18nIntegration } from './integration';
|
|
6
|
-
export {
|
|
7
|
-
export
|
|
8
|
-
export {
|
|
9
|
-
export type {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export type { I18nRoutingStrategy } from './router/types';
|
|
13
|
-
export type { I18nClientProps, LocaleHeadOptions, LocaleHeadResult } from './utils';
|
|
14
|
-
export { getDefaultLocale, getI18n, getI18nProps, getLocale, getLocaleRewritePath, getLocales, prepareLocaleRewrite, useI18n, useLocaleHead, } from './utils';
|
|
3
|
+
export { AstroI18n, type AstroI18nOptions } from './composer.js';
|
|
4
|
+
export type { I18nIntegrationOptions } from './integration.js';
|
|
5
|
+
export { createI18n, i18nIntegration } from './integration.js';
|
|
6
|
+
export type { I18nMiddlewareOptions } from './middleware.js';
|
|
7
|
+
export { createI18nMiddleware, detectLocale } from './middleware.js';
|
|
8
|
+
export { createAstroRouterAdapter } from './router/adapter.js';
|
|
9
|
+
export type { I18nRoutingStrategy } from './router/types.js';
|
|
10
|
+
export type { I18nClientProps, LocaleHeadOptions, LocaleHeadResult } from './utils.js';
|
|
11
|
+
export { getDefaultLocale, getI18n, getI18nProps, getLocale, getLocaleRewritePath, getLocales, prepareLocaleRewrite, useI18n, useLocaleHead, } from './utils.js';
|