@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.
- package/README.md +5 -5
- package/dist/context.d.ts +15 -24
- package/dist/context.d.ts.map +1 -1
- package/dist/hooks/__useI18n.d.ts +2 -2
- package/dist/hooks/__useI18n.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +129 -167
- package/dist/index.js.map +1 -1
- package/dist/plural.d.ts +3 -3
- package/dist/plural.d.ts.map +1 -1
- package/dist/provider.d.ts +3 -3
- package/dist/provider.d.ts.map +1 -1
- package/dist/rich-dom.d.ts +0 -6
- package/dist/rich-dom.d.ts.map +1 -1
- package/dist/select.d.ts +3 -3
- package/dist/select.d.ts.map +1 -1
- package/dist/server.cjs +2 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.ts +33 -17
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +54 -0
- package/dist/server.js.map +1 -0
- package/dist/solid-runtime.d.ts.map +1 -1
- package/dist/trans.d.ts +3 -3
- package/dist/trans.d.ts.map +1 -1
- package/dist/types.d.ts +8 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/use-i18n.d.ts +4 -8
- package/dist/use-i18n.d.ts.map +1 -1
- package/dist/vite-plugin.cjs +2 -113
- package/dist/vite-plugin.cjs.map +1 -1
- package/dist/vite-plugin.js +14 -123
- package/dist/vite-plugin.js.map +1 -1
- package/llms-full.txt +186 -0
- package/llms-migration.txt +176 -0
- package/llms.txt +64 -0
- package/package.json +17 -5
- package/src/context.ts +56 -77
- package/src/hooks/__useI18n.ts +2 -2
- package/src/index.ts +6 -6
- package/src/plural.tsx +9 -38
- package/src/provider.tsx +5 -5
- package/src/rich-dom.tsx +25 -47
- package/src/select.tsx +11 -8
- package/src/server.ts +94 -49
- package/src/solid-runtime.ts +15 -134
- package/src/trans.tsx +7 -4
- package/src/types.ts +9 -8
- package/src/use-i18n.ts +5 -16
- 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
|
-
|
|
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
|
|
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
|
|
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>):
|
|
37
|
+
t(id: string | MessageDescriptor, values?: Record<string, unknown>): LocalizedString
|
|
37
38
|
/** Tagged template form: t`Hello ${name}` */
|
|
38
|
-
t(strings: TemplateStringsArray, ...exprs: unknown[]):
|
|
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):
|
|
45
|
+
d(value: Date | number, style?: string): LocalizedString
|
|
45
46
|
/** Format a number value for the current locale */
|
|
46
|
-
n(value: number, style?: 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>):
|
|
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 {
|
|
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
|
-
*
|
|
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():
|
|
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
|
|
28
|
-
'or the component to be inside an <I18nProvider>.',
|
|
17
|
+
'useI18n() must be used inside an <I18nProvider>.',
|
|
29
18
|
)
|
|
30
19
|
}
|
package/src/vite-plugin.ts
CHANGED
|
@@ -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
|
)
|