@i18n-micro/solid 1.2.0 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,324 @@
1
+ import { Accessor } from 'solid-js';
2
+ import { BaseI18n } from '@i18n-micro/core';
3
+ import { CleanTranslation } from '@i18n-micro/types';
4
+ import { Component } from 'solid-js';
5
+ import { Context } from 'solid-js';
6
+ import { defaultPlural } from '@i18n-micro/core';
7
+ import { FormatService } from '@i18n-micro/core';
8
+ import { Getter } from '@i18n-micro/types';
9
+ import { interpolate } from '@i18n-micro/core';
10
+ import { JSX } from 'solid-js';
11
+ import { Locale } from '@i18n-micro/types';
12
+ import { LocaleCode } from '@i18n-micro/types';
13
+ import { Location as Location_2 } from '@solidjs/router';
14
+ import { ModuleOptions } from '@i18n-micro/types';
15
+ import { Params } from '@i18n-micro/types';
16
+ import { ParentComponent } from 'solid-js';
17
+ import { PluralFunc } from '@i18n-micro/types';
18
+ import { TranslationKey } from '@i18n-micro/types';
19
+ import { Translations } from '@i18n-micro/types';
20
+ import { TranslationStorage } from '@i18n-micro/core';
21
+ import { useNavigate } from '@solidjs/router';
22
+
23
+ export { CleanTranslation }
24
+
25
+ export declare function createI18n(options: SolidI18nOptions): SolidI18n;
26
+
27
+ /**
28
+ * Factory for Solid Router adapter
29
+ * Implements routing utilities for Solid Router
30
+ * Uses @solidjs/router APIs for navigation and path resolution
31
+ *
32
+ * **IMPORTANT**: This function must be called inside a SolidJS component or reactive context
33
+ * (e.g., inside a component function, not at module level). This is required because
34
+ * `createSignal` and `createEffect` need to be within a reactive owner context.
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * const RouterRoot: Component = () => {
39
+ * const navigate = useNavigate()
40
+ * const location = useLocation()
41
+ * const routingStrategy = createSolidRouterAdapter(
42
+ * locales,
43
+ * defaultLocale,
44
+ * navigate,
45
+ * location,
46
+ * )
47
+ * // ...
48
+ * }
49
+ * ```
50
+ *
51
+ * @param locales - Array of locale configurations
52
+ * @param defaultLocale - Default locale code
53
+ * @param navigate - Navigation function from @solidjs/router's useNavigate hook
54
+ * @param location - Location object from @solidjs/router's useLocation hook
55
+ * @returns I18nRoutingStrategy with reactive pathname accessor
56
+ */
57
+ export declare function createSolidRouterAdapter(locales: Locale[], defaultLocale: string, navigate: NavigateFunction, location: Location_2): I18nRoutingStrategy & {
58
+ getCurrentPathAccessor: Accessor<string>;
59
+ };
60
+
61
+ export { defaultPlural }
62
+
63
+ export { FormatService }
64
+
65
+ export { Getter }
66
+
67
+ export declare const I18nContext: Context<SolidI18n | undefined>;
68
+
69
+ export declare const I18nDefaultLocaleContext: Context<string | undefined>;
70
+
71
+ export declare const I18nGroup: Component<I18nGroupProps>;
72
+
73
+ declare interface I18nGroupProps extends JSX.HTMLAttributes<HTMLDivElement> {
74
+ prefix: string;
75
+ groupClass?: string;
76
+ }
77
+
78
+ export declare const I18nLink: Component<I18nLinkProps>;
79
+
80
+ declare interface I18nLinkProps extends JSX.AnchorHTMLAttributes<HTMLAnchorElement> {
81
+ to: string | {
82
+ path?: string;
83
+ };
84
+ localeRoute?: (to: string | {
85
+ path?: string;
86
+ }, locale?: string) => string | {
87
+ path?: string;
88
+ };
89
+ activeStyle?: JSX.CSSProperties;
90
+ }
91
+
92
+ export declare const I18nLocalesContext: Context<Locale[] | undefined>;
93
+
94
+ export declare const I18nProvider: ParentComponent<I18nProviderProps>;
95
+
96
+ export declare interface I18nProviderProps {
97
+ i18n: SolidI18n;
98
+ locales?: Locale[];
99
+ defaultLocale?: string;
100
+ routingStrategy?: I18nRoutingStrategy;
101
+ }
102
+
103
+ export declare const I18nRouterContext: Context<I18nRoutingStrategy | undefined>;
104
+
105
+ /**
106
+ * Routing strategy interface for i18n
107
+ * Implement this interface to integrate with any router library
108
+ * Matches Vue package interface for consistency
109
+ */
110
+ export declare interface I18nRoutingStrategy {
111
+ /**
112
+ * Returns current path (without locale prefix if needed, or full path)
113
+ * Used for determining active classes in links
114
+ * Note: For SolidJS, this should return the current value synchronously.
115
+ * For reactive updates, use `getCurrentPathAccessor` instead.
116
+ */
117
+ getCurrentPath: () => string;
118
+ /**
119
+ * (SolidJS-specific, highly recommended) Returns reactive accessor for current path
120
+ * This is REQUIRED for proper reactivity in SolidJS components.
121
+ * Without this, active link states and path-dependent UI won't update reactively.
122
+ *
123
+ * @example
124
+ * ```tsx
125
+ * const pathnameAccessor = router.getCurrentPathAccessor?.()
126
+ * // Use inside createMemo for reactivity:
127
+ * const currentPath = createMemo(() => pathnameAccessor?.() ?? router.getCurrentPath())
128
+ * ```
129
+ */
130
+ getCurrentPathAccessor?: () => Accessor<string>;
131
+ /**
132
+ * Component to use for rendering links (e.g., RouterLink)
133
+ */
134
+ linkComponent?: string | Component<{
135
+ href: string;
136
+ children?: JSX.Element;
137
+ style?: JSX.CSSProperties;
138
+ class?: string;
139
+ [key: string]: unknown;
140
+ }>;
141
+ /**
142
+ * Function to navigate to another route/locale
143
+ */
144
+ push: (target: {
145
+ path: string;
146
+ }) => void;
147
+ /**
148
+ * Function to replace current route
149
+ */
150
+ replace: (target: {
151
+ path: string;
152
+ }) => void;
153
+ /**
154
+ * Generate path for specific locale
155
+ */
156
+ resolvePath?: (to: string | {
157
+ path?: string;
158
+ }, locale: string) => string | {
159
+ path?: string;
160
+ };
161
+ /**
162
+ * (Optional) Get current route object for SEO/Meta tags
163
+ */
164
+ getRoute?: () => {
165
+ fullPath: string;
166
+ query: Record<string, unknown>;
167
+ };
168
+ }
169
+
170
+ export declare const I18nSwitcher: Component<I18nSwitcherProps>;
171
+
172
+ declare interface I18nSwitcherProps extends JSX.HTMLAttributes<HTMLDivElement> {
173
+ locales?: Locale[];
174
+ currentLocale?: string | (() => string);
175
+ getLocaleName?: () => string | null;
176
+ switchLocale?: (locale: string) => void;
177
+ localeRoute?: (to: string | {
178
+ path?: string;
179
+ }, locale?: string) => string | {
180
+ path?: string;
181
+ };
182
+ customLabels?: Record<string, string>;
183
+ customWrapperStyle?: JSX.CSSProperties;
184
+ customButtonStyle?: JSX.CSSProperties;
185
+ customDropdownStyle?: JSX.CSSProperties;
186
+ customItemStyle?: JSX.CSSProperties;
187
+ customLinkStyle?: JSX.CSSProperties;
188
+ customActiveLinkStyle?: JSX.CSSProperties;
189
+ /**
190
+ * Inline style applied to the main switcher button when the current locale is
191
+ * marked as `disabled: true` in locale config.
192
+ *
193
+ * Disabled locales are omitted from dropdown items.
194
+ */
195
+ customDisabledLinkStyle?: JSX.CSSProperties;
196
+ customIconStyle?: JSX.CSSProperties;
197
+ }
198
+
199
+ export declare const I18nT: Component<I18nTProps>;
200
+
201
+ declare interface I18nTProps extends JSX.HTMLAttributes<HTMLElement> {
202
+ keypath: TranslationKey;
203
+ params?: Record<string, string | number | boolean>;
204
+ tag?: string;
205
+ plural?: number | string;
206
+ defaultValue?: string;
207
+ html?: boolean;
208
+ hideIfEmpty?: boolean;
209
+ customPluralRule?: PluralFunc;
210
+ number?: number | string;
211
+ date?: Date | string | number;
212
+ relativeDate?: Date | string | number;
213
+ }
214
+
215
+ export { interpolate }
216
+
217
+ export { Locale }
218
+
219
+ export { LocaleCode }
220
+
221
+ export { ModuleOptions }
222
+
223
+ declare type NavigateFunction = ReturnType<typeof useNavigate>;
224
+
225
+ export { Params }
226
+
227
+ export { PluralFunc }
228
+
229
+ export declare class SolidI18n extends BaseI18n {
230
+ private readonly store;
231
+ private readonly _localeSignal;
232
+ private readonly _setLocaleSignal;
233
+ private readonly _routeSignal;
234
+ private readonly _setRouteSignal;
235
+ private readonly _fallbackSignal;
236
+ readonly storage: TranslationStorage;
237
+ constructor(options: SolidI18nOptions);
238
+ getLocale(): string;
239
+ getFallbackLocale(): string;
240
+ getRoute(): string;
241
+ set locale(val: string);
242
+ get locale(): string;
243
+ get localeAccessor(): Accessor<string>;
244
+ get fallbackLocale(): string;
245
+ get currentRoute(): string;
246
+ get routeAccessor(): Accessor<string>;
247
+ setRoute(val: string): void;
248
+ addTranslations(locale: string, translations: Translations, merge?: boolean): void;
249
+ addRouteTranslations(locale: string, routeName: string, translations: Translations, merge?: boolean): void;
250
+ clearCache(): void;
251
+ protected onTranslationsChanged(): void;
252
+ private listeners;
253
+ subscribe(cb: () => void): () => void;
254
+ getSnapshot(): string;
255
+ private notifyListeners;
256
+ }
257
+
258
+ export declare interface SolidI18nOptions {
259
+ locale: string;
260
+ fallbackLocale?: string;
261
+ messages?: Record<string, Translations>;
262
+ plural?: PluralFunc;
263
+ missingWarn?: boolean;
264
+ missingHandler?: (locale: string, key: string, routeName: string) => void;
265
+ }
266
+
267
+ export { TranslationKey }
268
+
269
+ export { Translations }
270
+
271
+ export declare function useI18n(options?: UseI18nOptions): {
272
+ instance: SolidI18n;
273
+ locale: Accessor<string>;
274
+ getLocales: () => Locale[];
275
+ defaultLocale: () => string;
276
+ getLocaleName: () => string | null;
277
+ localeRoute: (to: string | {
278
+ path?: string;
279
+ }, localeCode?: string) => string | {
280
+ path?: string;
281
+ };
282
+ localePath: (to: string | {
283
+ path?: string;
284
+ }, locale?: string) => string;
285
+ switchLocale: (newLocale: string) => void;
286
+ t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeContext?: unknown) => CleanTranslation;
287
+ ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeContext?: unknown) => string;
288
+ tc: (key: TranslationKey, count: number | Params, defaultValue?: string) => string;
289
+ tn: {
290
+ (value: number, options?: Intl.NumberFormatOptions): string;
291
+ (value: number, key: string, overrides?: Intl.NumberFormatOptions): string;
292
+ (value: number, key: string, locale: string, overrides?: Intl.NumberFormatOptions): string;
293
+ };
294
+ td: {
295
+ (value: Date | number | string, options?: Intl.DateTimeFormatOptions): string;
296
+ (value: Date | number | string, key: string, overrides?: Intl.DateTimeFormatOptions): string;
297
+ (value: Date | number | string, key: string, locale: string, overrides?: Intl.DateTimeFormatOptions): string;
298
+ };
299
+ tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
300
+ has: (key: TranslationKey, routeContext?: unknown) => boolean;
301
+ setRoute: (val: string) => void;
302
+ getRoute: () => string;
303
+ getLocale: () => string;
304
+ addTranslations: (locale: string, translations: Translations, merge?: boolean) => void;
305
+ addRouteTranslations: (locale: string, routeName: string, translations: Translations, merge?: boolean) => void;
306
+ resolveTranslations: (routeContext?: unknown) => Translations;
307
+ setTranslation: (key: TranslationKey, value: unknown) => void;
308
+ clearCache: () => void;
309
+ };
310
+
311
+ export declare const useI18nContext: () => SolidI18n;
312
+
313
+ export declare const useI18nDefaultLocale: () => string;
314
+
315
+ export declare const useI18nLocales: () => Locale[];
316
+
317
+ export declare interface UseI18nOptions {
318
+ locales?: Locale[];
319
+ defaultLocale?: string;
320
+ }
321
+
322
+ export declare const useI18nRouter: () => I18nRoutingStrategy | undefined;
323
+
324
+ export { }
package/dist/index.d.ts CHANGED
@@ -186,6 +186,12 @@ declare interface I18nSwitcherProps extends JSX.HTMLAttributes<HTMLDivElement> {
186
186
  customItemStyle?: JSX.CSSProperties;
187
187
  customLinkStyle?: JSX.CSSProperties;
188
188
  customActiveLinkStyle?: JSX.CSSProperties;
189
+ /**
190
+ * Inline style applied to the main switcher button when the current locale is
191
+ * marked as `disabled: true` in locale config.
192
+ *
193
+ * Disabled locales are omitted from dropdown items.
194
+ */
189
195
  customDisabledLinkStyle?: JSX.CSSProperties;
190
196
  customIconStyle?: JSX.CSSProperties;
191
197
  }
