@fluenti/solid 0.2.1 → 0.3.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.
Files changed (53) hide show
  1. package/README.md +5 -5
  2. package/dist/context.d.ts +15 -24
  3. package/dist/context.d.ts.map +1 -1
  4. package/dist/hooks/__useI18n.d.ts +2 -2
  5. package/dist/hooks/__useI18n.d.ts.map +1 -1
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +6 -6
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +129 -167
  11. package/dist/index.js.map +1 -1
  12. package/dist/plural.d.ts +3 -3
  13. package/dist/plural.d.ts.map +1 -1
  14. package/dist/provider.d.ts +3 -3
  15. package/dist/provider.d.ts.map +1 -1
  16. package/dist/rich-dom.d.ts +0 -6
  17. package/dist/rich-dom.d.ts.map +1 -1
  18. package/dist/select.d.ts +3 -3
  19. package/dist/select.d.ts.map +1 -1
  20. package/dist/server.cjs +2 -0
  21. package/dist/server.cjs.map +1 -0
  22. package/dist/server.d.ts +33 -17
  23. package/dist/server.d.ts.map +1 -1
  24. package/dist/server.js +54 -0
  25. package/dist/server.js.map +1 -0
  26. package/dist/solid-runtime.d.ts.map +1 -1
  27. package/dist/trans.d.ts +3 -3
  28. package/dist/trans.d.ts.map +1 -1
  29. package/dist/types.d.ts +8 -8
  30. package/dist/types.d.ts.map +1 -1
  31. package/dist/use-i18n.d.ts +4 -8
  32. package/dist/use-i18n.d.ts.map +1 -1
  33. package/dist/vite-plugin.cjs +2 -113
  34. package/dist/vite-plugin.cjs.map +1 -1
  35. package/dist/vite-plugin.js +14 -123
  36. package/dist/vite-plugin.js.map +1 -1
  37. package/llms-full.txt +186 -0
  38. package/llms-migration.txt +176 -0
  39. package/llms.txt +64 -0
  40. package/package.json +17 -5
  41. package/src/context.ts +56 -77
  42. package/src/hooks/__useI18n.ts +2 -2
  43. package/src/index.ts +6 -6
  44. package/src/plural.tsx +9 -38
  45. package/src/provider.tsx +5 -5
  46. package/src/rich-dom.tsx +25 -47
  47. package/src/select.tsx +11 -8
  48. package/src/server.ts +94 -49
  49. package/src/solid-runtime.ts +15 -134
  50. package/src/trans.tsx +7 -4
  51. package/src/types.ts +9 -8
  52. package/src/use-i18n.ts +5 -16
  53. package/src/vite-plugin.ts +1 -1
package/src/types.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { Accessor } from 'solid-js'
2
2
  import type {
3
- FluentConfig,
3
+ FluentiCoreConfig,
4
4
  Locale,
5
+ LocalizedString,
5
6
  Messages,
6
7
  CompiledMessage,
7
8
  MessageDescriptor,
@@ -15,7 +16,7 @@ export type ChunkLoader = (
15
16
  ) => Promise<Record<string, CompiledMessage> | { default: Record<string, CompiledMessage> }>
16
17
 
17
18
  /** Extended config with lazy locale loading support */
18
- export interface I18nConfig extends FluentConfig {
19
+ export interface FluentiConfig extends FluentiCoreConfig {
19
20
  /** Async chunk loader for lazy locale loading */
20
21
  chunkLoader?: ChunkLoader
21
22
  /** Enable lazy locale loading through chunkLoader */
@@ -27,25 +28,25 @@ export interface I18nConfig extends FluentConfig {
27
28
  }
28
29
 
29
30
  /** Reactive i18n context holding locale signal and translation utilities */
30
- export interface I18nContext {
31
+ export interface FluentiContext {
31
32
  /** Reactive accessor for the current locale */
32
33
  locale(): Locale
33
34
  /** Set the active locale (async when lazy locale loading is enabled) */
34
35
  setLocale(locale: Locale): Promise<void>
35
36
  /** Translate a message by id with optional interpolation values */
36
- t(id: string | MessageDescriptor, values?: Record<string, unknown>): string
37
+ t(id: string | MessageDescriptor, values?: Record<string, unknown>): LocalizedString
37
38
  /** Tagged template form: t`Hello ${name}` */
38
- t(strings: TemplateStringsArray, ...exprs: unknown[]): string
39
+ t(strings: TemplateStringsArray, ...exprs: unknown[]): LocalizedString
39
40
  /** Merge additional messages into a locale catalog at runtime */
40
41
  loadMessages(locale: Locale, messages: Messages): void
41
42
  /** Return all locale codes that have loaded messages */
42
43
  getLocales(): Locale[]
43
44
  /** Format a date value for the current locale */
44
- d(value: Date | number, style?: string): string
45
+ d(value: Date | number, style?: string): LocalizedString
45
46
  /** Format a number value for the current locale */
46
- n(value: number, style?: string): string
47
+ n(value: number, style?: string): LocalizedString
47
48
  /** Format an ICU message string directly (no catalog lookup) */
48
- format(message: string, values?: Record<string, unknown>): string
49
+ format(message: string, values?: Record<string, unknown>): LocalizedString
49
50
  /** Whether a locale chunk is currently being loaded */
50
51
  isLoading: Accessor<boolean>
51
52
  /** Set of locales whose messages have been loaded */
package/src/use-i18n.ts CHANGED
@@ -1,30 +1,19 @@
1
1
  import { useContext } from 'solid-js'
2
2
  import { I18nCtx } from './provider'
3
- import { getGlobalI18nContext } from './context'
4
- import type { I18nContext } from './context'
3
+ import type { FluentiContext } from './context'
5
4
 
6
5
  /**
7
- * Access the i18n context.
6
+ * Access the i18n context from the nearest `<I18nProvider>`.
8
7
  *
9
- * Resolution order:
10
- * 1. Nearest `<I18nProvider>` in the component tree
11
- * 2. Module-level singleton created by `createI18n()`
12
- *
13
- * Throws if neither is available.
8
+ * Throws if no provider is found in the component tree.
14
9
  */
15
- export function useI18n(): I18nContext {
10
+ export function useI18n(): FluentiContext {
16
11
  const ctx = useContext(I18nCtx)
17
12
  if (ctx) {
18
13
  return ctx
19
14
  }
20
15
 
21
- const global = getGlobalI18nContext()
22
- if (global) {
23
- return global
24
- }
25
-
26
16
  throw new Error(
27
- 'useI18n requires either createI18n() to be called at startup, ' +
28
- 'or the component to be inside an <I18nProvider>.',
17
+ 'useI18n() must be used inside an <I18nProvider>.',
29
18
  )
30
19
  }
@@ -7,7 +7,7 @@ export type { FluentiPluginOptions as FluentiSolidOptions } from '@fluenti/vite-
7
7
 
8
8
  export default function fluentiSolid(options?: FluentiPluginOptions): Plugin[] {
9
9
  return createFluentiPlugins(
10
- { ...options, framework: 'solid' },
10
+ { ...(options?.config !== undefined ? { config: options.config } : {}), framework: 'solid' },
11
11
  [],
12
12
  solidRuntimeGenerator,
13
13
  )