@i18n-micro/solid 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.
@@ -0,0 +1,305 @@
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
+ customDisabledLinkStyle?: JSX.CSSProperties;
190
+ customIconStyle?: JSX.CSSProperties;
191
+ }
192
+
193
+ export declare const I18nT: Component<I18nTProps>;
194
+
195
+ declare interface I18nTProps extends JSX.HTMLAttributes<HTMLElement> {
196
+ keypath: TranslationKey;
197
+ params?: Record<string, string | number | boolean>;
198
+ tag?: string;
199
+ plural?: number | string;
200
+ defaultValue?: string;
201
+ html?: boolean;
202
+ hideIfEmpty?: boolean;
203
+ customPluralRule?: PluralFunc;
204
+ number?: number | string;
205
+ date?: Date | string | number;
206
+ relativeDate?: Date | string | number;
207
+ }
208
+
209
+ export { interpolate }
210
+
211
+ export { Locale }
212
+
213
+ export { LocaleCode }
214
+
215
+ export { ModuleOptions }
216
+
217
+ declare type NavigateFunction = ReturnType<typeof useNavigate>;
218
+
219
+ export { Params }
220
+
221
+ export { PluralFunc }
222
+
223
+ export declare class SolidI18n extends BaseI18n {
224
+ private _locale;
225
+ private _setLocale;
226
+ private _fallbackLocale;
227
+ private _currentRoute;
228
+ private _setRoute;
229
+ readonly storage: TranslationStorage;
230
+ private listeners;
231
+ constructor(options: SolidI18nOptions);
232
+ getLocale(): string;
233
+ getFallbackLocale(): string;
234
+ getRoute(): string;
235
+ set locale(val: string);
236
+ get locale(): string;
237
+ get localeAccessor(): Accessor<string>;
238
+ get fallbackLocale(): string;
239
+ get currentRoute(): string;
240
+ get routeAccessor(): Accessor<string>;
241
+ setRoute(val: string): void;
242
+ addTranslations(locale: string, translations: Translations, merge?: boolean): void;
243
+ addRouteTranslations(locale: string, routeName: string, translations: Translations, merge?: boolean): void;
244
+ clearCache(): void;
245
+ subscribe(cb: () => void): () => void;
246
+ private notifyListeners;
247
+ }
248
+
249
+ export declare interface SolidI18nOptions {
250
+ locale: string;
251
+ fallbackLocale?: string;
252
+ messages?: Record<string, Translations>;
253
+ plural?: PluralFunc;
254
+ missingWarn?: boolean;
255
+ missingHandler?: (locale: string, key: string, routeName: string) => void;
256
+ }
257
+
258
+ export { TranslationKey }
259
+
260
+ export { Translations }
261
+
262
+ export declare function useI18n(options?: UseI18nOptions): {
263
+ instance: SolidI18n;
264
+ locale: Accessor<string>;
265
+ getLocales: () => Locale[];
266
+ defaultLocale: () => string;
267
+ getLocaleName: () => string | null;
268
+ localeRoute: (to: string | {
269
+ path?: string;
270
+ }, localeCode?: string) => string | {
271
+ path?: string;
272
+ };
273
+ localePath: (to: string | {
274
+ path?: string;
275
+ }, locale?: string) => string;
276
+ 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;
279
+ 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;
282
+ tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
283
+ has: (key: TranslationKey, routeName?: string) => boolean;
284
+ setRoute: (val: string) => void;
285
+ getRoute: () => string;
286
+ getLocale: () => string;
287
+ addTranslations: (locale: string, translations: Translations, merge?: boolean) => void;
288
+ addRouteTranslations: (locale: string, routeName: string, translations: Translations, merge?: boolean) => void;
289
+ clearCache: () => void;
290
+ };
291
+
292
+ export declare const useI18nContext: () => SolidI18n;
293
+
294
+ export declare const useI18nDefaultLocale: () => string;
295
+
296
+ export declare const useI18nLocales: () => Locale[];
297
+
298
+ export declare interface UseI18nOptions {
299
+ locales?: Locale[];
300
+ defaultLocale?: string;
301
+ }
302
+
303
+ export declare const useI18nRouter: () => I18nRoutingStrategy | undefined;
304
+
305
+ export { }
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BaseI18n as dt } from "@i18n-micro/core";
2
2
  import { FormatService as Ot, defaultPlural as Wt, interpolate as Ht } from "@i18n-micro/core";
