@i18n-micro/preact 1.2.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.
- package/dist/index.d.cts +271 -0
- package/package.json +40 -9
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { Attributes } from 'preact';
|
|
2
|
+
import { BaseI18n } from '@i18n-micro/core';
|
|
3
|
+
import { CleanTranslation } from '@i18n-micro/types';
|
|
4
|
+
import { ComponentChildren } from 'preact';
|
|
5
|
+
import { Context } from 'preact';
|
|
6
|
+
import { default as default_2 } from 'react';
|
|
7
|
+
import { defaultPlural } from '@i18n-micro/core';
|
|
8
|
+
import { FormatService } from '@i18n-micro/core';
|
|
9
|
+
import { Getter } from '@i18n-micro/types';
|
|
10
|
+
import { interpolate } from '@i18n-micro/core';
|
|
11
|
+
import { JSX as JSX_2 } from 'preact';
|
|
12
|
+
import { Locale } from '@i18n-micro/types';
|
|
13
|
+
import { LocaleCode } from '@i18n-micro/types';
|
|
14
|
+
import { ModuleOptions } from '@i18n-micro/types';
|
|
15
|
+
import { Params } from '@i18n-micro/types';
|
|
16
|
+
import { PluralFunc } from '@i18n-micro/types';
|
|
17
|
+
import { TranslationKey } from '@i18n-micro/types';
|
|
18
|
+
import { Translations } from '@i18n-micro/types';
|
|
19
|
+
import { TranslationStorage } from '@i18n-micro/core';
|
|
20
|
+
import { VNode } from 'preact';
|
|
21
|
+
|
|
22
|
+
export { CleanTranslation }
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Создает адаптер для работы с History API (универсальный для Pure Preact)
|
|
26
|
+
* Работает с любым роутером, который использует History API (wouter, preact-router, и т.д.)
|
|
27
|
+
*/
|
|
28
|
+
export declare function createBrowserHistoryAdapter(locales: Locale[], defaultLocale: string): I18nRoutingStrategy;
|
|
29
|
+
|
|
30
|
+
export declare function createI18n(options: PreactI18nOptions): PreactI18n;
|
|
31
|
+
|
|
32
|
+
export declare const createPreactRouterAdapter: typeof createBrowserHistoryAdapter;
|
|
33
|
+
|
|
34
|
+
export { defaultPlural }
|
|
35
|
+
|
|
36
|
+
export { FormatService }
|
|
37
|
+
|
|
38
|
+
export { Getter }
|
|
39
|
+
|
|
40
|
+
export declare const I18nContext: Context<PreactI18n | null>;
|
|
41
|
+
|
|
42
|
+
export declare const I18nDefaultLocaleContext: Context<string | null>;
|
|
43
|
+
|
|
44
|
+
export declare const I18nGroup: (props: I18nGroupProps) => JSX_2.Element;
|
|
45
|
+
|
|
46
|
+
export declare interface I18nGroupProps extends Omit<JSX_2.HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
47
|
+
prefix: string;
|
|
48
|
+
groupClass?: string;
|
|
49
|
+
children?: (props: {
|
|
50
|
+
prefix: string;
|
|
51
|
+
t: (key: string, params?: Record<string, string | number | boolean>) => string;
|
|
52
|
+
}) => ComponentChildren;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export declare const I18nLink: (props: I18nLinkProps) => JSX_2.Element;
|
|
56
|
+
|
|
57
|
+
export declare interface I18nLinkProps extends JSX_2.AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
58
|
+
to: string | {
|
|
59
|
+
path?: string;
|
|
60
|
+
};
|
|
61
|
+
activeStyle?: Record<string, string | number>;
|
|
62
|
+
localeRoute?: (to: string | {
|
|
63
|
+
path?: string;
|
|
64
|
+
}, locale?: string) => string | {
|
|
65
|
+
path?: string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export declare const I18nLocalesContext: Context<Locale[] | null>;
|
|
70
|
+
|
|
71
|
+
export declare function I18nProvider({ i18n, locales, defaultLocale, routingStrategy, children }: I18nProviderProps): VNode<Attributes & {
|
|
72
|
+
value: PreactI18n | null;
|
|
73
|
+
children?: ComponentChildren;
|
|
74
|
+
}>;
|
|
75
|
+
|
|
76
|
+
export declare interface I18nProviderProps {
|
|
77
|
+
i18n: PreactI18n;
|
|
78
|
+
locales?: Locale[];
|
|
79
|
+
defaultLocale?: string;
|
|
80
|
+
routingStrategy?: I18nRoutingStrategy;
|
|
81
|
+
children?: ComponentChildren;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export declare const I18nRouterContext: Context<I18nRoutingStrategy | null>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Routing strategy interface for i18n
|
|
88
|
+
* Implement this interface to integrate with any router library
|
|
89
|
+
* Matches Vue/Solid package interface for consistency
|
|
90
|
+
*/
|
|
91
|
+
export declare interface I18nRoutingStrategy {
|
|
92
|
+
/**
|
|
93
|
+
* Returns current path (without locale prefix if needed, or full path)
|
|
94
|
+
* Used for determining active classes in links
|
|
95
|
+
*/
|
|
96
|
+
getCurrentPath: () => string;
|
|
97
|
+
/**
|
|
98
|
+
* Component to use for rendering links (e.g., RouterLink)
|
|
99
|
+
*/
|
|
100
|
+
linkComponent?: string | default_2.ComponentType<{
|
|
101
|
+
href: string;
|
|
102
|
+
children?: default_2.ReactNode;
|
|
103
|
+
style?: default_2.CSSProperties;
|
|
104
|
+
className?: string;
|
|
105
|
+
[key: string]: unknown;
|
|
106
|
+
}>;
|
|
107
|
+
/**
|
|
108
|
+
* Function to navigate to another route/locale
|
|
109
|
+
*/
|
|
110
|
+
push: (target: {
|
|
111
|
+
path: string;
|
|
112
|
+
}) => void;
|
|
113
|
+
/**
|
|
114
|
+
* Function to replace current route
|
|
115
|
+
*/
|
|
116
|
+
replace: (target: {
|
|
117
|
+
path: string;
|
|
118
|
+
}) => void;
|
|
119
|
+
/**
|
|
120
|
+
* Generate path for specific locale
|
|
121
|
+
*/
|
|
122
|
+
resolvePath?: (to: string | {
|
|
123
|
+
path?: string;
|
|
124
|
+
}, locale: string) => string | {
|
|
125
|
+
path?: string;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* (Optional) Get current route object for SEO/Meta tags
|
|
129
|
+
*/
|
|
130
|
+
getRoute?: () => {
|
|
131
|
+
fullPath: string;
|
|
132
|
+
query: Record<string, unknown>;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export declare const I18nSwitcher: (props: I18nSwitcherProps) => JSX_2.Element;
|
|
137
|
+
|
|
138
|
+
export declare interface I18nSwitcherProps extends JSX_2.HTMLAttributes<HTMLDivElement> {
|
|
139
|
+
locales?: Locale[];
|
|
140
|
+
currentLocale?: string | (() => string);
|
|
141
|
+
getLocaleName?: () => string | null;
|
|
142
|
+
switchLocale?: (locale: string) => void;
|
|
143
|
+
localeRoute?: (to: string | {
|
|
144
|
+
path?: string;
|
|
145
|
+
}, locale?: string) => string | {
|
|
146
|
+
path?: string;
|
|
147
|
+
};
|
|
148
|
+
customLabels?: Record<string, string>;
|
|
149
|
+
customWrapperStyle?: Record<string, string | number>;
|
|
150
|
+
customButtonStyle?: Record<string, string | number>;
|
|
151
|
+
customDropdownStyle?: Record<string, string | number>;
|
|
152
|
+
customItemStyle?: Record<string, string | number>;
|
|
153
|
+
customLinkStyle?: Record<string, string | number>;
|
|
154
|
+
customActiveLinkStyle?: Record<string, string | number>;
|
|
155
|
+
customIconStyle?: Record<string, string | number>;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export declare const I18nT: (props: I18nTProps) => JSX_2.Element | null;
|
|
159
|
+
|
|
160
|
+
export declare interface I18nTProps extends Omit<JSX_2.HTMLAttributes<HTMLElement>, 'children'> {
|
|
161
|
+
keypath: TranslationKey;
|
|
162
|
+
params?: Record<string, string | number | boolean>;
|
|
163
|
+
tag?: keyof JSX_2.IntrinsicElements;
|
|
164
|
+
plural?: number | string;
|
|
165
|
+
defaultValue?: string;
|
|
166
|
+
html?: boolean;
|
|
167
|
+
hideIfEmpty?: boolean;
|
|
168
|
+
customPluralRule?: PluralFunc;
|
|
169
|
+
number?: number | string;
|
|
170
|
+
date?: Date | string | number;
|
|
171
|
+
relativeDate?: Date | string | number;
|
|
172
|
+
children?: never;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { interpolate }
|
|
176
|
+
|
|
177
|
+
export { Locale }
|
|
178
|
+
|
|
179
|
+
export { LocaleCode }
|
|
180
|
+
|
|
181
|
+
export { ModuleOptions }
|
|
182
|
+
|
|
183
|
+
export { Params }
|
|
184
|
+
|
|
185
|
+
export { PluralFunc }
|
|
186
|
+
|
|
187
|
+
export declare class PreactI18n extends BaseI18n {
|
|
188
|
+
private _locale;
|
|
189
|
+
private _fallbackLocale;
|
|
190
|
+
private _currentRoute;
|
|
191
|
+
private listeners;
|
|
192
|
+
private revision;
|
|
193
|
+
readonly storage: TranslationStorage;
|
|
194
|
+
constructor(options: PreactI18nOptions);
|
|
195
|
+
subscribe: (listener: () => void) => () => boolean;
|
|
196
|
+
getSnapshot: () => string;
|
|
197
|
+
private notify;
|
|
198
|
+
get locale(): string;
|
|
199
|
+
set locale(val: string);
|
|
200
|
+
get fallbackLocale(): string;
|
|
201
|
+
set fallbackLocale(val: string);
|
|
202
|
+
get currentRoute(): string;
|
|
203
|
+
setRoute(routeName: string): void;
|
|
204
|
+
getLocale(): string;
|
|
205
|
+
getFallbackLocale(): string;
|
|
206
|
+
getRoute(): string;
|
|
207
|
+
addTranslations(locale: string, translations: Translations, merge?: boolean): void;
|
|
208
|
+
addRouteTranslations(locale: string, routeName: string, translations: Translations, merge?: boolean): void;
|
|
209
|
+
clearCache(): void;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export declare interface PreactI18nOptions {
|
|
213
|
+
locale: string;
|
|
214
|
+
fallbackLocale?: string;
|
|
215
|
+
messages?: Record<string, Translations>;
|
|
216
|
+
plural?: PluralFunc;
|
|
217
|
+
missingWarn?: boolean;
|
|
218
|
+
missingHandler?: (locale: string, key: string, routeName: string) => void;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export { TranslationKey }
|
|
222
|
+
|
|
223
|
+
export { Translations }
|
|
224
|
+
|
|
225
|
+
export declare const useI18n: (options?: UseI18nOptions) => UseI18nReturn;
|
|
226
|
+
|
|
227
|
+
export declare const useI18nContext: () => PreactI18n;
|
|
228
|
+
|
|
229
|
+
export declare const useI18nDefaultLocale: () => string | null;
|
|
230
|
+
|
|
231
|
+
export declare const useI18nLocales: () => Locale[] | null;
|
|
232
|
+
|
|
233
|
+
export declare interface UseI18nOptions {
|
|
234
|
+
locales?: Locale[];
|
|
235
|
+
defaultLocale?: string;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export declare interface UseI18nReturn {
|
|
239
|
+
t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation;
|
|
240
|
+
ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeName?: string) => string;
|
|
241
|
+
tc: (key: TranslationKey, count: number | Params, defaultValue?: string) => string;
|
|
242
|
+
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
243
|
+
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
244
|
+
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
245
|
+
has: (key: TranslationKey, routeName?: string) => boolean;
|
|
246
|
+
locale: string;
|
|
247
|
+
fallbackLocale: string;
|
|
248
|
+
currentRoute: string;
|
|
249
|
+
setLocale: (locale: string) => void;
|
|
250
|
+
setRoute: (routeName: string) => void;
|
|
251
|
+
getRoute: () => string;
|
|
252
|
+
getLocales: () => Locale[];
|
|
253
|
+
defaultLocale: () => string;
|
|
254
|
+
getLocaleName: () => string | null;
|
|
255
|
+
switchLocale?: (locale: string) => void;
|
|
256
|
+
localeRoute?: (to: string | {
|
|
257
|
+
path?: string;
|
|
258
|
+
}, locale?: string) => string | {
|
|
259
|
+
path?: string;
|
|
260
|
+
};
|
|
261
|
+
localePath?: (to: string | {
|
|
262
|
+
path?: string;
|
|
263
|
+
}, locale?: string) => string;
|
|
264
|
+
addTranslations: (locale: string, translations: Translations, merge?: boolean) => void;
|
|
265
|
+
addRouteTranslations: (locale: string, routeName: string, translations: Translations, merge?: boolean) => void;
|
|
266
|
+
clearCache: () => void;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export declare const useI18nRouter: () => I18nRoutingStrategy | null;
|
|
270
|
+
|
|
271
|
+
export { }
|
package/package.json
CHANGED
|
@@ -1,26 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/preact",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"description": "Preact bindings for i18n-micro — hooks, context, and UI components.",
|
|
4
5
|
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/s00d/nuxt-i18n-micro.git",
|
|
11
|
+
"directory": "packages/preact"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/s00d/nuxt-i18n-micro/tree/main/packages/preact#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/s00d/nuxt-i18n-micro/issues"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
5
20
|
"main": "./dist/index.cjs",
|
|
6
|
-
"module": "./dist/index.mjs",
|
|
7
21
|
"types": "./dist/index.d.ts",
|
|
8
22
|
"exports": {
|
|
9
23
|
".": {
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.mjs"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./dist/index.d.cts",
|
|
30
|
+
"default": "./dist/index.cjs"
|
|
31
|
+
},
|
|
32
|
+
"default": "./dist/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
14
35
|
},
|
|
15
36
|
"files": [
|
|
16
|
-
"dist"
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE"
|
|
17
40
|
],
|
|
18
41
|
"publishConfig": {
|
|
19
42
|
"access": "public"
|
|
20
43
|
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"preact",
|
|
46
|
+
"i18n",
|
|
47
|
+
"internationalization",
|
|
48
|
+
"translations"
|
|
49
|
+
],
|
|
21
50
|
"dependencies": {
|
|
22
|
-
"@i18n-micro/
|
|
23
|
-
"@i18n-micro/
|
|
51
|
+
"@i18n-micro/types": "1.2.2",
|
|
52
|
+
"@i18n-micro/core": "1.3.1"
|
|
24
53
|
},
|
|
25
54
|
"peerDependencies": {
|
|
26
55
|
"preact": "^10.0.0"
|
|
@@ -35,12 +64,14 @@
|
|
|
35
64
|
"jest": "^29.7.0",
|
|
36
65
|
"jest-environment-jsdom": "^29.7.0",
|
|
37
66
|
"preact": "^10.0.0",
|
|
67
|
+
"publint": "^0.3.17",
|
|
38
68
|
"ts-jest": "^29.4.6",
|
|
39
69
|
"vite": "^7.3.1",
|
|
40
70
|
"vite-plugin-dts": "^4.5.4"
|
|
41
71
|
},
|
|
42
72
|
"scripts": {
|
|
43
73
|
"build": "vite build",
|
|
74
|
+
"check:package": "publint",
|
|
44
75
|
"dev": "cd playground && vite",
|
|
45
76
|
"test": "jest",
|
|
46
77
|
"typecheck": "tsc --noEmit"
|