@@ -221,13 +227,13 @@ export { Params }
221
227
  export { PluralFunc }
222
228
 
223
229
  export declare class SolidI18n extends BaseI18n {
224
- private _locale;
225
- private _setLocale;
226
- private _fallbackLocale;
227
- private _currentRoute;
228
- private _setRoute;
230
+ private readonly store;
231
+ private readonly _localeSignal;
232
+ private readonly _setLocaleSignal;
233
+ private readonly _routeSignal;
234
+ private readonly _setRouteSignal;
235
+ private readonly _fallbackSignal;
229
236
  readonly storage: TranslationStorage;
230
- private listeners;
231
237
  constructor(options: SolidI18nOptions);
232
238
  getLocale(): string;
233
239
  getFallbackLocale(): string;
@@ -242,7 +248,10 @@ export declare class SolidI18n extends BaseI18n {
242
248
  addTranslations(locale: string, translations: Translations, merge?: boolean): void;
243
249
  addRouteTranslations(locale: string, routeName: string, translations: Translations, merge?: boolean): void;
244
250
  clearCache(): void;
251
+ protected onTranslationsChanged(): void;
252
+ private listeners;
245
253
  subscribe(cb: () => void): () => void;
254
+ getSnapshot(): string;
246
255
  private notifyListeners;
247
256
  }
248
257
 
@@ -274,18 +283,28 @@ export declare function useI18n(options?: UseI18nOptions): {
274
283
  path?: string;
275
284
  }, locale?: string) => string;