3
- import { spread as T, mergeProps as x, insert as S, memo as v, template as C, createComponent as k, delegateEvents as ft, use as ht, setAttribute as K, effect as W, style as I, className as pt, Dynamic as H } from "solid-js/web";
3
+ import { spread as T, mergeProps as x, insert as S, memo as v, template as C, createComponent as k, use as ft, setAttribute as K, effect as W, style as I, className as ht, delegateEvents as pt, Dynamic as H } from "solid-js/web";
4
4
  import { createContext as E, useContext as j, splitProps as V, createMemo as P, createSignal as A, onMount as gt, onCleanup as mt, createEffect as yt } from "solid-js";
5
5
  import { A as vt } from "@solidjs/router";
6
6
  const Q = E(), U = E(), X = E(), Y = E(), D = () => {
@@ -200,7 +200,7 @@ const Nt = (r) => {
200
200
  document.removeEventListener("click", Z);
201
201
  }), (() => {
202
202
  var u = xt(), m = u.firstChild, R = m.firstChild, w = R.nextSibling;
203
- return ht((d) => {
203
+ return ft((d) => {
204
204
  a = d;
205
205
  }, u), T(u, x({
206
206
  get style() {
@@ -231,7 +231,7 @@ const Nt = (r) => {
231
231
  ...n.customLinkStyle,
232
232
  ...N ? n.customActiveLinkStyle : {}
233
233
  };
234
- return b.e = I(O, it, b.e), J !== b.t && pt($, b.t = J), b.a = I($, ut, b.a), b;
234
+ return b.e = I(O, it, b.e), J !== b.t && ht($, b.t = J), b.a = I($, ut, b.a), b;
235
235
  }, {
236
236
  e: void 0,
237
237
  t: void 0,
@@ -260,7 +260,7 @@ const Nt = (r) => {
260
260
  }), u;
261
261
  })();
262
262
  };
263
- ft(["click"]);
263
+ pt(["click"]);
264
264
  const Tt = (r) => {
265
265
  const t = D(), [e, o] = V(r, ["keypath", "params", "tag", "plural", "defaultValue", "html", "hideIfEmpty", "customPluralRule", "number", "date", "relativeDate"]), n = P(() => {
266
266
  const h = t.localeAccessor(), c = t.routeAccessor();
package/package.json CHANGED
@@ -1,23 +1,53 @@
1
1
  {
2
2
  "name": "@i18n-micro/solid",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
+ "description": "SolidJS bindings for i18n-micro — primitives, 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/solid"
12
+ },
13
+ "homepage": "https://github.com/s00d/nuxt-i18n-micro/tree/main/packages/solid#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
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.cjs"
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
+ "solid",
46
+ "solidjs",
47
+ "i18n",
48
+ "internationalization",
49
+ "translations"
50
+ ],
21
51
  "peerDependencies": {
22
52
  "solid-js": "^1.9.10",
23
53
  "@solidjs/router": "^0.15.4"
@@ -31,13 +61,14 @@
31
61
  }
32
62
  },
33
63
  "dependencies": {
34
- "@i18n-micro/core": "1.2.0",
35
- "@i18n-micro/types": "1.1.5"
64
+ "@i18n-micro/core": "1.3.1",
65
+ "@i18n-micro/types": "1.2.2"
36
66
  },
37
67
  "devDependencies": {
38
68
  "@types/jest": "^29.5.14",
39
69
  "jest": "^29.7.0",
40
70
  "jest-environment-jsdom": "^29.7.0",
71
+ "publint": "^0.3.17",
41
72
  "solid-js": "^1.9.10",
42
73
  "ts-jest": "^29.4.6",
43
74
  "vite": "^7.3.1",
@@ -46,6 +77,7 @@
46
77
  },
47
78
  "scripts": {
48
79
  "build": "vite build",
80
+ "check:package": "publint",
49
81
  "dev": "cd playground && vite",
50
82
  "test": "jest",
51
83
  "typecheck": "tsc --noEmit"