@embedpdf/plugin-i18n 2.0.0-next.0
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/LICENSE +21 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +399 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/actions.d.ts +15 -0
- package/dist/lib/i18n-plugin.d.ts +28 -0
- package/dist/lib/index.d.ts +9 -0
- package/dist/lib/locales/en.d.ts +2 -0
- package/dist/lib/locales/es.d.ts +2 -0
- package/dist/lib/locales/index.d.ts +2 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/reducer.d.ts +5 -0
- package/dist/lib/types.d.ts +104 -0
- package/dist/preact/adapter.d.ts +5 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -0
- package/dist/preact/index.cjs.map +1 -0
- package/dist/preact/index.d.ts +1 -0
- package/dist/preact/index.js +70 -0
- package/dist/preact/index.js.map +1 -0
- package/dist/react/adapter.d.ts +2 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +69 -0
- package/dist/react/index.js.map +1 -0
- package/dist/shared/components/index.d.ts +1 -0
- package/dist/shared/components/translate.d.ts +35 -0
- package/dist/shared/hooks/index.d.ts +1 -0
- package/dist/shared/hooks/use-i18n.d.ts +43 -0
- package/dist/shared/index.d.ts +3 -0
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-preact/components/translate.d.ts +35 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-i18n.d.ts +43 -0
- package/dist/shared-preact/index.d.ts +3 -0
- package/dist/shared-react/components/index.d.ts +1 -0
- package/dist/shared-react/components/translate.d.ts +35 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-i18n.d.ts +43 -0
- package/dist/shared-react/index.d.ts +3 -0
- package/dist/svelte/components/Translate.svelte.d.ts +9 -0
- package/dist/svelte/components/index.d.ts +1 -0
- package/dist/svelte/hooks/index.d.ts +1 -0
- package/dist/svelte/hooks/use-i18n.svelte.d.ts +41 -0
- package/dist/svelte/index.cjs +2 -0
- package/dist/svelte/index.cjs.map +1 -0
- package/dist/svelte/index.d.ts +3 -0
- package/dist/svelte/index.js +90 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/vue/components/index.d.ts +1 -0
- package/dist/vue/components/translate.vue.d.ts +9 -0
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-i18n.d.ts +30 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +3 -0
- package/dist/vue/index.js +98 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { BasePluginConfig, EventHook } from '@embedpdf/core';
|
|
2
|
+
export type TranslationKey = string;
|
|
3
|
+
export type LocaleCode = string;
|
|
4
|
+
export type ParamResolver<TStore = any> = (context: {
|
|
5
|
+
state: TStore;
|
|
6
|
+
documentId?: string;
|
|
7
|
+
}) => Record<string, string | number>;
|
|
8
|
+
export interface TranslateOptions {
|
|
9
|
+
documentId?: string;
|
|
10
|
+
params?: Record<string, string | number>;
|
|
11
|
+
fallback?: string;
|
|
12
|
+
}
|
|
13
|
+
export type ScopedTranslateOptions = Omit<TranslateOptions, 'documentId'>;
|
|
14
|
+
export type ParamResolvers<TStore = any> = Record<TranslationKey, ParamResolver<TStore>>;
|
|
15
|
+
export interface TranslationDictionary {
|
|
16
|
+
[key: string]: string | TranslationDictionary;
|
|
17
|
+
}
|
|
18
|
+
export interface Locale {
|
|
19
|
+
code: LocaleCode;
|
|
20
|
+
name: string;
|
|
21
|
+
translations: TranslationDictionary;
|
|
22
|
+
}
|
|
23
|
+
export interface I18nPluginConfig extends BasePluginConfig {
|
|
24
|
+
defaultLocale: LocaleCode;
|
|
25
|
+
fallbackLocale?: LocaleCode;
|
|
26
|
+
locales: Locale[];
|
|
27
|
+
paramResolvers?: ParamResolvers;
|
|
28
|
+
}
|
|
29
|
+
export interface I18nState {
|
|
30
|
+
currentLocale: LocaleCode;
|
|
31
|
+
availableLocales: LocaleCode[];
|
|
32
|
+
}
|
|
33
|
+
export interface LocaleChangeEvent {
|
|
34
|
+
previousLocale: LocaleCode;
|
|
35
|
+
currentLocale: LocaleCode;
|
|
36
|
+
}
|
|
37
|
+
export interface TranslationParamsChangedData {
|
|
38
|
+
changedKeys: TranslationKey[];
|
|
39
|
+
}
|
|
40
|
+
export interface TranslationParamsChangedEvent {
|
|
41
|
+
documentId: string;
|
|
42
|
+
changedKeys: TranslationKey[];
|
|
43
|
+
}
|
|
44
|
+
export interface I18nScope {
|
|
45
|
+
/**
|
|
46
|
+
* Translate a key for this document
|
|
47
|
+
* @param key - Translation key
|
|
48
|
+
* @param options - Optional translation options (params, fallback)
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const scoped = i18n.forDocument(documentId);
|
|
52
|
+
* scoped.t('page.title')
|
|
53
|
+
* scoped.t('page.count', { params: { count: 5 } })
|
|
54
|
+
* scoped.t('unknown.key', { fallback: 'Default Text' })
|
|
55
|
+
*/
|
|
56
|
+
t(key: TranslationKey, options?: ScopedTranslateOptions): string;
|
|
57
|
+
/**
|
|
58
|
+
* Event when translation params change for this document
|
|
59
|
+
*/
|
|
60
|
+
onParamsChanged: EventHook<TranslationParamsChangedData>;
|
|
61
|
+
}
|
|
62
|
+
export interface I18nCapability {
|
|
63
|
+
/**
|
|
64
|
+
* Translate a key with optional context
|
|
65
|
+
* If a param resolver is registered for this key, it will be called automatically
|
|
66
|
+
*
|
|
67
|
+
* @param key - Translation key
|
|
68
|
+
* @param options - Optional translation options (documentId, params)
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* // Simple global translation
|
|
72
|
+
* i18n.t('loading.viewer')
|
|
73
|
+
*
|
|
74
|
+
* // Global translation with params
|
|
75
|
+
* i18n.t('document.total', { params: { amount: 5 } })
|
|
76
|
+
*
|
|
77
|
+
* // Document-scoped with param resolver
|
|
78
|
+
* i18n.t('page.current', { documentId })
|
|
79
|
+
*
|
|
80
|
+
* // Document-scoped with explicit params
|
|
81
|
+
* i18n.t('welcome', { documentId, params: { name: 'User' } })
|
|
82
|
+
*/
|
|
83
|
+
t(key: TranslationKey, options?: TranslateOptions): string;
|
|
84
|
+
/**
|
|
85
|
+
* Get document-scoped API
|
|
86
|
+
*/
|
|
87
|
+
forDocument(documentId: string): I18nScope;
|
|
88
|
+
/**
|
|
89
|
+
* Register a param resolver dynamically
|
|
90
|
+
*/
|
|
91
|
+
registerParamResolver(key: TranslationKey, resolver: ParamResolver): void;
|
|
92
|
+
/**
|
|
93
|
+
* Unregister a param resolver
|
|
94
|
+
*/
|
|
95
|
+
unregisterParamResolver(key: TranslationKey): void;
|
|
96
|
+
setLocale(locale: LocaleCode): void;
|
|
97
|
+
getLocale(): LocaleCode;
|
|
98
|
+
getAvailableLocales(): LocaleCode[];
|
|
99
|
+
getLocaleInfo(code: LocaleCode): Locale | null;
|
|
100
|
+
registerLocale(locale: Locale): void;
|
|
101
|
+
hasLocale(code: LocaleCode): boolean;
|
|
102
|
+
onLocaleChange: EventHook<LocaleChangeEvent>;
|
|
103
|
+
onParamsChanged: EventHook<TranslationParamsChangedEvent>;
|
|
104
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Fragment } from 'preact';
|
|
2
|
+
export { useEffect, useRef, useState, useCallback, useMemo, useReducer } from 'preact/hooks';
|
|
3
|
+
export type { ComponentChildren as ReactNode } from 'preact';
|
|
4
|
+
export type CSSProperties = import('preact').JSX.CSSProperties;
|
|
5
|
+
export type HTMLAttributes<T = any> = import('preact').JSX.HTMLAttributes<T extends EventTarget ? T : never>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@embedpdf/core/preact';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),r=require("@embedpdf/plugin-i18n");require("preact");const t=require("preact/hooks"),a=()=>e.useCapability(r.I18nPlugin.id),n=e=>{const{provides:r}=a(),[,n]=t.useReducer(e=>e+1,0),o=t.useCallback((t,a)=>r?r.t(t,{documentId:e,params:null==a?void 0:a.params,fallback:null==a?void 0:a.fallback}):(null==a?void 0:a.fallback)??t,[r,e]);return t.useEffect(()=>{if(!r)return;const t=r.onLocaleChange(()=>{n()}),a=e?r.forDocument(e).onParamsChanged(()=>{n()}):r.onParamsChanged(()=>{n()});return()=>{t(),a()}},[r,e]),{translate:o,locale:(null==r?void 0:r.getLocale())??"en"}},o=(e,r,t)=>{const{translate:a}=n(t);return a(e,r)};exports.Translate=function({k:e,params:r,fallback:t,documentId:a,children:n}){const l=o(e,{params:r,fallback:t},a);return n?n(l):l},exports.useI18nCapability=a,exports.useI18nPlugin=()=>e.usePlugin(r.I18nPlugin.id),exports.useLocale=()=>{const{provides:e}=a(),[r,n]=t.useState(()=>(null==e?void 0:e.getLocale())??"en");return t.useEffect(()=>{if(!e)return;const r=e.onLocaleChange(({currentLocale:e})=>{n(e)});return n(e.getLocale()),r},[e]),r},exports.useTranslation=o,exports.useTranslations=n,Object.keys(r).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-i18n.ts","../../src/shared/components/translate.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { I18nPlugin } from '@embedpdf/plugin-i18n';\nimport { useState, useEffect, useCallback, useReducer } from '@framework';\n\nexport const useI18nCapability = () => useCapability<I18nPlugin>(I18nPlugin.id);\nexport const useI18nPlugin = () => usePlugin<I18nPlugin>(I18nPlugin.id);\n\n/**\n * Hook to get a translate function for a component\n * Automatically updates all translations on locale or param changes\n *\n * @param documentId - Optional document ID for document-scoped translations\n * @returns translate function and current locale\n *\n * @example\n * const { translate } = useTranslations(documentId);\n * return (\n * <div>\n * <h1>{translate('page.title')}</h1>\n * <p>{translate('page.count', { params: { count: 5 } })}</p>\n * <p>{translate('unknown.key', { fallback: 'Default Text' })}</p>\n * </div>\n * );\n */\nexport const useTranslations = (documentId?: string) => {\n const { provides } = useI18nCapability();\n const [, forceUpdate] = useReducer((x) => x + 1, 0);\n\n // Create a stable translate function with options support\n const translate = useCallback(\n (\n key: string,\n options?: {\n params?: Record<string, string | number>;\n fallback?: string;\n },\n ): string => {\n if (!provides) return options?.fallback ?? key;\n return provides.t(key, { documentId, params: options?.params, fallback: options?.fallback });\n },\n [provides, documentId],\n );\n\n useEffect(() => {\n if (!provides) return;\n\n // Update on locale change (all translations need to refresh)\n const unsubscribeLocale = provides.onLocaleChange(() => {\n forceUpdate();\n });\n\n // Update on params change (for keys with param resolvers)\n const unsubscribeParams = documentId\n ? provides.forDocument(documentId).onParamsChanged(() => {\n forceUpdate(); // Re-render component when any params change\n })\n : provides.onParamsChanged(() => {\n forceUpdate(); // Global params change\n });\n\n return () => {\n unsubscribeLocale();\n unsubscribeParams();\n };\n }, [provides, documentId]);\n\n return {\n translate,\n locale: provides?.getLocale() ?? 'en',\n };\n};\n\n// Keep the old hook for single-key translations (useful for derived state)\nexport const useTranslation = (\n key: string,\n options?: {\n params?: Record<string, string | number>;\n fallback?: string;\n },\n documentId?: string,\n) => {\n const { translate } = useTranslations(documentId);\n return translate(key, options);\n};\n\n/**\n * Hook to get current locale\n */\nexport const useLocale = () => {\n const { provides } = useI18nCapability();\n const [locale, setLocale] = useState<string>(() => provides?.getLocale() ?? 'en');\n\n useEffect(() => {\n if (!provides) return;\n\n const unsubscribe = provides.onLocaleChange(({ currentLocale }) => {\n setLocale(currentLocale);\n });\n\n setLocale(provides.getLocale());\n\n return unsubscribe;\n }, [provides]);\n\n return locale;\n};\n","import { ReactNode } from '@framework';\nimport { useTranslation } from '../hooks';\n\ninterface TranslateProps {\n k: string; // translation key\n params?: Record<string, string | number>;\n fallback?: string; // Fallback string if translation not found\n documentId?: string; // Optional document ID for document-scoped translations\n children?: (translation: string) => ReactNode;\n}\n\n/**\n * Component for inline translation\n *\n * @example\n * // Global translation\n * <Translate k=\"loading.viewer\" />\n *\n * @example\n * // With explicit params\n * <Translate k=\"zoom.level\" params={{ level: 150 }} />\n *\n * @example\n * // With fallback\n * <Translate k=\"unknown.key\" fallback=\"Default Text\" />\n *\n * @example\n * // Document-scoped (uses param resolvers)\n * <Translate k=\"page.current\" documentId={documentId} />\n *\n * @example\n * // With render prop\n * <Translate k=\"zoom.level\" params={{ level: 150 }}>\n * {(text) => <span className=\"font-bold\">{text}</span>}\n * </Translate>\n */\nexport function Translate({ k, params, fallback, documentId, children }: TranslateProps) {\n const translation = useTranslation(k, { params, fallback }, documentId);\n\n if (children) {\n return children(translation);\n }\n\n return translation;\n}\n"],"names":["useI18nCapability","useCapability","I18nPlugin","id","useTranslations","documentId","provides","forceUpdate","useReducer","x","translate","useCallback","key","options","t","params","fallback","useEffect","unsubscribeLocale","onLocaleChange","unsubscribeParams","forDocument","onParamsChanged","locale","getLocale","useTranslation","k","children","translation","usePlugin","setLocale","useState","unsubscribe","currentLocale"],"mappings":"8MAIaA,EAAoB,IAAMC,gBAA0BC,EAAAA,WAAWC,IAoB/DC,EAAmBC,IAC9B,MAAMC,SAAEA,GAAaN,KACf,CAAGO,GAAeC,EAAAA,WAAYC,GAAMA,EAAI,EAAG,GAG3CC,EAAYC,EAAAA,YAChB,CACEC,EACAC,IAKKP,EACEA,EAASQ,EAAEF,EAAK,CAAEP,aAAYU,OAAQ,MAAAF,OAAA,EAAAA,EAASE,OAAQC,SAAU,MAAAH,OAAA,EAAAA,EAASG,YAD3D,MAAAH,OAAA,EAAAA,EAASG,WAAYJ,EAG7C,CAACN,EAAUD,IA0Bb,OAvBAY,EAAAA,UAAU,KACR,IAAKX,EAAU,OAGf,MAAMY,EAAoBZ,EAASa,eAAe,KAChDZ,MAIIa,EAAoBf,EACtBC,EAASe,YAAYhB,GAAYiB,gBAAgB,KAC/Cf,MAEFD,EAASgB,gBAAgB,KACvBf,MAGN,MAAO,KACLW,IACAE,MAED,CAACd,EAAUD,IAEP,CACLK,YACAa,cAAQjB,WAAUkB,cAAe,OAKxBC,EAAiB,CAC5Bb,EACAC,EAIAR,KAEA,MAAMK,UAAEA,GAAcN,EAAgBC,GACtC,OAAOK,EAAUE,EAAKC,sBC9CjB,UAAmBa,EAAEA,EAAAX,OAAGA,WAAQC,EAAAX,WAAUA,EAAAsB,SAAYA,IAC3D,MAAMC,EAAcH,EAAeC,EAAG,CAAEX,SAAQC,YAAYX,GAE5D,OAAIsB,EACKA,EAASC,GAGXA,CACT,oDDvC6B,IAAMC,YAAsB3B,EAAAA,WAAWC,sBAmF3C,KACvB,MAAMG,SAAEA,GAAaN,KACduB,EAAQO,GAAaC,EAAAA,SAAiB,KAAM,MAAAzB,OAAA,EAAAA,EAAUkB,cAAe,MAc5E,OAZAP,EAAAA,UAAU,KACR,IAAKX,EAAU,OAEf,MAAM0B,EAAc1B,EAASa,eAAe,EAAGc,oBAC7CH,EAAUG,KAKZ,OAFAH,EAAUxB,EAASkB,aAEZQ,GACN,CAAC1B,IAEGiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../shared-preact';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useCapability, usePlugin } from "@embedpdf/core/preact";
|
|
2
|
+
import { I18nPlugin } from "@embedpdf/plugin-i18n";
|
|
3
|
+
export * from "@embedpdf/plugin-i18n";
|
|
4
|
+
import "preact";
|
|
5
|
+
import { useReducer, useCallback, useEffect, useState } from "preact/hooks";
|
|
6
|
+
const useI18nCapability = () => useCapability(I18nPlugin.id);
|
|
7
|
+
const useI18nPlugin = () => usePlugin(I18nPlugin.id);
|
|
8
|
+
const useTranslations = (documentId) => {
|
|
9
|
+
const { provides } = useI18nCapability();
|
|
10
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
11
|
+
const translate = useCallback(
|
|
12
|
+
(key, options) => {
|
|
13
|
+
if (!provides) return (options == null ? void 0 : options.fallback) ?? key;
|
|
14
|
+
return provides.t(key, { documentId, params: options == null ? void 0 : options.params, fallback: options == null ? void 0 : options.fallback });
|
|
15
|
+
},
|
|
16
|
+
[provides, documentId]
|
|
17
|
+
);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!provides) return;
|
|
20
|
+
const unsubscribeLocale = provides.onLocaleChange(() => {
|
|
21
|
+
forceUpdate();
|
|
22
|
+
});
|
|
23
|
+
const unsubscribeParams = documentId ? provides.forDocument(documentId).onParamsChanged(() => {
|
|
24
|
+
forceUpdate();
|
|
25
|
+
}) : provides.onParamsChanged(() => {
|
|
26
|
+
forceUpdate();
|
|
27
|
+
});
|
|
28
|
+
return () => {
|
|
29
|
+
unsubscribeLocale();
|
|
30
|
+
unsubscribeParams();
|
|
31
|
+
};
|
|
32
|
+
}, [provides, documentId]);
|
|
33
|
+
return {
|
|
34
|
+
translate,
|
|
35
|
+
locale: (provides == null ? void 0 : provides.getLocale()) ?? "en"
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const useTranslation = (key, options, documentId) => {
|
|
39
|
+
const { translate } = useTranslations(documentId);
|
|
40
|
+
return translate(key, options);
|
|
41
|
+
};
|
|
42
|
+
const useLocale = () => {
|
|
43
|
+
const { provides } = useI18nCapability();
|
|
44
|
+
const [locale, setLocale] = useState(() => (provides == null ? void 0 : provides.getLocale()) ?? "en");
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!provides) return;
|
|
47
|
+
const unsubscribe = provides.onLocaleChange(({ currentLocale }) => {
|
|
48
|
+
setLocale(currentLocale);
|
|
49
|
+
});
|
|
50
|
+
setLocale(provides.getLocale());
|
|
51
|
+
return unsubscribe;
|
|
52
|
+
}, [provides]);
|
|
53
|
+
return locale;
|
|
54
|
+
};
|
|
55
|
+
function Translate({ k, params, fallback, documentId, children }) {
|
|
56
|
+
const translation = useTranslation(k, { params, fallback }, documentId);
|
|
57
|
+
if (children) {
|
|
58
|
+
return children(translation);
|
|
59
|
+
}
|
|
60
|
+
return translation;
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
Translate,
|
|
64
|
+
useI18nCapability,
|
|
65
|
+
useI18nPlugin,
|
|
66
|
+
useLocale,
|
|
67
|
+
useTranslation,
|
|
68
|
+
useTranslations
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-i18n.ts","../../src/shared/components/translate.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { I18nPlugin } from '@embedpdf/plugin-i18n';\nimport { useState, useEffect, useCallback, useReducer } from '@framework';\n\nexport const useI18nCapability = () => useCapability<I18nPlugin>(I18nPlugin.id);\nexport const useI18nPlugin = () => usePlugin<I18nPlugin>(I18nPlugin.id);\n\n/**\n * Hook to get a translate function for a component\n * Automatically updates all translations on locale or param changes\n *\n * @param documentId - Optional document ID for document-scoped translations\n * @returns translate function and current locale\n *\n * @example\n * const { translate } = useTranslations(documentId);\n * return (\n * <div>\n * <h1>{translate('page.title')}</h1>\n * <p>{translate('page.count', { params: { count: 5 } })}</p>\n * <p>{translate('unknown.key', { fallback: 'Default Text' })}</p>\n * </div>\n * );\n */\nexport const useTranslations = (documentId?: string) => {\n const { provides } = useI18nCapability();\n const [, forceUpdate] = useReducer((x) => x + 1, 0);\n\n // Create a stable translate function with options support\n const translate = useCallback(\n (\n key: string,\n options?: {\n params?: Record<string, string | number>;\n fallback?: string;\n },\n ): string => {\n if (!provides) return options?.fallback ?? key;\n return provides.t(key, { documentId, params: options?.params, fallback: options?.fallback });\n },\n [provides, documentId],\n );\n\n useEffect(() => {\n if (!provides) return;\n\n // Update on locale change (all translations need to refresh)\n const unsubscribeLocale = provides.onLocaleChange(() => {\n forceUpdate();\n });\n\n // Update on params change (for keys with param resolvers)\n const unsubscribeParams = documentId\n ? provides.forDocument(documentId).onParamsChanged(() => {\n forceUpdate(); // Re-render component when any params change\n })\n : provides.onParamsChanged(() => {\n forceUpdate(); // Global params change\n });\n\n return () => {\n unsubscribeLocale();\n unsubscribeParams();\n };\n }, [provides, documentId]);\n\n return {\n translate,\n locale: provides?.getLocale() ?? 'en',\n };\n};\n\n// Keep the old hook for single-key translations (useful for derived state)\nexport const useTranslation = (\n key: string,\n options?: {\n params?: Record<string, string | number>;\n fallback?: string;\n },\n documentId?: string,\n) => {\n const { translate } = useTranslations(documentId);\n return translate(key, options);\n};\n\n/**\n * Hook to get current locale\n */\nexport const useLocale = () => {\n const { provides } = useI18nCapability();\n const [locale, setLocale] = useState<string>(() => provides?.getLocale() ?? 'en');\n\n useEffect(() => {\n if (!provides) return;\n\n const unsubscribe = provides.onLocaleChange(({ currentLocale }) => {\n setLocale(currentLocale);\n });\n\n setLocale(provides.getLocale());\n\n return unsubscribe;\n }, [provides]);\n\n return locale;\n};\n","import { ReactNode } from '@framework';\nimport { useTranslation } from '../hooks';\n\ninterface TranslateProps {\n k: string; // translation key\n params?: Record<string, string | number>;\n fallback?: string; // Fallback string if translation not found\n documentId?: string; // Optional document ID for document-scoped translations\n children?: (translation: string) => ReactNode;\n}\n\n/**\n * Component for inline translation\n *\n * @example\n * // Global translation\n * <Translate k=\"loading.viewer\" />\n *\n * @example\n * // With explicit params\n * <Translate k=\"zoom.level\" params={{ level: 150 }} />\n *\n * @example\n * // With fallback\n * <Translate k=\"unknown.key\" fallback=\"Default Text\" />\n *\n * @example\n * // Document-scoped (uses param resolvers)\n * <Translate k=\"page.current\" documentId={documentId} />\n *\n * @example\n * // With render prop\n * <Translate k=\"zoom.level\" params={{ level: 150 }}>\n * {(text) => <span className=\"font-bold\">{text}</span>}\n * </Translate>\n */\nexport function Translate({ k, params, fallback, documentId, children }: TranslateProps) {\n const translation = useTranslation(k, { params, fallback }, documentId);\n\n if (children) {\n return children(translation);\n }\n\n return translation;\n}\n"],"names":[],"mappings":";;;;;AAIO,MAAM,oBAAoB,MAAM,cAA0B,WAAW,EAAE;AACvE,MAAM,gBAAgB,MAAM,UAAsB,WAAW,EAAE;AAmB/D,MAAM,kBAAkB,CAAC,eAAwB;AACtD,QAAM,EAAE,SAAA,IAAa,kBAAA;AACrB,QAAM,CAAA,EAAG,WAAW,IAAI,WAAW,CAAC,MAAM,IAAI,GAAG,CAAC;AAGlD,QAAM,YAAY;AAAA,IAChB,CACE,KACA,YAIW;AACX,UAAI,CAAC,SAAU,SAAO,mCAAS,aAAY;AAC3C,aAAO,SAAS,EAAE,KAAK,EAAE,YAAY,QAAQ,mCAAS,QAAQ,UAAU,mCAAS,SAAA,CAAU;AAAA,IAC7F;AAAA,IACA,CAAC,UAAU,UAAU;AAAA,EAAA;AAGvB,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AAGf,UAAM,oBAAoB,SAAS,eAAe,MAAM;AACtD,kBAAA;AAAA,IACF,CAAC;AAGD,UAAM,oBAAoB,aACtB,SAAS,YAAY,UAAU,EAAE,gBAAgB,MAAM;AACrD,kBAAA;AAAA,IACF,CAAC,IACD,SAAS,gBAAgB,MAAM;AAC7B,kBAAA;AAAA,IACF,CAAC;AAEL,WAAO,MAAM;AACX,wBAAA;AACA,wBAAA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,UAAU,UAAU,CAAC;AAEzB,SAAO;AAAA,IACL;AAAA,IACA,SAAQ,qCAAU,gBAAe;AAAA,EAAA;AAErC;AAGO,MAAM,iBAAiB,CAC5B,KACA,SAIA,eACG;AACH,QAAM,EAAE,UAAA,IAAc,gBAAgB,UAAU;AAChD,SAAO,UAAU,KAAK,OAAO;AAC/B;AAKO,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,SAAA,IAAa,kBAAA;AACrB,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAiB,OAAM,qCAAU,gBAAe,IAAI;AAEhF,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AAEf,UAAM,cAAc,SAAS,eAAe,CAAC,EAAE,oBAAoB;AACjE,gBAAU,aAAa;AAAA,IACzB,CAAC;AAED,cAAU,SAAS,WAAW;AAE9B,WAAO;AAAA,EACT,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AACT;ACrEO,SAAS,UAAU,EAAE,GAAG,QAAQ,UAAU,YAAY,YAA4B;AACvF,QAAM,cAAc,eAAe,GAAG,EAAE,QAAQ,SAAA,GAAY,UAAU;AAEtE,MAAI,UAAU;AACZ,WAAO,SAAS,WAAW;AAAA,EAC7B;AAEA,SAAO;AACT;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@embedpdf/core/react';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),r=require("@embedpdf/plugin-i18n"),t=require("react"),a=()=>e.useCapability(r.I18nPlugin.id),n=e=>{const{provides:r}=a(),[,n]=t.useReducer(e=>e+1,0),o=t.useCallback((t,a)=>r?r.t(t,{documentId:e,params:null==a?void 0:a.params,fallback:null==a?void 0:a.fallback}):(null==a?void 0:a.fallback)??t,[r,e]);return t.useEffect(()=>{if(!r)return;const t=r.onLocaleChange(()=>{n()}),a=e?r.forDocument(e).onParamsChanged(()=>{n()}):r.onParamsChanged(()=>{n()});return()=>{t(),a()}},[r,e]),{translate:o,locale:(null==r?void 0:r.getLocale())??"en"}},o=(e,r,t)=>{const{translate:a}=n(t);return a(e,r)};exports.Translate=function({k:e,params:r,fallback:t,documentId:a,children:n}){const l=o(e,{params:r,fallback:t},a);return n?n(l):l},exports.useI18nCapability=a,exports.useI18nPlugin=()=>e.usePlugin(r.I18nPlugin.id),exports.useLocale=()=>{const{provides:e}=a(),[r,n]=t.useState(()=>(null==e?void 0:e.getLocale())??"en");return t.useEffect(()=>{if(!e)return;const r=e.onLocaleChange(({currentLocale:e})=>{n(e)});return n(e.getLocale()),r},[e]),r},exports.useTranslation=o,exports.useTranslations=n,Object.keys(r).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-i18n.ts","../../src/shared/components/translate.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { I18nPlugin } from '@embedpdf/plugin-i18n';\nimport { useState, useEffect, useCallback, useReducer } from '@framework';\n\nexport const useI18nCapability = () => useCapability<I18nPlugin>(I18nPlugin.id);\nexport const useI18nPlugin = () => usePlugin<I18nPlugin>(I18nPlugin.id);\n\n/**\n * Hook to get a translate function for a component\n * Automatically updates all translations on locale or param changes\n *\n * @param documentId - Optional document ID for document-scoped translations\n * @returns translate function and current locale\n *\n * @example\n * const { translate } = useTranslations(documentId);\n * return (\n * <div>\n * <h1>{translate('page.title')}</h1>\n * <p>{translate('page.count', { params: { count: 5 } })}</p>\n * <p>{translate('unknown.key', { fallback: 'Default Text' })}</p>\n * </div>\n * );\n */\nexport const useTranslations = (documentId?: string) => {\n const { provides } = useI18nCapability();\n const [, forceUpdate] = useReducer((x) => x + 1, 0);\n\n // Create a stable translate function with options support\n const translate = useCallback(\n (\n key: string,\n options?: {\n params?: Record<string, string | number>;\n fallback?: string;\n },\n ): string => {\n if (!provides) return options?.fallback ?? key;\n return provides.t(key, { documentId, params: options?.params, fallback: options?.fallback });\n },\n [provides, documentId],\n );\n\n useEffect(() => {\n if (!provides) return;\n\n // Update on locale change (all translations need to refresh)\n const unsubscribeLocale = provides.onLocaleChange(() => {\n forceUpdate();\n });\n\n // Update on params change (for keys with param resolvers)\n const unsubscribeParams = documentId\n ? provides.forDocument(documentId).onParamsChanged(() => {\n forceUpdate(); // Re-render component when any params change\n })\n : provides.onParamsChanged(() => {\n forceUpdate(); // Global params change\n });\n\n return () => {\n unsubscribeLocale();\n unsubscribeParams();\n };\n }, [provides, documentId]);\n\n return {\n translate,\n locale: provides?.getLocale() ?? 'en',\n };\n};\n\n// Keep the old hook for single-key translations (useful for derived state)\nexport const useTranslation = (\n key: string,\n options?: {\n params?: Record<string, string | number>;\n fallback?: string;\n },\n documentId?: string,\n) => {\n const { translate } = useTranslations(documentId);\n return translate(key, options);\n};\n\n/**\n * Hook to get current locale\n */\nexport const useLocale = () => {\n const { provides } = useI18nCapability();\n const [locale, setLocale] = useState<string>(() => provides?.getLocale() ?? 'en');\n\n useEffect(() => {\n if (!provides) return;\n\n const unsubscribe = provides.onLocaleChange(({ currentLocale }) => {\n setLocale(currentLocale);\n });\n\n setLocale(provides.getLocale());\n\n return unsubscribe;\n }, [provides]);\n\n return locale;\n};\n","import { ReactNode } from '@framework';\nimport { useTranslation } from '../hooks';\n\ninterface TranslateProps {\n k: string; // translation key\n params?: Record<string, string | number>;\n fallback?: string; // Fallback string if translation not found\n documentId?: string; // Optional document ID for document-scoped translations\n children?: (translation: string) => ReactNode;\n}\n\n/**\n * Component for inline translation\n *\n * @example\n * // Global translation\n * <Translate k=\"loading.viewer\" />\n *\n * @example\n * // With explicit params\n * <Translate k=\"zoom.level\" params={{ level: 150 }} />\n *\n * @example\n * // With fallback\n * <Translate k=\"unknown.key\" fallback=\"Default Text\" />\n *\n * @example\n * // Document-scoped (uses param resolvers)\n * <Translate k=\"page.current\" documentId={documentId} />\n *\n * @example\n * // With render prop\n * <Translate k=\"zoom.level\" params={{ level: 150 }}>\n * {(text) => <span className=\"font-bold\">{text}</span>}\n * </Translate>\n */\nexport function Translate({ k, params, fallback, documentId, children }: TranslateProps) {\n const translation = useTranslation(k, { params, fallback }, documentId);\n\n if (children) {\n return children(translation);\n }\n\n return translation;\n}\n"],"names":["useI18nCapability","useCapability","I18nPlugin","id","useTranslations","documentId","provides","forceUpdate","useReducer","x","translate","useCallback","key","options","t","params","fallback","useEffect","unsubscribeLocale","onLocaleChange","unsubscribeParams","forDocument","onParamsChanged","locale","getLocale","useTranslation","k","children","translation","usePlugin","setLocale","useState","unsubscribe","currentLocale"],"mappings":"8KAIaA,EAAoB,IAAMC,gBAA0BC,EAAAA,WAAWC,IAoB/DC,EAAmBC,IAC9B,MAAMC,SAAEA,GAAaN,KACf,CAAGO,GAAeC,EAAAA,WAAYC,GAAMA,EAAI,EAAG,GAG3CC,EAAYC,EAAAA,YAChB,CACEC,EACAC,IAKKP,EACEA,EAASQ,EAAEF,EAAK,CAAEP,aAAYU,OAAQ,MAAAF,OAAA,EAAAA,EAASE,OAAQC,SAAU,MAAAH,OAAA,EAAAA,EAASG,YAD3D,MAAAH,OAAA,EAAAA,EAASG,WAAYJ,EAG7C,CAACN,EAAUD,IA0Bb,OAvBAY,EAAAA,UAAU,KACR,IAAKX,EAAU,OAGf,MAAMY,EAAoBZ,EAASa,eAAe,KAChDZ,MAIIa,EAAoBf,EACtBC,EAASe,YAAYhB,GAAYiB,gBAAgB,KAC/Cf,MAEFD,EAASgB,gBAAgB,KACvBf,MAGN,MAAO,KACLW,IACAE,MAED,CAACd,EAAUD,IAEP,CACLK,YACAa,cAAQjB,WAAUkB,cAAe,OAKxBC,EAAiB,CAC5Bb,EACAC,EAIAR,KAEA,MAAMK,UAAEA,GAAcN,EAAgBC,GACtC,OAAOK,EAAUE,EAAKC,sBC9CjB,UAAmBa,EAAEA,EAAAX,OAAGA,WAAQC,EAAAX,WAAUA,EAAAsB,SAAYA,IAC3D,MAAMC,EAAcH,EAAeC,EAAG,CAAEX,SAAQC,YAAYX,GAE5D,OAAIsB,EACKA,EAASC,GAGXA,CACT,oDDvC6B,IAAMC,YAAsB3B,EAAAA,WAAWC,sBAmF3C,KACvB,MAAMG,SAAEA,GAAaN,KACduB,EAAQO,GAAaC,EAAAA,SAAiB,KAAM,MAAAzB,OAAA,EAAAA,EAAUkB,cAAe,MAc5E,OAZAP,EAAAA,UAAU,KACR,IAAKX,EAAU,OAEf,MAAM0B,EAAc1B,EAASa,eAAe,EAAGc,oBAC7CH,EAAUG,KAKZ,OAFAH,EAAUxB,EAASkB,aAEZQ,GACN,CAAC1B,IAEGiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../shared-react';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useCapability, usePlugin } from "@embedpdf/core/react";
|
|
2
|
+
import { I18nPlugin } from "@embedpdf/plugin-i18n";
|
|
3
|
+
export * from "@embedpdf/plugin-i18n";
|
|
4
|
+
import { useReducer, useCallback, useEffect, useState } from "react";
|
|
5
|
+
const useI18nCapability = () => useCapability(I18nPlugin.id);
|
|
6
|
+
const useI18nPlugin = () => usePlugin(I18nPlugin.id);
|
|
7
|
+
const useTranslations = (documentId) => {
|
|
8
|
+
const { provides } = useI18nCapability();
|
|
9
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
10
|
+
const translate = useCallback(
|
|
11
|
+
(key, options) => {
|
|
12
|
+
if (!provides) return (options == null ? void 0 : options.fallback) ?? key;
|
|
13
|
+
return provides.t(key, { documentId, params: options == null ? void 0 : options.params, fallback: options == null ? void 0 : options.fallback });
|
|
14
|
+
},
|
|
15
|
+
[provides, documentId]
|
|
16
|
+
);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!provides) return;
|
|
19
|
+
const unsubscribeLocale = provides.onLocaleChange(() => {
|
|
20
|
+
forceUpdate();
|
|
21
|
+
});
|
|
22
|
+
const unsubscribeParams = documentId ? provides.forDocument(documentId).onParamsChanged(() => {
|
|
23
|
+
forceUpdate();
|
|
24
|
+
}) : provides.onParamsChanged(() => {
|
|
25
|
+
forceUpdate();
|
|
26
|
+
});
|
|
27
|
+
return () => {
|
|
28
|
+
unsubscribeLocale();
|
|
29
|
+
unsubscribeParams();
|
|
30
|
+
};
|
|
31
|
+
}, [provides, documentId]);
|
|
32
|
+
return {
|
|
33
|
+
translate,
|
|
34
|
+
locale: (provides == null ? void 0 : provides.getLocale()) ?? "en"
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const useTranslation = (key, options, documentId) => {
|
|
38
|
+
const { translate } = useTranslations(documentId);
|
|
39
|
+
return translate(key, options);
|
|
40
|
+
};
|
|
41
|
+
const useLocale = () => {
|
|
42
|
+
const { provides } = useI18nCapability();
|
|
43
|
+
const [locale, setLocale] = useState(() => (provides == null ? void 0 : provides.getLocale()) ?? "en");
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!provides) return;
|
|
46
|
+
const unsubscribe = provides.onLocaleChange(({ currentLocale }) => {
|
|
47
|
+
setLocale(currentLocale);
|
|
48
|
+
});
|
|
49
|
+
setLocale(provides.getLocale());
|
|
50
|
+
return unsubscribe;
|
|
51
|
+
}, [provides]);
|
|
52
|
+
return locale;
|
|
53
|
+
};
|
|
54
|
+
function Translate({ k, params, fallback, documentId, children }) {
|
|
55
|
+
const translation = useTranslation(k, { params, fallback }, documentId);
|
|
56
|
+
if (children) {
|
|
57
|
+
return children(translation);
|
|
58
|
+
}
|
|
59
|
+
return translation;
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
Translate,
|
|
63
|
+
useI18nCapability,
|
|
64
|
+
useI18nPlugin,
|
|
65
|
+
useLocale,
|
|
66
|
+
useTranslation,
|
|
67
|
+
useTranslations
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-i18n.ts","../../src/shared/components/translate.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { I18nPlugin } from '@embedpdf/plugin-i18n';\nimport { useState, useEffect, useCallback, useReducer } from '@framework';\n\nexport const useI18nCapability = () => useCapability<I18nPlugin>(I18nPlugin.id);\nexport const useI18nPlugin = () => usePlugin<I18nPlugin>(I18nPlugin.id);\n\n/**\n * Hook to get a translate function for a component\n * Automatically updates all translations on locale or param changes\n *\n * @param documentId - Optional document ID for document-scoped translations\n * @returns translate function and current locale\n *\n * @example\n * const { translate } = useTranslations(documentId);\n * return (\n * <div>\n * <h1>{translate('page.title')}</h1>\n * <p>{translate('page.count', { params: { count: 5 } })}</p>\n * <p>{translate('unknown.key', { fallback: 'Default Text' })}</p>\n * </div>\n * );\n */\nexport const useTranslations = (documentId?: string) => {\n const { provides } = useI18nCapability();\n const [, forceUpdate] = useReducer((x) => x + 1, 0);\n\n // Create a stable translate function with options support\n const translate = useCallback(\n (\n key: string,\n options?: {\n params?: Record<string, string | number>;\n fallback?: string;\n },\n ): string => {\n if (!provides) return options?.fallback ?? key;\n return provides.t(key, { documentId, params: options?.params, fallback: options?.fallback });\n },\n [provides, documentId],\n );\n\n useEffect(() => {\n if (!provides) return;\n\n // Update on locale change (all translations need to refresh)\n const unsubscribeLocale = provides.onLocaleChange(() => {\n forceUpdate();\n });\n\n // Update on params change (for keys with param resolvers)\n const unsubscribeParams = documentId\n ? provides.forDocument(documentId).onParamsChanged(() => {\n forceUpdate(); // Re-render component when any params change\n })\n : provides.onParamsChanged(() => {\n forceUpdate(); // Global params change\n });\n\n return () => {\n unsubscribeLocale();\n unsubscribeParams();\n };\n }, [provides, documentId]);\n\n return {\n translate,\n locale: provides?.getLocale() ?? 'en',\n };\n};\n\n// Keep the old hook for single-key translations (useful for derived state)\nexport const useTranslation = (\n key: string,\n options?: {\n params?: Record<string, string | number>;\n fallback?: string;\n },\n documentId?: string,\n) => {\n const { translate } = useTranslations(documentId);\n return translate(key, options);\n};\n\n/**\n * Hook to get current locale\n */\nexport const useLocale = () => {\n const { provides } = useI18nCapability();\n const [locale, setLocale] = useState<string>(() => provides?.getLocale() ?? 'en');\n\n useEffect(() => {\n if (!provides) return;\n\n const unsubscribe = provides.onLocaleChange(({ currentLocale }) => {\n setLocale(currentLocale);\n });\n\n setLocale(provides.getLocale());\n\n return unsubscribe;\n }, [provides]);\n\n return locale;\n};\n","import { ReactNode } from '@framework';\nimport { useTranslation } from '../hooks';\n\ninterface TranslateProps {\n k: string; // translation key\n params?: Record<string, string | number>;\n fallback?: string; // Fallback string if translation not found\n documentId?: string; // Optional document ID for document-scoped translations\n children?: (translation: string) => ReactNode;\n}\n\n/**\n * Component for inline translation\n *\n * @example\n * // Global translation\n * <Translate k=\"loading.viewer\" />\n *\n * @example\n * // With explicit params\n * <Translate k=\"zoom.level\" params={{ level: 150 }} />\n *\n * @example\n * // With fallback\n * <Translate k=\"unknown.key\" fallback=\"Default Text\" />\n *\n * @example\n * // Document-scoped (uses param resolvers)\n * <Translate k=\"page.current\" documentId={documentId} />\n *\n * @example\n * // With render prop\n * <Translate k=\"zoom.level\" params={{ level: 150 }}>\n * {(text) => <span className=\"font-bold\">{text}</span>}\n * </Translate>\n */\nexport function Translate({ k, params, fallback, documentId, children }: TranslateProps) {\n const translation = useTranslation(k, { params, fallback }, documentId);\n\n if (children) {\n return children(translation);\n }\n\n return translation;\n}\n"],"names":[],"mappings":";;;;AAIO,MAAM,oBAAoB,MAAM,cAA0B,WAAW,EAAE;AACvE,MAAM,gBAAgB,MAAM,UAAsB,WAAW,EAAE;AAmB/D,MAAM,kBAAkB,CAAC,eAAwB;AACtD,QAAM,EAAE,SAAA,IAAa,kBAAA;AACrB,QAAM,CAAA,EAAG,WAAW,IAAI,WAAW,CAAC,MAAM,IAAI,GAAG,CAAC;AAGlD,QAAM,YAAY;AAAA,IAChB,CACE,KACA,YAIW;AACX,UAAI,CAAC,SAAU,SAAO,mCAAS,aAAY;AAC3C,aAAO,SAAS,EAAE,KAAK,EAAE,YAAY,QAAQ,mCAAS,QAAQ,UAAU,mCAAS,SAAA,CAAU;AAAA,IAC7F;AAAA,IACA,CAAC,UAAU,UAAU;AAAA,EAAA;AAGvB,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AAGf,UAAM,oBAAoB,SAAS,eAAe,MAAM;AACtD,kBAAA;AAAA,IACF,CAAC;AAGD,UAAM,oBAAoB,aACtB,SAAS,YAAY,UAAU,EAAE,gBAAgB,MAAM;AACrD,kBAAA;AAAA,IACF,CAAC,IACD,SAAS,gBAAgB,MAAM;AAC7B,kBAAA;AAAA,IACF,CAAC;AAEL,WAAO,MAAM;AACX,wBAAA;AACA,wBAAA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,UAAU,UAAU,CAAC;AAEzB,SAAO;AAAA,IACL;AAAA,IACA,SAAQ,qCAAU,gBAAe;AAAA,EAAA;AAErC;AAGO,MAAM,iBAAiB,CAC5B,KACA,SAIA,eACG;AACH,QAAM,EAAE,UAAA,IAAc,gBAAgB,UAAU;AAChD,SAAO,UAAU,KAAK,OAAO;AAC/B;AAKO,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,SAAA,IAAa,kBAAA;AACrB,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAiB,OAAM,qCAAU,gBAAe,IAAI;AAEhF,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AAEf,UAAM,cAAc,SAAS,eAAe,CAAC,EAAE,oBAAoB;AACjE,gBAAU,aAAa;AAAA,IACzB,CAAC;AAED,cAAU,SAAS,WAAW;AAE9B,WAAO;AAAA,EACT,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AACT;ACrEO,SAAS,UAAU,EAAE,GAAG,QAAQ,UAAU,YAAY,YAA4B;AACvF,QAAM,cAAc,eAAe,GAAG,EAAE,QAAQ,SAAA,GAAY,UAAU;AAEtE,MAAI,UAAU;AACZ,WAAO,SAAS,WAAW;AAAA,EAC7B;AAEA,SAAO;AACT;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './translate';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ReactNode } from '../../react/adapter.ts';
|
|
2
|
+
interface TranslateProps {
|
|
3
|
+
k: string;
|
|
4
|
+
params?: Record<string, string | number>;
|
|
5
|
+
fallback?: string;
|
|
6
|
+
documentId?: string;
|
|
7
|
+
children?: (translation: string) => ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Component for inline translation
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Global translation
|
|
14
|
+
* <Translate k="loading.viewer" />
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // With explicit params
|
|
18
|
+
* <Translate k="zoom.level" params={{ level: 150 }} />
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // With fallback
|
|
22
|
+
* <Translate k="unknown.key" fallback="Default Text" />
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Document-scoped (uses param resolvers)
|
|
26
|
+
* <Translate k="page.current" documentId={documentId} />
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // With render prop
|
|
30
|
+
* <Translate k="zoom.level" params={{ level: 150 }}>
|
|
31
|
+
* {(text) => <span className="font-bold">{text}</span>}
|
|
32
|
+
* </Translate>
|
|
33
|
+
*/
|
|
34
|
+
export declare function Translate({ k, params, fallback, documentId, children }: TranslateProps): ReactNode;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-i18n';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { I18nPlugin } from '../../index.ts';
|
|
2
|
+
export declare const useI18nCapability: () => {
|
|
3
|
+
provides: Readonly<import('../../index.ts').I18nCapability> | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useI18nPlugin: () => {
|
|
8
|
+
plugin: I18nPlugin | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Hook to get a translate function for a component
|
|
14
|
+
* Automatically updates all translations on locale or param changes
|
|
15
|
+
*
|
|
16
|
+
* @param documentId - Optional document ID for document-scoped translations
|
|
17
|
+
* @returns translate function and current locale
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const { translate } = useTranslations(documentId);
|
|
21
|
+
* return (
|
|
22
|
+
* <div>
|
|
23
|
+
* <h1>{translate('page.title')}</h1>
|
|
24
|
+
* <p>{translate('page.count', { params: { count: 5 } })}</p>
|
|
25
|
+
* <p>{translate('unknown.key', { fallback: 'Default Text' })}</p>
|
|
26
|
+
* </div>
|
|
27
|
+
* );
|
|
28
|
+
*/
|
|
29
|
+
export declare const useTranslations: (documentId?: string) => {
|
|
30
|
+
translate: (key: string, options?: {
|
|
31
|
+
params?: Record<string, string | number>;
|
|
32
|
+
fallback?: string;
|
|
33
|
+
}) => string;
|
|
34
|
+
locale: string;
|
|
35
|
+
};
|
|
36
|
+
export declare const useTranslation: (key: string, options?: {
|
|
37
|
+
params?: Record<string, string | number>;
|
|
38
|
+
fallback?: string;
|
|
39
|
+
}, documentId?: string) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Hook to get current locale
|
|
42
|
+
*/
|
|
43
|
+
export declare const useLocale: () => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './translate';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ReactNode } from '../../preact/adapter.ts';
|
|
2
|
+
interface TranslateProps {
|
|
3
|
+
k: string;
|
|
4
|
+
params?: Record<string, string | number>;
|
|
5
|
+
fallback?: string;
|
|
6
|
+
documentId?: string;
|
|
7
|
+
children?: (translation: string) => ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Component for inline translation
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Global translation
|
|
14
|
+
* <Translate k="loading.viewer" />
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // With explicit params
|
|
18
|
+
* <Translate k="zoom.level" params={{ level: 150 }} />
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // With fallback
|
|
22
|
+
* <Translate k="unknown.key" fallback="Default Text" />
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Document-scoped (uses param resolvers)
|
|
26
|
+
* <Translate k="page.current" documentId={documentId} />
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // With render prop
|
|
30
|
+
* <Translate k="zoom.level" params={{ level: 150 }}>
|
|
31
|
+
* {(text) => <span className="font-bold">{text}</span>}
|
|
32
|
+
* </Translate>
|
|
33
|
+
*/
|
|
34
|
+
export declare function Translate({ k, params, fallback, documentId, children }: TranslateProps): ReactNode;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-i18n';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { I18nPlugin } from '../../lib/index.ts';
|
|
2
|
+
export declare const useI18nCapability: () => {
|
|
3
|
+
provides: Readonly<import('../../lib/index.ts').I18nCapability> | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useI18nPlugin: () => {
|
|
8
|
+
plugin: I18nPlugin | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Hook to get a translate function for a component
|
|
14
|
+
* Automatically updates all translations on locale or param changes
|
|
15
|
+
*
|
|
16
|
+
* @param documentId - Optional document ID for document-scoped translations
|
|
17
|
+
* @returns translate function and current locale
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const { translate } = useTranslations(documentId);
|
|
21
|
+
* return (
|
|
22
|
+
* <div>
|
|
23
|
+
* <h1>{translate('page.title')}</h1>
|
|
24
|
+
* <p>{translate('page.count', { params: { count: 5 } })}</p>
|
|
25
|
+
* <p>{translate('unknown.key', { fallback: 'Default Text' })}</p>
|
|
26
|
+
* </div>
|
|
27
|
+
* );
|
|
28
|
+
*/
|
|
29
|
+
export declare const useTranslations: (documentId?: string) => {
|
|
30
|
+
translate: (key: string, options?: {
|
|
31
|
+
params?: Record<string, string | number>;
|
|
32
|
+
fallback?: string;
|
|
33
|
+
}) => string;
|
|
34
|
+
locale: string;
|
|
35
|
+
};
|
|
36
|
+
export declare const useTranslation: (key: string, options?: {
|
|
37
|
+
params?: Record<string, string | number>;
|
|
38
|
+
fallback?: string;
|
|
39
|
+
}, documentId?: string) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Hook to get current locale
|
|
42
|
+
*/
|
|
43
|
+
export declare const useLocale: () => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './translate';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ReactNode } from '../../react/adapter.ts';
|
|
2
|
+
interface TranslateProps {
|
|
3
|
+
k: string;
|
|
4
|
+
params?: Record<string, string | number>;
|
|
5
|
+
fallback?: string;
|
|
6
|
+
documentId?: string;
|
|
7
|
+
children?: (translation: string) => ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Component for inline translation
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Global translation
|
|
14
|
+
* <Translate k="loading.viewer" />
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // With explicit params
|
|
18
|
+
* <Translate k="zoom.level" params={{ level: 150 }} />
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // With fallback
|
|
22
|
+
* <Translate k="unknown.key" fallback="Default Text" />
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Document-scoped (uses param resolvers)
|
|
26
|
+
* <Translate k="page.current" documentId={documentId} />
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // With render prop
|
|
30
|
+
* <Translate k="zoom.level" params={{ level: 150 }}>
|
|
31
|
+
* {(text) => <span className="font-bold">{text}</span>}
|
|
32
|
+
* </Translate>
|
|
33
|
+
*/
|
|
34
|
+
export declare function Translate({ k, params, fallback, documentId, children }: TranslateProps): ReactNode;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-i18n';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { I18nPlugin } from '../../lib/index.ts';
|
|
2
|
+
export declare const useI18nCapability: () => {
|
|
3
|
+
provides: Readonly<import('../../lib/index.ts').I18nCapability> | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useI18nPlugin: () => {
|
|
8
|
+
plugin: I18nPlugin | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Hook to get a translate function for a component
|
|
14
|
+
* Automatically updates all translations on locale or param changes
|
|
15
|
+
*
|
|
16
|
+
* @param documentId - Optional document ID for document-scoped translations
|
|
17
|
+
* @returns translate function and current locale
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const { translate } = useTranslations(documentId);
|
|
21
|
+
* return (
|
|
22
|
+
* <div>
|
|
23
|
+
* <h1>{translate('page.title')}</h1>
|
|
24
|
+
* <p>{translate('page.count', { params: { count: 5 } })}</p>
|
|
25
|
+
* <p>{translate('unknown.key', { fallback: 'Default Text' })}</p>
|
|
26
|
+
* </div>
|
|
27
|
+
* );
|
|
28
|
+
*/
|
|
29
|
+
export declare const useTranslations: (documentId?: string) => {
|
|
30
|
+
translate: (key: string, options?: {
|
|
31
|
+
params?: Record<string, string | number>;
|
|
32
|
+
fallback?: string;
|
|
33
|
+
}) => string;
|
|
34
|
+
locale: string;
|
|
35
|
+
};
|
|
36
|
+
export declare const useTranslation: (key: string, options?: {
|
|
37
|
+
params?: Record<string, string | number>;
|
|
38
|
+
fallback?: string;
|
|
39
|
+
}, documentId?: string) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Hook to get current locale
|
|
42
|
+
*/
|
|
43
|
+
export declare const useLocale: () => string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface TranslateProps {
|
|
2
|
+
k: string;
|
|
3
|
+
params?: Record<string, string | number>;
|
|
4
|
+
fallback?: string;
|
|
5
|
+
documentId?: string;
|
|
6
|
+
}
|
|
7
|
+
declare const Translate: import('svelte', { with: { "resolution-mode": "import" } }).Component<TranslateProps, {}, "">;
|
|
8
|
+
type Translate = ReturnType<typeof Translate>;
|
|
9
|
+
export default Translate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Translate } from './Translate.svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-i18n.svelte';
|