276
285
  switchLocale: (newLocale: string) => void;
277
- t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation;
278
- ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeName?: string) => string;
286
+ t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeContext?: unknown) => CleanTranslation;
287
+ ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeContext?: unknown) => string;
279
288
  tc: (key: TranslationKey, count: number | Params, defaultValue?: string) => string;
280
- tn: (value: number, options?: Intl.NumberFormatOptions) => string;
281
- td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
289
+ tn: {
290
+ (value: number, options?: Intl.NumberFormatOptions): string;
291
+ (value: number, key: string, overrides?: Intl.NumberFormatOptions): string;
292
+ (value: number, key: string, locale: string, overrides?: Intl.NumberFormatOptions): string;
293
+ };
294
+ td: {
295
+ (value: Date | number | string, options?: Intl.DateTimeFormatOptions): string;
296
+ (value: Date | number | string, key: string, overrides?: Intl.DateTimeFormatOptions): string;
297
+ (value: Date | number | string, key: string, locale: string, overrides?: Intl.DateTimeFormatOptions): string;
298
+ };
282
299
  tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
283
- has: (key: TranslationKey, routeName?: string) => boolean;
300
+ has: (key: TranslationKey, routeContext?: unknown) => boolean;
284
301
  setRoute: (val: string) => void;
285
302
  getRoute: () => string;
286
303
  getLocale: () => string;
287
304
  addTranslations: (locale: string, translations: Translations, merge?: boolean) => void;
288
305
  addRouteTranslations: (locale: string, routeName: string, translations: Translations, merge?: boolean) => void;
306
+ resolveTranslations: (routeContext?: unknown) => Translations;
307
+ setTranslation: (key: TranslationKey, value: unknown) => void;
289
308
  clearCache: () => void;
290
309
  };
291
310