@embedpdf/plugin-i18n 2.15.0 → 3.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 +192 -21
- package/dist/index.cjs +268 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +159 -0
- package/dist/index.d.ts +159 -1
- package/dist/index.js +262 -397
- package/dist/index.js.map +1 -1
- package/package.json +18 -58
- package/dist/lib/actions.d.ts +0 -15
- package/dist/lib/i18n-plugin.d.ts +0 -28
- package/dist/lib/index.d.ts +0 -9
- package/dist/lib/locales/en.d.ts +0 -2
- package/dist/lib/locales/es.d.ts +0 -2
- package/dist/lib/locales/index.d.ts +0 -2
- package/dist/lib/manifest.d.ts +0 -4
- package/dist/lib/reducer.d.ts +0 -5
- package/dist/lib/types.d.ts +0 -104
- package/dist/preact/adapter.d.ts +0 -5
- package/dist/preact/core.d.ts +0 -1
- package/dist/preact/index.cjs +0 -2
- package/dist/preact/index.cjs.map +0 -1
- package/dist/preact/index.d.ts +0 -1
- package/dist/preact/index.js +0 -70
- package/dist/preact/index.js.map +0 -1
- package/dist/react/adapter.d.ts +0 -2
- package/dist/react/core.d.ts +0 -1
- package/dist/react/index.cjs +0 -2
- package/dist/react/index.cjs.map +0 -1
- package/dist/react/index.d.ts +0 -1
- package/dist/react/index.js +0 -69
- package/dist/react/index.js.map +0 -1
- package/dist/shared/components/index.d.ts +0 -1
- package/dist/shared/components/translate.d.ts +0 -35
- package/dist/shared/hooks/index.d.ts +0 -1
- package/dist/shared/hooks/use-i18n.d.ts +0 -43
- package/dist/shared/index.d.ts +0 -3
- package/dist/shared-preact/components/index.d.ts +0 -1
- package/dist/shared-preact/components/translate.d.ts +0 -35
- package/dist/shared-preact/hooks/index.d.ts +0 -1
- package/dist/shared-preact/hooks/use-i18n.d.ts +0 -43
- package/dist/shared-preact/index.d.ts +0 -3
- package/dist/shared-react/components/index.d.ts +0 -1
- package/dist/shared-react/components/translate.d.ts +0 -35
- package/dist/shared-react/hooks/index.d.ts +0 -1
- package/dist/shared-react/hooks/use-i18n.d.ts +0 -43
- package/dist/shared-react/index.d.ts +0 -3
- package/dist/svelte/components/Translate.svelte.d.ts +0 -9
- package/dist/svelte/components/index.d.ts +0 -1
- package/dist/svelte/hooks/index.d.ts +0 -1
- package/dist/svelte/hooks/use-i18n.svelte.d.ts +0 -41
- package/dist/svelte/index.cjs +0 -2
- package/dist/svelte/index.cjs.map +0 -1
- package/dist/svelte/index.d.ts +0 -3
- package/dist/svelte/index.js +0 -90
- package/dist/svelte/index.js.map +0 -1
- package/dist/vue/components/index.d.ts +0 -1
- package/dist/vue/components/translate.vue.d.ts +0 -9
- package/dist/vue/hooks/index.d.ts +0 -1
- package/dist/vue/hooks/use-i18n.d.ts +0 -30
- package/dist/vue/index.cjs +0 -2
- package/dist/vue/index.cjs.map +0 -1
- package/dist/vue/index.d.ts +0 -3
- package/dist/vue/index.js +0 -99
- package/dist/vue/index.js.map +0 -1
package/dist/react/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './translate';
|
|
@@ -1,35 +0,0 @@
|
|
|
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 {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './use-i18n';
|
|
@@ -1,43 +0,0 @@
|
|
|
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;
|
package/dist/shared/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './translate';
|
|
@@ -1,35 +0,0 @@
|
|
|
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 {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './use-i18n';
|
|
@@ -1,43 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './translate';
|
|
@@ -1,35 +0,0 @@
|
|
|
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 {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './use-i18n';
|
|
@@ -1,43 +0,0 @@
|
|
|
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;
|
|
@@ -1,9 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as Translate } from './Translate.svelte';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './use-i18n.svelte';
|
|
@@ -1,41 +0,0 @@
|
|
|
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 getDocumentId - Function that returns the document ID for document-scoped translations
|
|
17
|
-
* @returns translate function and current locale
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* const { translate, locale } = useTranslations(() => documentId);
|
|
21
|
-
* // In template:
|
|
22
|
-
* {translate('page.title')}
|
|
23
|
-
* {translate('page.count', { params: { count: 5 } })}
|
|
24
|
-
* {translate('unknown.key', { fallback: 'Default Text' })}
|
|
25
|
-
*/
|
|
26
|
-
export declare const useTranslations: (getDocumentId?: () => string | undefined) => {
|
|
27
|
-
translate: (key: string, options?: {
|
|
28
|
-
params?: Record<string, string | number>;
|
|
29
|
-
fallback?: string;
|
|
30
|
-
}) => string;
|
|
31
|
-
readonly locale: string;
|
|
32
|
-
};
|
|
33
|
-
export declare const useTranslation: (getKey: () => string, getOptions?: () => {
|
|
34
|
-
params?: Record<string, string | number>;
|
|
35
|
-
fallback?: string;
|
|
36
|
-
} | undefined, getDocumentId?: () => string | undefined) => {
|
|
37
|
-
readonly current: string;
|
|
38
|
-
};
|
|
39
|
-
export declare const useLocale: () => {
|
|
40
|
-
readonly current: string;
|
|
41
|
-
};
|
package/dist/svelte/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),t=require("@embedpdf/core/svelte"),r=require("@embedpdf/plugin-i18n");function n(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}require("svelte/internal/disclose-version");const o=n(e),a=()=>t.useCapability(r.I18nPlugin.id),l=e=>{const t=a();let r=o.state(0);const n=o.derived(()=>null==e?void 0:e());o.user_effect(()=>{const e=t.provides,a=o.get(n);if(!e)return;const l=e.onLocaleChange(()=>{o.update(r)}),s=a?e.forDocument(a).onParamsChanged(()=>{o.update(r)}):e.onParamsChanged(()=>{o.update(r)});return()=>{l(),s()}});return{translate:(n,a)=>{o.get(r);const l=t.provides;if(!l)return(null==a?void 0:a.fallback)??n;const s=null==e?void 0:e();return l.t(n,{documentId:s,params:null==a?void 0:a.params,fallback:null==a?void 0:a.fallback})},get locale(){var e;return(null==(e=t.provides)?void 0:e.getLocale())??"en"}}},s=(e,t,r)=>{const{translate:n}=l(r);return{get current(){return n(e(),null==t?void 0:t())}}};exports.Translate=function(e,t){o.push(t,!0);const r=s(()=>t.k,()=>({params:t.params,fallback:t.fallback}),()=>t.documentId);o.next();var n=o.text();o.template_effect(()=>o.set_text(n,r.current)),o.append(e,n),o.pop()},exports.useI18nCapability=a,exports.useI18nPlugin=()=>t.usePlugin(r.I18nPlugin.id),exports.useLocale=()=>{const e=a();let t=o.state("en");return o.user_effect(()=>{const r=e.provides;if(r)return o.set(t,r.getLocale(),!0),r.onLocaleChange(({currentLocale:e})=>{o.set(t,e,!0)})}),{get current(){return o.get(t)}}},exports.useTranslation=s,exports.useTranslations=l,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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-i18n.svelte.ts","../../src/svelte/components/Translate.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { I18nPlugin } from '@embedpdf/plugin-i18n';\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 getDocumentId - Function that returns the document ID for document-scoped translations\n * @returns translate function and current locale\n *\n * @example\n * const { translate, locale } = useTranslations(() => documentId);\n * // In template:\n * {translate('page.title')}\n * {translate('page.count', { params: { count: 5 } })}\n * {translate('unknown.key', { fallback: 'Default Text' })}\n */\nexport const useTranslations = (getDocumentId?: () => string | undefined) => {\n const capability = useI18nCapability();\n\n let forceUpdateCounter = $state(0);\n\n // Reactive documentId\n const documentId = $derived(getDocumentId?.());\n\n $effect(() => {\n const provides = capability.provides;\n const docId = documentId;\n\n if (!provides) return;\n\n // Subscribe to locale changes\n const unsubscribeLocale = provides.onLocaleChange(() => {\n forceUpdateCounter++;\n });\n\n // Subscribe to params changes\n const unsubscribeParams = docId\n ? provides.forDocument(docId).onParamsChanged(() => {\n forceUpdateCounter++;\n })\n : provides.onParamsChanged(() => {\n forceUpdateCounter++;\n });\n\n return () => {\n unsubscribeLocale();\n unsubscribeParams();\n };\n });\n\n // Create translate function\n const translate = (\n key: string,\n options?: {\n params?: Record<string, string | number>;\n fallback?: string;\n },\n ): string => {\n // Access forceUpdateCounter to trigger reactivity\n forceUpdateCounter;\n\n const provides = capability.provides;\n if (!provides) return options?.fallback ?? key;\n\n const docId = getDocumentId?.();\n return provides.t(key, {\n documentId: docId,\n params: options?.params,\n fallback: options?.fallback,\n });\n };\n\n return {\n translate,\n get locale() {\n return capability.provides?.getLocale() ?? 'en';\n },\n };\n};\n\n// Keep the old hook for single-key translations (useful for derived state)\nexport const useTranslation = (\n getKey: () => string,\n getOptions?: () =>\n | {\n params?: Record<string, string | number>;\n fallback?: string;\n }\n | undefined,\n getDocumentId?: () => string | undefined,\n) => {\n const { translate } = useTranslations(getDocumentId);\n\n return {\n get current() {\n return translate(getKey(), getOptions?.());\n },\n };\n};\n\nexport const useLocale = () => {\n const capability = useI18nCapability();\n\n let locale = $state<string>('en');\n\n $effect(() => {\n const provides = capability.provides;\n\n if (!provides) return;\n\n locale = provides.getLocale();\n\n return provides.onLocaleChange(({ currentLocale }) => {\n locale = currentLocale;\n });\n });\n\n return {\n get current() {\n return locale;\n },\n };\n};\n","<script lang=\"ts\">\n import { useTranslation } from '../hooks/use-i18n.svelte';\n\n interface TranslateProps {\n k: string;\n params?: Record<string, string | number>;\n fallback?: string;\n documentId?: string;\n }\n\n let { k, params, fallback, documentId }: TranslateProps = $props();\n\n const translation = useTranslation(\n () => k,\n () => ({ params, fallback }),\n () => documentId,\n );\n</script>\n\n{translation.current}\n"],"names":["useI18nCapability","useCapability","I18nPlugin","id","useTranslations","getDocumentId","capability","forceUpdateCounter","$","state","documentId","user_effect","provides","docId","unsubscribeLocale","onLocaleChange","unsubscribeParams","forDocument","onParamsChanged","translate","key","options","fallback","t","params","locale","_a","getLocale","useTranslation","getKey","getOptions","current","translation","$$props","k","template_effect","set_text","text","usePlugin","currentLocale","set"],"mappings":"ogBAGaA,EAAA,IAA0BC,gBAA0BC,EAAAA,WAAWC,IAiB/DC,EAAmBC,IACxB,MAAAC,EAAaN,QAEfO,EAAqBC,EAAAC,MAAO,GAG1B,MAAAC,gBAAsB,MAAAL,OAAA,EAAAA,KAE5BG,EAAAG,uBACQC,EAAWN,EAAWM,SACtBC,QAAQH,OAETE,EAAA,OAGC,MAAAE,EAAoBF,EAASG,6BACjCR,KAIIS,EAAoBH,EACtBD,EAASK,YAAYJ,GAAOK,8BAC1BX,KAEFK,EAASM,gBAAA,cACPX,gBAIJO,IACAE,cA2BFG,UAtBI,CACJC,EACAC,WAMAd,SAEMK,EAAWN,EAAWM,SACvB,IAAAA,EAAA,OAAiB,MAAAS,OAAA,EAAAA,EAASC,WAAYF,EAErC,MAAAP,EAAQ,MAAAR,OAAA,EAAAA,WACPO,EAASW,EAAEH,EAAA,CAChBV,WAAYG,EACZW,OAAQ,MAAAH,OAAA,EAAAA,EAASG,OACjBF,SAAU,MAAAD,OAAA,EAAAA,EAASC,YAMjB,UAAAG,SACK,OAAA,OAAAC,EAAApB,EAAWM,eAAX,EAAAc,EAAqBC,cAAe,IAC7C,IAKSC,GACXC,EACAC,EAMAzB,qBAEQc,GAAcf,EAAgBC,UAGhC,WAAA0B,UACKZ,EAAUU,IAAU,MAAAC,OAAA,EAAAA,IAC7B,iDCxFI,MAAAE,EAAcJ,EAAc,IAAAK,EAAAC,EAAA,MAEvBV,gBAAQF,SAAQW,EAAAX,WAAA,IAAAW,EAAAvB,oCAK5BF,EAAA2B,gBAAA,IAAA3B,EAAA4B,SAAAC,EAAAL,EAAYD,+BAFL,oDDbK,IAAsBO,YAAsBpC,EAAAA,WAAWC,2BAqG5D,MAAAG,EAAaN,QAEfyB,EAASjB,EAAAC,MAAe,aAE5BD,EAAAG,uBACQC,EAAWN,EAAWM,YAEvBA,EAIE,aAFPa,EAASb,EAASe,aAAA,GAEXf,EAASG,eAAA,EAAkBwB,oBAChC/B,EAAAgC,IAAAf,EAASc,GAAA,QAKP,WAAAR,gBACKN,EACT"}
|
package/dist/svelte/index.d.ts
DELETED
package/dist/svelte/index.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import * as $ from "svelte/internal/client";
|
|
2
|
-
import { useCapability, usePlugin } from "@embedpdf/core/svelte";
|
|
3
|
-
import { I18nPlugin } from "@embedpdf/plugin-i18n";
|
|
4
|
-
export * from "@embedpdf/plugin-i18n";
|
|
5
|
-
import "svelte/internal/disclose-version";
|
|
6
|
-
const useI18nCapability = () => useCapability(I18nPlugin.id);
|
|
7
|
-
const useI18nPlugin = () => usePlugin(I18nPlugin.id);
|
|
8
|
-
const useTranslations = (getDocumentId) => {
|
|
9
|
-
const capability = useI18nCapability();
|
|
10
|
-
let forceUpdateCounter = $.state(0);
|
|
11
|
-
const documentId = $.derived(() => getDocumentId == null ? void 0 : getDocumentId());
|
|
12
|
-
$.user_effect(() => {
|
|
13
|
-
const provides = capability.provides;
|
|
14
|
-
const docId = $.get(documentId);
|
|
15
|
-
if (!provides) return;
|
|
16
|
-
const unsubscribeLocale = provides.onLocaleChange(() => {
|
|
17
|
-
$.update(forceUpdateCounter);
|
|
18
|
-
});
|
|
19
|
-
const unsubscribeParams = docId ? provides.forDocument(docId).onParamsChanged(() => {
|
|
20
|
-
$.update(forceUpdateCounter);
|
|
21
|
-
}) : provides.onParamsChanged(() => {
|
|
22
|
-
$.update(forceUpdateCounter);
|
|
23
|
-
});
|
|
24
|
-
return () => {
|
|
25
|
-
unsubscribeLocale();
|
|
26
|
-
unsubscribeParams();
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
const translate = (key, options) => {
|
|
30
|
-
$.get(forceUpdateCounter);
|
|
31
|
-
const provides = capability.provides;
|
|
32
|
-
if (!provides) return (options == null ? void 0 : options.fallback) ?? key;
|
|
33
|
-
const docId = getDocumentId == null ? void 0 : getDocumentId();
|
|
34
|
-
return provides.t(key, {
|
|
35
|
-
documentId: docId,
|
|
36
|
-
params: options == null ? void 0 : options.params,
|
|
37
|
-
fallback: options == null ? void 0 : options.fallback
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
return {
|
|
41
|
-
translate,
|
|
42
|
-
get locale() {
|
|
43
|
-
var _a;
|
|
44
|
-
return ((_a = capability.provides) == null ? void 0 : _a.getLocale()) ?? "en";
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
const useTranslation = (getKey, getOptions, getDocumentId) => {
|
|
49
|
-
const { translate } = useTranslations(getDocumentId);
|
|
50
|
-
return {
|
|
51
|
-
get current() {
|
|
52
|
-
return translate(getKey(), getOptions == null ? void 0 : getOptions());
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
const useLocale = () => {
|
|
57
|
-
const capability = useI18nCapability();
|
|
58
|
-
let locale = $.state("en");
|
|
59
|
-
$.user_effect(() => {
|
|
60
|
-
const provides = capability.provides;
|
|
61
|
-
if (!provides) return;
|
|
62
|
-
$.set(locale, provides.getLocale(), true);
|
|
63
|
-
return provides.onLocaleChange(({ currentLocale }) => {
|
|
64
|
-
$.set(locale, currentLocale, true);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
return {
|
|
68
|
-
get current() {
|
|
69
|
-
return $.get(locale);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
function Translate($$anchor, $$props) {
|
|
74
|
-
$.push($$props, true);
|
|
75
|
-
const translation = useTranslation(() => $$props.k, () => ({ params: $$props.params, fallback: $$props.fallback }), () => $$props.documentId);
|
|
76
|
-
$.next();
|
|
77
|
-
var text = $.text();
|
|
78
|
-
$.template_effect(() => $.set_text(text, translation.current));
|
|
79
|
-
$.append($$anchor, text);
|
|
80
|
-
$.pop();
|
|
81
|
-
}
|
|
82
|
-
export {
|
|
83
|
-
Translate,
|
|
84
|
-
useI18nCapability,
|
|
85
|
-
useI18nPlugin,
|
|
86
|
-
useLocale,
|
|
87
|
-
useTranslation,
|
|
88
|
-
useTranslations
|
|
89
|
-
};
|
|
90
|
-
//# sourceMappingURL=index.js.map
|
package/dist/svelte/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-i18n.svelte.ts","../../src/svelte/components/Translate.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { I18nPlugin } from '@embedpdf/plugin-i18n';\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 getDocumentId - Function that returns the document ID for document-scoped translations\n * @returns translate function and current locale\n *\n * @example\n * const { translate, locale } = useTranslations(() => documentId);\n * // In template:\n * {translate('page.title')}\n * {translate('page.count', { params: { count: 5 } })}\n * {translate('unknown.key', { fallback: 'Default Text' })}\n */\nexport const useTranslations = (getDocumentId?: () => string | undefined) => {\n const capability = useI18nCapability();\n\n let forceUpdateCounter = $state(0);\n\n // Reactive documentId\n const documentId = $derived(getDocumentId?.());\n\n $effect(() => {\n const provides = capability.provides;\n const docId = documentId;\n\n if (!provides) return;\n\n // Subscribe to locale changes\n const unsubscribeLocale = provides.onLocaleChange(() => {\n forceUpdateCounter++;\n });\n\n // Subscribe to params changes\n const unsubscribeParams = docId\n ? provides.forDocument(docId).onParamsChanged(() => {\n forceUpdateCounter++;\n })\n : provides.onParamsChanged(() => {\n forceUpdateCounter++;\n });\n\n return () => {\n unsubscribeLocale();\n unsubscribeParams();\n };\n });\n\n // Create translate function\n const translate = (\n key: string,\n options?: {\n params?: Record<string, string | number>;\n fallback?: string;\n },\n ): string => {\n // Access forceUpdateCounter to trigger reactivity\n forceUpdateCounter;\n\n const provides = capability.provides;\n if (!provides) return options?.fallback ?? key;\n\n const docId = getDocumentId?.();\n return provides.t(key, {\n documentId: docId,\n params: options?.params,\n fallback: options?.fallback,\n });\n };\n\n return {\n translate,\n get locale() {\n return capability.provides?.getLocale() ?? 'en';\n },\n };\n};\n\n// Keep the old hook for single-key translations (useful for derived state)\nexport const useTranslation = (\n getKey: () => string,\n getOptions?: () =>\n | {\n params?: Record<string, string | number>;\n fallback?: string;\n }\n | undefined,\n getDocumentId?: () => string | undefined,\n) => {\n const { translate } = useTranslations(getDocumentId);\n\n return {\n get current() {\n return translate(getKey(), getOptions?.());\n },\n };\n};\n\nexport const useLocale = () => {\n const capability = useI18nCapability();\n\n let locale = $state<string>('en');\n\n $effect(() => {\n const provides = capability.provides;\n\n if (!provides) return;\n\n locale = provides.getLocale();\n\n return provides.onLocaleChange(({ currentLocale }) => {\n locale = currentLocale;\n });\n });\n\n return {\n get current() {\n return locale;\n },\n };\n};\n","<script lang=\"ts\">\n import { useTranslation } from '../hooks/use-i18n.svelte';\n\n interface TranslateProps {\n k: string;\n params?: Record<string, string | number>;\n fallback?: string;\n documentId?: string;\n }\n\n let { k, params, fallback, documentId }: TranslateProps = $props();\n\n const translation = useTranslation(\n () => k,\n () => ({ params, fallback }),\n () => documentId,\n );\n</script>\n\n{translation.current}\n"],"names":[],"mappings":";;;;;AAGa,MAAA,oBAAA,MAA0B,cAA0B,WAAW,EAAE;AACjE,MAAA,gBAAA,MAAsB,UAAsB,WAAW,EAAE;MAgBzD,kBAAA,CAAmB,kBAA6C;AACrE,QAAA,aAAa,kBAAA;MAEf,qBAAqB,EAAA,MAAO,CAAC;AAG3B,QAAA,6BAAsB,gDAAA;AAE5B,IAAA,kBAAc;UACN,WAAW,WAAW;AACtB,UAAA,cAAQ,UAAA;SAET,SAAA;AAGC,UAAA,oBAAoB,SAAS,qBAAqB;eACtD,kBAAA;AAAA,IACF,CAAC;AAGK,UAAA,oBAAoB,QACtB,SAAS,YAAY,KAAK,EAAE,sBAAsB;eAChD,kBAAA;AAAA,IACF,CAAC,IACD,SAAS,gBAAA,MAAsB;eAC7B,kBAAA;AAAA,IACF,CAAC;iBAEQ;AACX,wBAAA;AACA,wBAAA;AAAA,IACF;AAAA,EACF,CAAC;AAGK,QAAA,YAAA,CACJ,KACA,YAIW;UAEX,kBAAA;UAEM,WAAW,WAAW;AACvB,QAAA,CAAA,SAAA,SAAiB,mCAAS,aAAY;AAErC,UAAA,QAAQ;WACP,SAAS,EAAE,KAAA;AAAA,MAChB,YAAY;AAAA,MACZ,QAAQ,mCAAS;AAAA,MACjB,UAAU,mCAAS;AAAA;EAEvB;;IAGE;AAAA,IACI,IAAA,SAAS;;AACJ,eAAA,gBAAW,aAAX,mBAAqB,gBAAe;AAAA,IAC7C;AAAA;AAEJ;AAGa,MAAA,kBACX,QACA,YAMA,kBACG;UACK,UAAA,IAAc,gBAAgB,aAAa;;IAG7C,IAAA,UAAU;aACL,UAAU,UAAU,0CAAA;AAAA,IAC7B;AAAA;AAEJ;AAEa,MAAA,kBAAkB;AACvB,QAAA,aAAa,kBAAA;MAEf,SAAS,EAAA,MAAe,IAAI;AAEhC,IAAA,kBAAc;UACN,WAAW,WAAW;SAEvB,SAAA;UAEL,QAAS,SAAS,UAAA,GAAA,IAAA;AAEX,WAAA,SAAS,eAAA,CAAA,EAAkB,oBAAoB;AACpD,QAAA,IAAA,QAAS,eAAA,IAAA;AAAA,IACX,CAAC;AAAA,EACH,CAAC;;IAGK,IAAA,UAAU;mBACL,MAAA;AAAA,IACT;AAAA;AAEJ;sCC9HA;;AAYQ,QAAA,cAAc,eAAc,MAAA,QAAA,GAAA,OAAA,EAEvB,wBAAQ,UAAQ,QAAA,SAAA,IAAA,MAAA,QAAA,UAAA;;;AAK5B,IAAA,gBAAA,MAAA,EAAA,SAAA,MAAA,YAAY,OAAO,CAAA;;;AAFZ;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as Translate } from './translate.vue';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
interface TranslateProps {
|
|
2
|
-
k: string;
|
|
3
|
-
params?: Record<string, string | number>;
|
|
4
|
-
fallback?: string;
|
|
5
|
-
documentId?: string;
|
|
6
|
-
}
|
|
7
|
-
declare const __VLS_export: import('vue').DefineComponent<TranslateProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<TranslateProps> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
8
|
-
declare const _default: typeof __VLS_export;
|
|
9
|
-
export default _default;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './use-i18n';
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { MaybeRefOrGetter } from 'vue';
|
|
2
|
-
import { I18nPlugin } from '../../lib/index.ts';
|
|
3
|
-
export declare const useI18nCapability: () => import('@embedpdf/core/vue').CapabilityState<Readonly<import('../../lib/index.ts').I18nCapability>>;
|
|
4
|
-
export declare const useI18nPlugin: () => import('@embedpdf/core/vue').PluginState<I18nPlugin>;
|
|
5
|
-
/**
|
|
6
|
-
* Hook to get a translate function for a component
|
|
7
|
-
* Automatically updates all translations on locale or param changes
|
|
8
|
-
*
|
|
9
|
-
* @param documentId - Optional document ID for document-scoped translations (can be ref, computed, getter, or plain value)
|
|
10
|
-
* @returns translate function and current locale
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* const { translate, locale } = useTranslations(documentId);
|
|
14
|
-
* // In template:
|
|
15
|
-
* {{ translate('page.title') }}
|
|
16
|
-
* {{ translate('page.count', { params: { count: 5 } }) }}
|
|
17
|
-
* {{ translate('unknown.key', { fallback: 'Default Text' }) }}
|
|
18
|
-
*/
|
|
19
|
-
export declare const useTranslations: (documentId?: MaybeRefOrGetter<string | undefined>) => {
|
|
20
|
-
translate: (key: string, options?: {
|
|
21
|
-
params?: Record<string, string | number>;
|
|
22
|
-
fallback?: string;
|
|
23
|
-
}) => string;
|
|
24
|
-
locale: Readonly<import('vue').Ref<string, string>>;
|
|
25
|
-
};
|
|
26
|
-
export declare const useTranslation: (key: string, options?: {
|
|
27
|
-
params?: Record<string, string | number>;
|
|
28
|
-
fallback?: string;
|
|
29
|
-
}, documentId?: MaybeRefOrGetter<string | undefined>) => import('vue').ComputedRef<string>;
|
|
30
|
-
export declare const useLocale: () => import('vue').Ref<string, string>;
|
package/dist/vue/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),a=require("@embedpdf/core/vue"),t=require("@embedpdf/plugin-i18n"),n=()=>a.useCapability(t.I18nPlugin.id),r=a=>{const{provides:t}=n(),r=e.ref(0);e.watch([t,()=>a?e.toValue(a):void 0],([e,a],t,n)=>{if(!e)return;const l=e.onLocaleChange(()=>{r.value++}),o=a?e.forDocument(a).onParamsChanged(()=>{r.value++}):e.onParamsChanged(()=>{r.value++});n(()=>{l(),o()})},{immediate:!0});const l=e.computed(()=>{var e;return r.value,(null==(e=t.value)?void 0:e.getLocale())??"en"});return{translate:(n,l)=>{r.value;const o=t.value;if(!o)return(null==l?void 0:l.fallback)??n;const u=a?e.toValue(a):void 0;return o.t(n,{documentId:u,params:null==l?void 0:l.params,fallback:null==l?void 0:l.fallback})},locale:e.readonly(l)}},l=(a,t,n)=>{const{translate:l}=r(n);return e.computed(()=>l(a,t))},o=e.defineComponent({__name:"translate",props:{k:{},params:{},fallback:{},documentId:{}},setup(a){const t=a,n=l(t.k,{params:t.params,fallback:t.fallback},()=>t.documentId);return(a,t)=>(e.openBlock(),e.createElementBlock("span",null,e.toDisplayString(e.unref(n)),1))}});exports.Translate=o,exports.useI18nCapability=n,exports.useI18nPlugin=()=>a.usePlugin(t.I18nPlugin.id),exports.useLocale=()=>{const{provides:a}=n(),t=e.ref("en");return e.watch(a,(e,a,n)=>{if(!e)return;t.value=e.getLocale();n(e.onLocaleChange(({currentLocale:e})=>{t.value=e}))},{immediate:!0}),t},exports.useTranslation=l,exports.useTranslations=r,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/vue/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-i18n.ts","../../src/vue/components/translate.vue"],"sourcesContent":["import { ref, watch, computed, readonly, toValue, MaybeRefOrGetter } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { I18nPlugin } from '@embedpdf/plugin-i18n';\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 (can be ref, computed, getter, or plain value)\n * @returns translate function and current locale\n *\n * @example\n * const { translate, locale } = useTranslations(documentId);\n * // In template:\n * {{ translate('page.title') }}\n * {{ translate('page.count', { params: { count: 5 } }) }}\n * {{ translate('unknown.key', { fallback: 'Default Text' }) }}\n */\nexport const useTranslations = (documentId?: MaybeRefOrGetter<string | undefined>) => {\n const { provides } = useI18nCapability();\n const forceUpdateCounter = ref(0);\n\n // Watch for locale and params changes\n watch(\n [provides, () => (documentId ? toValue(documentId) : undefined)],\n ([providesValue, docId], _, onCleanup) => {\n if (!providesValue) return;\n\n // Subscribe to locale changes\n const unsubscribeLocale = providesValue.onLocaleChange(() => {\n forceUpdateCounter.value++;\n });\n\n // Subscribe to params changes\n const unsubscribeParams = docId\n ? providesValue.forDocument(docId).onParamsChanged(() => {\n forceUpdateCounter.value++;\n })\n : providesValue.onParamsChanged(() => {\n forceUpdateCounter.value++;\n });\n\n onCleanup(() => {\n unsubscribeLocale();\n unsubscribeParams();\n });\n },\n { immediate: true },\n );\n\n // Create translate function\n const translate = (\n key: string,\n options?: {\n params?: Record<string, string | number>;\n fallback?: string;\n },\n ): string => {\n // Access forceUpdateCounter to trigger reactivity\n forceUpdateCounter.value;\n\n const providesValue = provides.value;\n if (!providesValue) return options?.fallback ?? key;\n\n const docId = documentId ? toValue(documentId) : undefined;\n return providesValue.t(key, {\n documentId: docId,\n params: options?.params,\n fallback: options?.fallback,\n });\n };\n\n const locale = computed(() => {\n // Access forceUpdateCounter to trigger reactivity when locale changes\n forceUpdateCounter.value;\n return provides.value?.getLocale() ?? 'en';\n });\n\n return {\n translate,\n locale: readonly(locale),\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?: MaybeRefOrGetter<string | undefined>,\n) => {\n const { translate } = useTranslations(documentId);\n return computed(() => translate(key, options));\n};\n\nexport const useLocale = () => {\n const { provides } = useI18nCapability();\n const locale = ref<string>('en');\n\n watch(\n provides,\n (providesValue, _, onCleanup) => {\n if (!providesValue) return;\n\n locale.value = providesValue.getLocale();\n\n const unsubscribe = providesValue.onLocaleChange(({ currentLocale }) => {\n locale.value = currentLocale;\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n );\n\n return locale;\n};\n","<script setup lang=\"ts\">\nimport { useTranslation } from '../hooks/use-i18n';\n\ninterface TranslateProps {\n k: string;\n params?: Record<string, string | number>;\n fallback?: string;\n documentId?: string;\n}\n\nconst props = defineProps<TranslateProps>();\nconst translation = useTranslation(\n props.k,\n { params: props.params, fallback: props.fallback },\n () => props.documentId,\n);\n</script>\n\n<template>\n <span>{{ translation }}</span>\n</template>\n"],"names":["useI18nCapability","useCapability","I18nPlugin","id","useTranslations","documentId","provides","forceUpdateCounter","ref","watch","toValue","providesValue","docId","_","onCleanup","unsubscribeLocale","onLocaleChange","value","unsubscribeParams","forDocument","onParamsChanged","immediate","locale","computed","_a","getLocale","translate","key","options","fallback","t","params","readonly","useTranslation","props","__props","translation","k","_openBlock","_createElementBlock","_unref","usePlugin","currentLocale"],"mappings":"0KAIaA,EAAoB,IAAMC,gBAA0BC,EAAAA,WAAWC,IAiB/DC,EAAmBC,IAC9B,MAAMC,SAAEA,GAAaN,IACfO,EAAqBC,EAAAA,IAAI,GAG/BC,EAAAA,MACE,CAACH,EAAU,IAAOD,EAAaK,EAAAA,QAAQL,QAAc,GACrD,EAAEM,EAAeC,GAAQC,EAAGC,KAC1B,IAAKH,EAAe,OAGpB,MAAMI,EAAoBJ,EAAcK,eAAe,KACrDT,EAAmBU,UAIfC,EAAoBN,EACtBD,EAAcQ,YAAYP,GAAOQ,gBAAgB,KAC/Cb,EAAmBU,UAErBN,EAAcS,gBAAgB,KAC5Bb,EAAmBU,UAGzBH,EAAU,KACRC,IACAG,OAGJ,CAAEG,WAAW,IAIf,MAqBMC,EAASC,EAAAA,SAAS,WAGtB,OADAhB,EAAmBU,OACZ,OAAAO,EAAAlB,EAASW,YAAT,EAAAO,EAAgBC,cAAe,OAGxC,MAAO,CACLC,UA5BgB,CAChBC,EACAC,KAMArB,EAAmBU,MAEnB,MAAMN,EAAgBL,EAASW,MAC/B,IAAKN,EAAe,OAAO,MAAAiB,OAAA,EAAAA,EAASC,WAAYF,EAEhD,MAAMf,EAAQP,EAAaK,UAAQL,QAAc,EACjD,OAAOM,EAAcmB,EAAEH,EAAK,CAC1BtB,WAAYO,EACZmB,OAAQ,MAAAH,OAAA,EAAAA,EAASG,OACjBF,SAAU,MAAAD,OAAA,EAAAA,EAASC,YAYrBP,OAAQU,EAAAA,SAASV,KAKRW,EAAiB,CAC5BN,EACAC,EAIAvB,KAEA,MAAMqB,UAAEA,GAActB,EAAgBC,GACtC,OAAOkB,EAAAA,SAAS,IAAMG,EAAUC,EAAKC,uGCvFvC,MAAMM,EAAQC,EACRC,EAAcH,EAClBC,EAAMG,EACN,CAAEN,OAAQG,EAAMH,OAAQF,SAAUK,EAAML,UACxC,IAAMK,EAAM7B,0BAKZiC,EAAAA,YAAAC,EAAAA,mBAA8B,8BAArBC,QAAAJ,IAAW,6EDdO,IAAMK,YAAsBvC,EAAAA,WAAWC,sBA+F3C,KACvB,MAAMG,SAAEA,GAAaN,IACfsB,EAASd,EAAAA,IAAY,MAkB3B,OAhBAC,EAAAA,MACEH,EACA,CAACK,EAAeE,EAAGC,KACjB,IAAKH,EAAe,OAEpBW,EAAOL,MAAQN,EAAcc,YAM7BX,EAJoBH,EAAcK,eAAe,EAAG0B,oBAClDpB,EAAOL,MAAQyB,MAKnB,CAAErB,WAAW,IAGRC"}
|
package/dist/vue/index.d.ts
DELETED