@i18n-micro/astro 1.3.24 → 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/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,84 +1,28 @@
|
|
|
1
1
|
# @i18n-micro/astro
|
|
2
2
|
|
|
3
|
-
Astro integration for
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
3
|
+
Astro integration for Nuxt I18n Micro: locale from the URL, a per-request instance in `Astro.locals`, `useI18n(Astro)`, `.astro` components, a home-page redirect to the visitor's language, `useLocaleHead` for SEO, and adapters for Vue, React, Preact and Svelte islands.
|
|
6
4
|
|
|
7
5
|
```bash
|
|
8
6
|
pnpm add @i18n-micro/astro
|
|
9
|
-
# or
|
|
10
|
-
npm install @i18n-micro/astro
|
|
11
|
-
# or
|
|
12
|
-
yarn add @i18n-micro/astro
|
|
13
7
|
```
|
|
14
8
|
|
|
15
|
-
|
|
9
|
+
Peer: `astro` `^5.0.0 || ^6.0.0 || ^7.0.0` (island frameworks optional).
|
|
16
10
|
|
|
17
|
-
|
|
11
|
+
The integration bundles the dictionaries and installs the middleware:
|
|
18
12
|
|
|
19
|
-
```
|
|
13
|
+
```ts
|
|
14
|
+
// astro.config.mjs
|
|
20
15
|
import { defineConfig } from 'astro/config'
|
|
21
16
|
import { i18nIntegration } from '@i18n-micro/astro'
|
|
22
17
|
|
|
23
18
|
export default defineConfig({
|
|
24
|
-
integrations: [
|
|
25
|
-
i18nIntegration({
|
|
26
|
-
locale: 'en',
|
|
27
|
-
fallbackLocale: 'en',
|
|
28
|
-
locales: [
|
|
29
|
-
{ code: 'en', iso: 'en-US', displayName: 'English' },
|
|
30
|
-
{ code: 'fr', iso: 'fr-FR', displayName: 'Français' },
|
|
31
|
-
],
|
|
32
|
-
messages: {
|
|
33
|
-
en: { greeting: 'Hello, {name}!' },
|
|
34
|
-
fr: { greeting: 'Bonjour, {name}!' },
|
|
35
|
-
},
|
|
36
|
-
}),
|
|
37
|
-
],
|
|
19
|
+
integrations: [i18nIntegration({ locale: 'en', locales: [{ code: 'en' }, { code: 'de' }], translationDir: 'src/locales' })],
|
|
38
20
|
})
|
|
39
21
|
```
|
|
40
22
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
```astro
|
|
44
|
-
---
|
|
45
|
-
// src/pages/index.astro
|
|
46
|
-
import { useI18n } from '@i18n-micro/astro'
|
|
47
|
-
|
|
48
|
-
const { t, locale } = useI18n(Astro)
|
|
49
|
-
---
|
|
50
|
-
|
|
51
|
-
<html>
|
|
52
|
-
<head>
|
|
53
|
-
<title>{t('greeting', { name: 'World' })}</title>
|
|
54
|
-
</head>
|
|
55
|
-
<body>
|
|
56
|
-
<h1>{t('greeting', { name: 'World' })}</h1>
|
|
57
|
-
</body>
|
|
58
|
-
</html>
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### 3. Locale-prefixed URLs (`/[locale]/*`)
|
|
62
|
-
|
|
63
|
-
When using `createAstroRouterAdapter`, add rewrite stubs under `src/pages/[locale]/`:
|
|
64
|
-
|
|
65
|
-
```astro
|
|
66
|
-
---
|
|
67
|
-
import { prepareLocaleRewrite } from '@i18n-micro/astro'
|
|
68
|
-
|
|
69
|
-
const rewriteTarget = prepareLocaleRewrite(Astro)
|
|
70
|
-
if (rewriteTarget instanceof Response) return rewriteTarget
|
|
71
|
-
|
|
72
|
-
return Astro.rewrite(rewriteTarget)
|
|
73
|
-
---
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
See the [full Astro integration guide](https://s00d.github.io/nuxt-i18n-micro/integrations/astro-package.html#locale-prefixed-routes-locale) for routing layout and typecheck notes.
|
|
77
|
-
|
|
78
|
-
## Resources
|
|
23
|
+
Islands: [https://s00d.github.io/nuxt-i18n-micro/integrations/astro-islands](https://s00d.github.io/nuxt-i18n-micro/integrations/astro-islands).
|
|
79
24
|
|
|
80
|
-
-
|
|
81
|
-
- **Documentation**: [https://s00d.github.io/nuxt-i18n-micro/](https://s00d.github.io/nuxt-i18n-micro/)
|
|
25
|
+
Docs: [https://s00d.github.io/nuxt-i18n-micro/integrations/astro-package](https://s00d.github.io/nuxt-i18n-micro/integrations/astro-package) · Repository: [github.com/s00d/nuxt-i18n-micro](https://github.com/s00d/nuxt-i18n-micro)
|
|
82
26
|
|
|
83
27
|
## License
|
|
84
28
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const onRequest: import('astro').MiddlewareHandler;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { CleanTranslation, Params, TranslationKey, Translations } from '@i18n-micro/types';
|
|
2
|
+
import { I18nClientProps } from '../utils.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* I18n state for client islands
|
|
5
|
+
*/
|
|
6
|
+
export interface I18nState {
|
|
7
|
+
locale: string;
|
|
8
|
+
/** The tag plurals go by, when it is not `locale`. */
|
|
9
|
+
pluralLocale?: string;
|
|
10
|
+
/** Tags of the codes that have one: `setLocale` finds the new locale's here. */
|
|
11
|
+
localeIso?: Record<string, string>;
|
|
12
|
+
fallbackLocale: string;
|
|
13
|
+
translations: Record<string, Translations>;
|
|
14
|
+
currentRoute: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Pure function to get a translation from state, answering as the server's `t()` does over the
|
|
18
|
+
* same keys. `getI18nProps` already merged the root and fallback dictionaries into the state.
|
|
19
|
+
* For Linked Messages (@:path.to.key), use the server-side i18n instance.
|
|
20
|
+
*/
|
|
21
|
+
export declare function translate(state: I18nState, key: string, params?: Params, defaultValue?: string | null, routeName?: string): string | number | boolean | Translations | null;
|
|
22
|
+
/**
|
|
23
|
+
* `tc` of every island adapter, as the server's `BaseI18n.tc`: a missing key gives `defaultValue`
|
|
24
|
+
* (else the key), because the getter reports the miss to `defaultPlural` instead of the key.
|
|
25
|
+
*/
|
|
26
|
+
export declare function translatePlural(state: I18nState, key: TranslationKey, count: number | Params, defaultValue?: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a translation exists in the state: a subtree counts, as on the server
|
|
29
|
+
*/
|
|
30
|
+
export declare function hasTranslation(state: I18nState, key: string, routeName?: string): boolean;
|
|
31
|
+
/** `state` in another locale, with that locale's plural tag. */
|
|
32
|
+
export declare const withLocale: (state: I18nState, locale: string) => I18nState;
|
|
33
|
+
/** What every island adapter returns, over the state it reads at each call. */
|
|
34
|
+
export declare function createIslandApi(getState: () => I18nState): {
|
|
35
|
+
t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation;
|
|
36
|
+
ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeName?: string) => string;
|
|
37
|
+
tc: (key: TranslationKey, count: number | Params, defaultValue?: string) => string;
|
|
38
|
+
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
39
|
+
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
40
|
+
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
41
|
+
has: (key: TranslationKey, routeName?: string) => boolean;
|
|
42
|
+
getRoute: () => string;
|
|
43
|
+
};
|
|
44
|
+
type SetI18nState = (update: I18nState | ((current: I18nState) => I18nState)) => void;
|
|
45
|
+
export interface I18nContextValue {
|
|
46
|
+
state: I18nState;
|
|
47
|
+
setState: SetI18nState;
|
|
48
|
+
}
|
|
49
|
+
/** What an island binding needs of its library: core stays free of framework imports. */
|
|
50
|
+
interface IslandLibrary<Children, Element, Context extends {
|
|
51
|
+
Provider: unknown;
|
|
52
|
+
}> {
|
|
53
|
+
createContext: (value: I18nContextValue | null) => Context;
|
|
54
|
+
createElement: (type: Context['Provider'], props: {
|
|
55
|
+
value: I18nContextValue;
|
|
56
|
+
}, children: Children) => Element;
|
|
57
|
+
useCallback: <T extends (arg: string) => void>(callback: T, deps: unknown[]) => T;
|
|
58
|
+
useContext: (context: Context) => I18nContextValue | null;
|
|
59
|
+
useMemo: <T>(factory: () => T, deps: unknown[]) => T;
|
|
60
|
+
useState: <T>(initial: T) => [T, (update: T | ((current: T) => T)) => void];
|
|
61
|
+
}
|
|
62
|
+
/** The provider and hook of an island library (Preact and React have one API). */
|
|
63
|
+
export declare function createIslandBinding<Children, Element, Context extends {
|
|
64
|
+
Provider: unknown;
|
|
65
|
+
}>(lib: IslandLibrary<Children, Element, Context>): {
|
|
66
|
+
I18nProvider: ({ children, value }: {
|
|
67
|
+
children: Children;
|
|
68
|
+
value: I18nClientProps;
|
|
69
|
+
}) => Element;
|
|
70
|
+
useAstroI18n: () => {
|
|
71
|
+
locale: string;
|
|
72
|
+
fallbackLocale: string;
|
|
73
|
+
currentRoute: string;
|
|
74
|
+
setLocale: (locale: string) => void;
|
|
75
|
+
setRoute: (currentRoute: string) => void;
|
|
76
|
+
t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation;
|
|
77
|
+
ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeName?: string) => string;
|
|
78
|
+
tc: (key: TranslationKey, count: number | Params, defaultValue?: string) => string;
|
|
79
|
+
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
80
|
+
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
81
|
+
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
82
|
+
has: (key: TranslationKey, routeName?: string) => boolean;
|
|
83
|
+
getRoute: () => string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
export {};
|
package/dist/client/core.d.ts
CHANGED
|
@@ -1,23 +1,86 @@
|
|
|
1
|
-
import { Params, Translations } from '@i18n-micro/types';
|
|
1
|
+
import { CleanTranslation, Params, TranslationKey, Translations } from '@i18n-micro/types';
|
|
2
|
+
import { I18nClientProps } from '../utils.js';
|
|
2
3
|
/**
|
|
3
4
|
* I18n state for client islands
|
|
4
5
|
*/
|
|
5
6
|
export interface I18nState {
|
|
6
7
|
locale: string;
|
|
8
|
+
/** The tag plurals go by, when it is not `locale`. */
|
|
9
|
+
pluralLocale?: string;
|
|
10
|
+
/** Tags of the codes that have one: `setLocale` finds the new locale's here. */
|
|
11
|
+
localeIso?: Record<string, string>;
|
|
7
12
|
fallbackLocale: string;
|
|
8
13
|
translations: Record<string, Translations>;
|
|
9
14
|
currentRoute: string;
|
|
10
15
|
}
|
|
11
16
|
/**
|
|
12
|
-
* Pure function to get a translation from state
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* It supports basic translation lookup and interpolation.
|
|
16
|
-
* Returns CleanTranslation which can be string, number, boolean, object, or null.
|
|
17
|
-
* For advanced features like Linked Messages (@:path.to.key), use the server-side i18n instance.
|
|
17
|
+
* Pure function to get a translation from state, answering as the server's `t()` does over the
|
|
18
|
+
* same keys. `getI18nProps` already merged the root and fallback dictionaries into the state.
|
|
19
|
+
* For Linked Messages (@:path.to.key), use the server-side i18n instance.
|
|
18
20
|
*/
|
|
19
21
|
export declare function translate(state: I18nState, key: string, params?: Params, defaultValue?: string | null, routeName?: string): string | number | boolean | Translations | null;
|
|
20
22
|
/**
|
|
21
|
-
*
|
|
23
|
+
* `tc` of every island adapter, as the server's `BaseI18n.tc`: a missing key gives `defaultValue`
|
|
24
|
+
* (else the key), because the getter reports the miss to `defaultPlural` instead of the key.
|
|
25
|
+
*/
|
|
26
|
+
export declare function translatePlural(state: I18nState, key: TranslationKey, count: number | Params, defaultValue?: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a translation exists in the state: a subtree counts, as on the server
|
|
22
29
|
*/
|
|
23
30
|
export declare function hasTranslation(state: I18nState, key: string, routeName?: string): boolean;
|
|
31
|
+
/** `state` in another locale, with that locale's plural tag. */
|
|
32
|
+
export declare const withLocale: (state: I18nState, locale: string) => I18nState;
|
|
33
|
+
/** What every island adapter returns, over the state it reads at each call. */
|
|
34
|
+
export declare function createIslandApi(getState: () => I18nState): {
|
|
35
|
+
t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation;
|
|
36
|
+
ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeName?: string) => string;
|
|
37
|
+
tc: (key: TranslationKey, count: number | Params, defaultValue?: string) => string;
|
|
38
|
+
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
39
|
+
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
40
|
+
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
41
|
+
has: (key: TranslationKey, routeName?: string) => boolean;
|
|
42
|
+
getRoute: () => string;
|
|
43
|
+
};
|
|
44
|
+
type SetI18nState = (update: I18nState | ((current: I18nState) => I18nState)) => void;
|
|
45
|
+
export interface I18nContextValue {
|
|
46
|
+
state: I18nState;
|
|
47
|
+
setState: SetI18nState;
|
|
48
|
+
}
|
|
49
|
+
/** What an island binding needs of its library: core stays free of framework imports. */
|
|
50
|
+
interface IslandLibrary<Children, Element, Context extends {
|
|
51
|
+
Provider: unknown;
|
|
52
|
+
}> {
|
|
53
|
+
createContext: (value: I18nContextValue | null) => Context;
|
|
54
|
+
createElement: (type: Context['Provider'], props: {
|
|
55
|
+
value: I18nContextValue;
|
|
56
|
+
}, children: Children) => Element;
|
|
57
|
+
useCallback: <T extends (arg: string) => void>(callback: T, deps: unknown[]) => T;
|
|
58
|
+
useContext: (context: Context) => I18nContextValue | null;
|
|
59
|
+
useMemo: <T>(factory: () => T, deps: unknown[]) => T;
|
|
60
|
+
useState: <T>(initial: T) => [T, (update: T | ((current: T) => T)) => void];
|
|
61
|
+
}
|
|
62
|
+
/** The provider and hook of an island library (Preact and React have one API). */
|
|
63
|
+
export declare function createIslandBinding<Children, Element, Context extends {
|
|
64
|
+
Provider: unknown;
|
|
65
|
+
}>(lib: IslandLibrary<Children, Element, Context>): {
|
|
66
|
+
I18nProvider: ({ children, value }: {
|
|
67
|
+
children: Children;
|
|
68
|
+
value: I18nClientProps;
|
|
69
|
+
}) => Element;
|
|
70
|
+
useAstroI18n: () => {
|
|
71
|
+
locale: string;
|
|
72
|
+
fallbackLocale: string;
|
|
73
|
+
currentRoute: string;
|
|
74
|
+
setLocale: (locale: string) => void;
|
|
75
|
+
setRoute: (currentRoute: string) => void;
|
|
76
|
+
t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation;
|
|
77
|
+
ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeName?: string) => string;
|
|
78
|
+
tc: (key: TranslationKey, count: number | Params, defaultValue?: string) => string;
|
|
79
|
+
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
80
|
+
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
81
|
+
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
82
|
+
has: (key: TranslationKey, routeName?: string) => boolean;
|
|
83
|
+
getRoute: () => string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
export {};
|
package/dist/client/index.d.cts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
export type { I18nState } from './core';
|
|
2
|
-
export { hasTranslation, translate } from './core';
|
|
3
|
-
export { I18nProvider as I18nProviderPreact, useAstroI18n as useAstroI18nPreact } from './preact';
|
|
4
|
-
export { I18nProvider, useAstroI18n as useAstroI18nReact } from './react';
|
|
5
|
-
export { createI18nStore, useAstroI18n as useAstroI18nSvelte } from './svelte';
|
|
6
|
-
export { provideI18n, useAstroI18n as useAstroI18nVue } from './vue';
|
|
1
|
+
export type { I18nState } from './core.cjs';
|
|
2
|
+
export { hasTranslation, translate } from './core.cjs';
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
export type { I18nState } from './core';
|
|
2
|
-
export { hasTranslation, translate } from './core';
|
|
3
|
-
export { I18nProvider as I18nProviderPreact, useAstroI18n as useAstroI18nPreact } from './preact';
|
|
4
|
-
export { I18nProvider, useAstroI18n as useAstroI18nReact } from './react';
|
|
5
|
-
export { createI18nStore, useAstroI18n as useAstroI18nSvelte } from './svelte';
|
|
6
|
-
export { provideI18n, useAstroI18n as useAstroI18nVue } from './vue';
|
|
1
|
+
export type { I18nState } from './core.js';
|
|
2
|
+
export { hasTranslation, translate } from './core.js';
|
package/dist/client/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { I18nProvider as n, useAstroI18n as r } from "./preact.js";
|
|
3
|
-
import { I18nProvider as i, useAstroI18n as a } from "./react.js";
|
|
4
|
-
import { createI18nStore as o, useAstroI18n as s } from "./svelte.js";
|
|
5
|
-
import { n as c, t as l } from "../vue-CWHjIOiS.js";
|
|
6
|
-
export { i as I18nProvider, n as I18nProviderPreact, o as createI18nStore, t as hasTranslation, l as provideI18n, e as translate, r as useAstroI18nPreact, a as useAstroI18nReact, s as useAstroI18nSvelte, c as useAstroI18nVue };
|
|
1
|
+
export { r as hasTranslation, i as translate } from "../core-DTAcn2yF.js";
|
package/dist/client/preact.d.ts
CHANGED
|
@@ -1,30 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ComponentChildren } from 'preact';
|
|
3
|
-
import { I18nClientProps } from '../utils';
|
|
4
|
-
import { I18nState } from './core';
|
|
5
|
-
/**
|
|
6
|
-
* Провайдер для i18n в Preact островах
|
|
7
|
-
*/
|
|
1
|
+
import { ComponentChildren, VNode } from 'preact';
|
|
8
2
|
export declare const I18nProvider: ({ children, value }: {
|
|
9
3
|
children: ComponentChildren;
|
|
10
|
-
value: I18nClientProps;
|
|
11
|
-
}) =>
|
|
12
|
-
value: I18nState | null;
|
|
13
|
-
children?: ComponentChildren;
|
|
14
|
-
}>;
|
|
15
|
-
/**
|
|
16
|
-
* Хук для использования i18n в Preact компонентах
|
|
17
|
-
*/
|
|
18
|
-
export declare function useAstroI18n(): {
|
|
19
|
-
t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation;
|
|
20
|
-
ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeName?: string) => string;
|
|
21
|
-
tc: (key: TranslationKey, count: number | 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: TranslationKey, routeName?: string) => boolean;
|
|
4
|
+
value: import('../index.js').I18nClientProps;
|
|
5
|
+
}) => VNode<{}>, useAstroI18n: () => {
|
|
26
6
|
locale: string;
|
|
27
7
|
fallbackLocale: string;
|
|
28
8
|
currentRoute: string;
|
|
9
|
+
setLocale: (locale: string) => void;
|
|
10
|
+
setRoute: (currentRoute: string) => void;
|
|
11
|
+
t: (key: import('@i18n-micro/types').TranslationKey, params?: import('@i18n-micro/types').Params, defaultValue?: string | null, routeName?: string) => import('@i18n-micro/types').CleanTranslation;
|
|
12
|
+
ts: (key: import('@i18n-micro/types').TranslationKey, params?: import('@i18n-micro/types').Params, defaultValue?: string, routeName?: string) => string;
|
|
13
|
+
tc: (key: import('@i18n-micro/types').TranslationKey, count: number | import('@i18n-micro/types').Params, defaultValue?: string) => string;
|
|
14
|
+
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
15
|
+
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
16
|
+
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
17
|
+
has: (key: import('@i18n-micro/types').TranslationKey, routeName?: string) => boolean;
|
|
29
18
|
getRoute: () => string;
|
|
30
19
|
};
|
package/dist/client/preact.js
CHANGED
|
@@ -1,37 +1,13 @@
|
|
|
1
|
-
import { n as e
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
function f() {
|
|
16
|
-
let n = o(u);
|
|
17
|
-
if (!n) throw Error("useAstroI18n must be used within an I18nProvider");
|
|
18
|
-
let i = s(() => (t, r, i, a) => e(n, t, r, i, a), [n]);
|
|
19
|
-
return {
|
|
20
|
-
t: i,
|
|
21
|
-
ts: s(() => (e, t, n, r) => i(e, t, n, r)?.toString() ?? n ?? e, [i]),
|
|
22
|
-
tc: s(() => (e, t, a) => {
|
|
23
|
-
let { count: o, ...s } = typeof t == "number" ? { count: t } : t;
|
|
24
|
-
return o === void 0 ? a ?? e : r(e, Number.parseInt(o.toString(), 10), s, n.locale, (e, t, n) => i(e, t, n)) ?? a ?? e;
|
|
25
|
-
}, [i, n]),
|
|
26
|
-
tn: s(() => (e, t) => l.formatNumber(e, n.locale, t), [n.locale]),
|
|
27
|
-
td: s(() => (e, t) => l.formatDate(e, n.locale, t), [n.locale]),
|
|
28
|
-
tdr: s(() => (e, t) => l.formatRelativeTime(e, n.locale, t), [n.locale]),
|
|
29
|
-
has: s(() => (e, r) => t(n, e, r), [n]),
|
|
30
|
-
locale: n.locale,
|
|
31
|
-
fallbackLocale: n.fallbackLocale,
|
|
32
|
-
currentRoute: n.currentRoute,
|
|
33
|
-
getRoute: () => n.currentRoute
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
//#endregion
|
|
37
|
-
export { d as I18nProvider, f as useAstroI18n };
|
|
1
|
+
import { n as e } from "../core-DTAcn2yF.js";
|
|
2
|
+
import { createContext as t, createElement as n } from "preact";
|
|
3
|
+
import { useCallback as r, useContext as i, useMemo as a, useState as o } from "preact/hooks";
|
|
4
|
+
// src/client/preact.tsx
|
|
5
|
+
var { I18nProvider: s, useAstroI18n: c } = /*#__PURE__*/ e({
|
|
6
|
+
createContext: t,
|
|
7
|
+
createElement: n,
|
|
8
|
+
useCallback: r,
|
|
9
|
+
useContext: i,
|
|
10
|
+
useMemo: a,
|
|
11
|
+
useState: o
|
|
12
|
+
});
|
|
13
|
+
export { s as I18nProvider, c as useAstroI18n };
|
package/dist/client/react.d.ts
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
export declare function I18nProvider({ children, value }: {
|
|
8
|
-
children: React.ReactNode;
|
|
9
|
-
value: I18nClientProps;
|
|
10
|
-
}): React.ReactElement;
|
|
11
|
-
/**
|
|
12
|
-
* Хук для использования i18n в React компонентах
|
|
13
|
-
*/
|
|
14
|
-
export declare function useAstroI18n(): {
|
|
15
|
-
t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation;
|
|
16
|
-
ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeName?: string) => string;
|
|
17
|
-
tc: (key: TranslationKey, count: number | Params, defaultValue?: string) => string;
|
|
18
|
-
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
19
|
-
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
20
|
-
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
21
|
-
has: (key: TranslationKey, routeName?: string) => boolean;
|
|
1
|
+
import { ReactElement, ReactNode } from 'react';
|
|
2
|
+
export declare const I18nProvider: ({ children, value }: {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
value: import('../index.js').I18nClientProps;
|
|
5
|
+
}) => ReactElement<unknown, string | import('react').JSXElementConstructor<any>>, useAstroI18n: () => {
|
|
22
6
|
locale: string;
|
|
23
7
|
fallbackLocale: string;
|
|
24
8
|
currentRoute: string;
|
|
9
|
+
setLocale: (locale: string) => void;
|
|
10
|
+
setRoute: (currentRoute: string) => void;
|
|
11
|
+
t: (key: import('@i18n-micro/types').TranslationKey, params?: import('@i18n-micro/types').Params, defaultValue?: string | null, routeName?: string) => import('@i18n-micro/types').CleanTranslation;
|
|
12
|
+
ts: (key: import('@i18n-micro/types').TranslationKey, params?: import('@i18n-micro/types').Params, defaultValue?: string, routeName?: string) => string;
|
|
13
|
+
tc: (key: import('@i18n-micro/types').TranslationKey, count: number | import('@i18n-micro/types').Params, defaultValue?: string) => string;
|
|
14
|
+
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
15
|
+
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
16
|
+
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
17
|
+
has: (key: import('@i18n-micro/types').TranslationKey, routeName?: string) => boolean;
|
|
25
18
|
getRoute: () => string;
|
|
26
19
|
};
|
package/dist/client/react.js
CHANGED
|
@@ -1,37 +1,12 @@
|
|
|
1
|
-
import { n as e
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return i.createElement(u.Provider, { value: n }, e);
|
|
14
|
-
}
|
|
15
|
-
function f() {
|
|
16
|
-
let n = o(u);
|
|
17
|
-
if (!n) throw Error("useAstroI18n must be used within an I18nProvider");
|
|
18
|
-
let i = s(() => (t, r, i, a) => e(n, t, r, i, a), [n]);
|
|
19
|
-
return {
|
|
20
|
-
t: i,
|
|
21
|
-
ts: s(() => (e, t, n, r) => i(e, t, n, r)?.toString() ?? n ?? e, [i]),
|
|
22
|
-
tc: s(() => (e, t, a) => {
|
|
23
|
-
let { count: o, ...s } = typeof t == "number" ? { count: t } : t;
|
|
24
|
-
return o === void 0 ? a ?? e : r(e, Number.parseInt(o.toString(), 10), s, n.locale, (e, t, n) => i(e, t, n)) ?? a ?? e;
|
|
25
|
-
}, [i, n]),
|
|
26
|
-
tn: s(() => (e, t) => l.formatNumber(e, n.locale, t), [n.locale]),
|
|
27
|
-
td: s(() => (e, t) => l.formatDate(e, n.locale, t), [n.locale]),
|
|
28
|
-
tdr: s(() => (e, t) => l.formatRelativeTime(e, n.locale, t), [n.locale]),
|
|
29
|
-
has: s(() => (e, r) => t(n, e, r), [n]),
|
|
30
|
-
locale: n.locale,
|
|
31
|
-
fallbackLocale: n.fallbackLocale,
|
|
32
|
-
currentRoute: n.currentRoute,
|
|
33
|
-
getRoute: () => n.currentRoute
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
//#endregion
|
|
37
|
-
export { d as I18nProvider, f as useAstroI18n };
|
|
1
|
+
import { n as e } from "../core-DTAcn2yF.js";
|
|
2
|
+
import { createContext as t, createElement as n, useCallback as r, useContext as i, useMemo as a, useState as o } from "react";
|
|
3
|
+
// src/client/react.tsx
|
|
4
|
+
var { I18nProvider: s, useAstroI18n: c } = /*#__PURE__*/ e({
|
|
5
|
+
createContext: t,
|
|
6
|
+
createElement: n,
|
|
7
|
+
useCallback: r,
|
|
8
|
+
useContext: i,
|
|
9
|
+
useMemo: a,
|
|
10
|
+
useState: o
|
|
11
|
+
});
|
|
12
|
+
export { s as I18nProvider, c as useAstroI18n };
|
package/dist/client/svelte.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CleanTranslation, Params, TranslationKey } from '@i18n-micro/types';
|
|
2
1
|
import { Writable } from 'svelte/store';
|
|
3
|
-
import { I18nClientProps } from '../utils';
|
|
4
|
-
import { I18nState } from './core';
|
|
2
|
+
import { I18nClientProps } from '../utils.js';
|
|
3
|
+
import { I18nState } from './core.js';
|
|
5
4
|
/**
|
|
6
|
-
* Creates a Svelte store for i18n state
|
|
5
|
+
* Creates a Svelte store for i18n state. An island kept by `transition:persist` follows its new
|
|
6
|
+
* props with `$: store.set(i18n)` (`$effect(() => store.set(i18n))` with runes).
|
|
7
7
|
*/
|
|
8
8
|
export declare function createI18nStore(props: I18nClientProps): Writable<I18nState>;
|
|
9
9
|
/**
|
|
@@ -11,18 +11,18 @@ export declare function createI18nStore(props: I18nClientProps): Writable<I18nSt
|
|
|
11
11
|
* Use in the component's <script> block
|
|
12
12
|
*/
|
|
13
13
|
export declare function useAstroI18n(store: Writable<I18nState>): {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
locale: string;
|
|
15
|
+
fallbackLocale: string;
|
|
16
|
+
currentRoute: string;
|
|
17
|
+
setLocale: (locale: string) => void;
|
|
18
|
+
setRoute: (routeName: 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;
|
|
18
22
|
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
19
23
|
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
20
24
|
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
21
|
-
has: (key: TranslationKey, routeName?: string) => boolean;
|
|
22
|
-
readonly locale: string;
|
|
23
|
-
readonly fallbackLocale: string;
|
|
24
|
-
readonly currentRoute: string;
|
|
25
|
-
setLocale: (locale: string) => void;
|
|
26
|
-
setRoute: (routeName: string) => void;
|
|
25
|
+
has: (key: import('@i18n-micro/types').TranslationKey, routeName?: string) => boolean;
|
|
27
26
|
getRoute: () => string;
|
|
27
|
+
store: Writable<I18nState>;
|
|
28
28
|
};
|
package/dist/client/svelte.js
CHANGED
|
@@ -1,62 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function s(e) {
|
|
7
|
-
return a({
|
|
8
|
-
locale: e.locale,
|
|
9
|
-
fallbackLocale: e.fallbackLocale,
|
|
10
|
-
translations: e.translations,
|
|
11
|
-
currentRoute: e.currentRoute
|
|
12
|
-
});
|
|
1
|
+
import { a as e, t } from "../core-DTAcn2yF.js";
|
|
2
|
+
import { get as n, writable as r } from "svelte/store";
|
|
3
|
+
// src/client/svelte.ts
|
|
4
|
+
function i(e) {
|
|
5
|
+
return r(e);
|
|
13
6
|
}
|
|
14
|
-
function
|
|
15
|
-
let
|
|
7
|
+
function a(r) {
|
|
8
|
+
let i = () => n(r);
|
|
16
9
|
return {
|
|
17
|
-
store:
|
|
18
|
-
t
|
|
19
|
-
ts: (e, t, n, r) => s(e, t, n, r)?.toString() ?? n ?? e,
|
|
20
|
-
tc: (e, t, n) => {
|
|
21
|
-
let i = a(), { count: o, ...c } = typeof t == "number" ? { count: t } : t;
|
|
22
|
-
return o === void 0 ? n ?? e : r(e, Number.parseInt(o.toString(), 10), c, i.locale, (e, t, n) => s(e, t, n)) ?? n ?? e;
|
|
23
|
-
},
|
|
24
|
-
tn: (e, t) => {
|
|
25
|
-
let n = a();
|
|
26
|
-
return o.formatNumber(e, n.locale, t);
|
|
27
|
-
},
|
|
28
|
-
td: (e, t) => {
|
|
29
|
-
let n = a();
|
|
30
|
-
return o.formatDate(e, n.locale, t);
|
|
31
|
-
},
|
|
32
|
-
tdr: (e, t) => {
|
|
33
|
-
let n = a();
|
|
34
|
-
return o.formatRelativeTime(e, n.locale, t);
|
|
35
|
-
},
|
|
36
|
-
has: (e, n) => t(a(), e, n),
|
|
10
|
+
store: r,
|
|
11
|
+
...t(i),
|
|
37
12
|
get locale() {
|
|
38
|
-
return
|
|
13
|
+
return i().locale;
|
|
39
14
|
},
|
|
40
15
|
get fallbackLocale() {
|
|
41
|
-
return
|
|
16
|
+
return i().fallbackLocale;
|
|
42
17
|
},
|
|
43
18
|
get currentRoute() {
|
|
44
|
-
return
|
|
19
|
+
return i().currentRoute;
|
|
45
20
|
},
|
|
46
|
-
setLocale: (
|
|
47
|
-
|
|
48
|
-
...t,
|
|
49
|
-
locale: e
|
|
50
|
-
}));
|
|
21
|
+
setLocale: (t) => {
|
|
22
|
+
r.update((n) => e(n, t));
|
|
51
23
|
},
|
|
52
24
|
setRoute: (e) => {
|
|
53
|
-
|
|
25
|
+
r.update((t) => ({
|
|
54
26
|
...t,
|
|
55
27
|
currentRoute: e
|
|
56
28
|
}));
|
|
57
|
-
}
|
|
58
|
-
getRoute: () => a().currentRoute
|
|
29
|
+
}
|
|
59
30
|
};
|
|
60
31
|
}
|
|
61
|
-
|
|
62
|
-
export { s as createI18nStore, c as useAstroI18n };
|
|
32
|
+
export { i as createI18nStore, a as useAstroI18n };
|