@weglot/translate-react 0.0.0-stage → 0.1.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 +202 -0
- package/NOTICE +6 -0
- package/README.md +190 -2
- package/build/_virtual/rolldown_runtime.cjs +29 -0
- package/build/_virtual/rolldown_runtime.mjs +7 -0
- package/build/index.cjs +0 -0
- package/build/index.d.cts +2 -0
- package/build/index.d.mts +2 -0
- package/build/index.mjs +1 -0
- package/build/locale.d.cts +6 -0
- package/build/locale.d.cts.map +1 -0
- package/build/locale.d.mts +6 -0
- package/build/locale.d.mts.map +1 -0
- package/build/metadata/manager.cjs +119 -0
- package/build/metadata/manager.mjs +114 -0
- package/build/metadata/manager.mjs.map +1 -0
- package/build/plugin/build-translator.cjs +207 -0
- package/build/plugin/build-translator.mjs +205 -0
- package/build/plugin/build-translator.mjs.map +1 -0
- package/build/plugin/cleanup.cjs +20 -0
- package/build/plugin/cleanup.mjs +20 -0
- package/build/plugin/cleanup.mjs.map +1 -0
- package/build/plugin/index.cjs +0 -0
- package/build/plugin/index.d.cts +2 -0
- package/build/plugin/index.d.mts +2 -0
- package/build/plugin/index.mjs +1 -0
- package/build/plugin/next-compiler-loader.cjs +40 -0
- package/build/plugin/next-compiler-loader.d.cts +12 -0
- package/build/plugin/next-compiler-loader.d.cts.map +1 -0
- package/build/plugin/next-compiler-loader.d.mts +13 -0
- package/build/plugin/next-compiler-loader.d.mts.map +1 -0
- package/build/plugin/next-compiler-loader.mjs +41 -0
- package/build/plugin/next-compiler-loader.mjs.map +1 -0
- package/build/plugin/next-config-loader.cjs +13 -0
- package/build/plugin/next-config-loader.d.cts +8 -0
- package/build/plugin/next-config-loader.d.cts.map +1 -0
- package/build/plugin/next-config-loader.d.mts +9 -0
- package/build/plugin/next-config-loader.d.mts.map +1 -0
- package/build/plugin/next-config-loader.mjs +14 -0
- package/build/plugin/next-config-loader.mjs.map +1 -0
- package/build/plugin/next-locale-client-loader.cjs +9 -0
- package/build/plugin/next-locale-client-loader.d.cts +8 -0
- package/build/plugin/next-locale-client-loader.d.cts.map +1 -0
- package/build/plugin/next-locale-client-loader.d.mts +9 -0
- package/build/plugin/next-locale-client-loader.d.mts.map +1 -0
- package/build/plugin/next-locale-client-loader.mjs +10 -0
- package/build/plugin/next-locale-client-loader.mjs.map +1 -0
- package/build/plugin/next-locale-server-loader.cjs +9 -0
- package/build/plugin/next-locale-server-loader.d.cts +8 -0
- package/build/plugin/next-locale-server-loader.d.cts.map +1 -0
- package/build/plugin/next-locale-server-loader.d.mts +9 -0
- package/build/plugin/next-locale-server-loader.d.mts.map +1 -0
- package/build/plugin/next-locale-server-loader.mjs +10 -0
- package/build/plugin/next-locale-server-loader.mjs.map +1 -0
- package/build/plugin/next.cjs +226 -0
- package/build/plugin/next.d.cts +9 -0
- package/build/plugin/next.d.cts.map +1 -0
- package/build/plugin/next.d.mts +9 -0
- package/build/plugin/next.d.mts.map +1 -0
- package/build/plugin/next.mjs +228 -0
- package/build/plugin/next.mjs.map +1 -0
- package/build/plugin/transform/babel-compat.cjs +13 -0
- package/build/plugin/transform/babel-compat.mjs +10 -0
- package/build/plugin/transform/babel-compat.mjs.map +1 -0
- package/build/plugin/transform/expression-strings.cjs +145 -0
- package/build/plugin/transform/expression-strings.mjs +140 -0
- package/build/plugin/transform/expression-strings.mjs.map +1 -0
- package/build/plugin/transform/index.cjs +45 -0
- package/build/plugin/transform/index.mjs +43 -0
- package/build/plugin/transform/index.mjs.map +1 -0
- package/build/plugin/transform/metadata.cjs +142 -0
- package/build/plugin/transform/metadata.mjs +141 -0
- package/build/plugin/transform/metadata.mjs.map +1 -0
- package/build/plugin/transform/process-file.cjs +525 -0
- package/build/plugin/transform/process-file.mjs +524 -0
- package/build/plugin/transform/process-file.mjs.map +1 -0
- package/build/plugin/transform/use-i18n.cjs +8 -0
- package/build/plugin/transform/use-i18n.mjs +7 -0
- package/build/plugin/transform/use-i18n.mjs.map +1 -0
- package/build/plugin/transform/utils.cjs +237 -0
- package/build/plugin/transform/utils.mjs +219 -0
- package/build/plugin/transform/utils.mjs.map +1 -0
- package/build/plugin/unplugin.cjs +188 -0
- package/build/plugin/unplugin.d.cts +8 -0
- package/build/plugin/unplugin.d.cts.map +1 -0
- package/build/plugin/unplugin.d.mts +8 -0
- package/build/plugin/unplugin.d.mts.map +1 -0
- package/build/plugin/unplugin.mjs +188 -0
- package/build/plugin/unplugin.mjs.map +1 -0
- package/build/plugin/vite.cjs +27 -0
- package/build/plugin/vite.d.cts +9 -0
- package/build/plugin/vite.d.cts.map +1 -0
- package/build/plugin/vite.d.mts +9 -0
- package/build/plugin/vite.d.mts.map +1 -0
- package/build/plugin/vite.mjs +28 -0
- package/build/plugin/vite.mjs.map +1 -0
- package/build/plugin/webpack.cjs +26 -0
- package/build/plugin/webpack.d.cts +8 -0
- package/build/plugin/webpack.d.cts.map +1 -0
- package/build/plugin/webpack.d.mts +8 -0
- package/build/plugin/webpack.d.mts.map +1 -0
- package/build/plugin/webpack.mjs +27 -0
- package/build/plugin/webpack.mjs.map +1 -0
- package/build/react/client/index.cjs +9 -0
- package/build/react/client/index.d.cts +5 -0
- package/build/react/client/index.d.mts +5 -0
- package/build/react/client/index.mjs +6 -0
- package/build/react/client/useTranslation.cjs +71 -0
- package/build/react/client/useTranslation.d.cts +42 -0
- package/build/react/client/useTranslation.d.cts.map +1 -0
- package/build/react/client/useTranslation.d.mts +42 -0
- package/build/react/client/useTranslation.d.mts.map +1 -0
- package/build/react/client/useTranslation.mjs +71 -0
- package/build/react/client/useTranslation.mjs.map +1 -0
- package/build/react/next/client.cjs +25 -0
- package/build/react/next/client.d.cts +9 -0
- package/build/react/next/client.d.cts.map +1 -0
- package/build/react/next/client.d.mts +9 -0
- package/build/react/next/client.d.mts.map +1 -0
- package/build/react/next/client.mjs +24 -0
- package/build/react/next/client.mjs.map +1 -0
- package/build/react/next/cookie-locale-resolver.cjs +29 -0
- package/build/react/next/cookie-locale-resolver.d.cts +33 -0
- package/build/react/next/cookie-locale-resolver.d.cts.map +1 -0
- package/build/react/next/cookie-locale-resolver.d.mts +33 -0
- package/build/react/next/cookie-locale-resolver.d.mts.map +1 -0
- package/build/react/next/cookie-locale-resolver.mjs +29 -0
- package/build/react/next/cookie-locale-resolver.mjs.map +1 -0
- package/build/react/next/server.cjs +21 -0
- package/build/react/next/server.d.cts +13 -0
- package/build/react/next/server.d.cts.map +1 -0
- package/build/react/next/server.d.mts +14 -0
- package/build/react/next/server.d.mts.map +1 -0
- package/build/react/next/server.mjs +20 -0
- package/build/react/next/server.mjs.map +1 -0
- package/build/react/server/ServerWeglotProvider.cjs +19 -0
- package/build/react/server/ServerWeglotProvider.d.cts +12 -0
- package/build/react/server/ServerWeglotProvider.d.cts.map +1 -0
- package/build/react/server/ServerWeglotProvider.d.mts +12 -0
- package/build/react/server/ServerWeglotProvider.d.mts.map +1 -0
- package/build/react/server/ServerWeglotProvider.mjs +19 -0
- package/build/react/server/ServerWeglotProvider.mjs.map +1 -0
- package/build/react/server/index.cjs +7 -0
- package/build/react/server/index.d.cts +4 -0
- package/build/react/server/index.d.mts +4 -0
- package/build/react/server/index.mjs +5 -0
- package/build/react/server/useTranslation.cjs +60 -0
- package/build/react/server/useTranslation.d.cts +36 -0
- package/build/react/server/useTranslation.d.cts.map +1 -0
- package/build/react/server/useTranslation.d.mts +36 -0
- package/build/react/server/useTranslation.d.mts.map +1 -0
- package/build/react/server/useTranslation.mjs +60 -0
- package/build/react/server/useTranslation.mjs.map +1 -0
- package/build/react/server-only/index.cjs +42 -0
- package/build/react/server-only/index.d.cts +38 -0
- package/build/react/server-only/index.d.cts.map +1 -0
- package/build/react/server-only/index.d.mts +38 -0
- package/build/react/server-only/index.d.mts.map +1 -0
- package/build/react/server-only/index.mjs +42 -0
- package/build/react/server-only/index.mjs.map +1 -0
- package/build/react/server-only/translations.cjs +86 -0
- package/build/react/server-only/translations.mjs +86 -0
- package/build/react/server-only/translations.mjs.map +1 -0
- package/build/react/shared/LocaleSwitcher.cjs +61 -0
- package/build/react/shared/LocaleSwitcher.d.cts +71 -0
- package/build/react/shared/LocaleSwitcher.d.cts.map +1 -0
- package/build/react/shared/LocaleSwitcher.d.mts +71 -0
- package/build/react/shared/LocaleSwitcher.d.mts.map +1 -0
- package/build/react/shared/LocaleSwitcher.mjs +61 -0
- package/build/react/shared/LocaleSwitcher.mjs.map +1 -0
- package/build/react/shared/WeglotContext.cjs +14 -0
- package/build/react/shared/WeglotContext.d.cts +34 -0
- package/build/react/shared/WeglotContext.d.cts.map +1 -0
- package/build/react/shared/WeglotContext.d.mts +34 -0
- package/build/react/shared/WeglotContext.d.mts.map +1 -0
- package/build/react/shared/WeglotContext.mjs +13 -0
- package/build/react/shared/WeglotContext.mjs.map +1 -0
- package/build/react/shared/WeglotProvider.cjs +250 -0
- package/build/react/shared/WeglotProvider.d.cts +60 -0
- package/build/react/shared/WeglotProvider.d.cts.map +1 -0
- package/build/react/shared/WeglotProvider.d.mts +60 -0
- package/build/react/shared/WeglotProvider.d.mts.map +1 -0
- package/build/react/shared/WeglotProvider.mjs +250 -0
- package/build/react/shared/WeglotProvider.mjs.map +1 -0
- package/build/react/shared/render-rich-text.cjs +56 -0
- package/build/react/shared/render-rich-text.d.cts +16 -0
- package/build/react/shared/render-rich-text.d.cts.map +1 -0
- package/build/react/shared/render-rich-text.d.mts +16 -0
- package/build/react/shared/render-rich-text.d.mts.map +1 -0
- package/build/react/shared/render-rich-text.mjs +55 -0
- package/build/react/shared/render-rich-text.mjs.map +1 -0
- package/build/react/shared/utils.cjs +34 -0
- package/build/react/shared/utils.mjs +35 -0
- package/build/react/shared/utils.mjs.map +1 -0
- package/build/react/types.d.cts +16 -0
- package/build/react/types.d.cts.map +1 -0
- package/build/react/types.d.mts +16 -0
- package/build/react/types.d.mts.map +1 -0
- package/build/runtime/html/segmenter.cjs +226 -0
- package/build/runtime/html/segmenter.mjs +225 -0
- package/build/runtime/html/segmenter.mjs.map +1 -0
- package/build/runtime/index.cjs +6 -0
- package/build/runtime/index.d.cts +2 -0
- package/build/runtime/index.d.mts +2 -0
- package/build/runtime/index.mjs +3 -0
- package/build/runtime/translate-dynamic.cjs +142 -0
- package/build/runtime/translate-dynamic.d.cts +29 -0
- package/build/runtime/translate-dynamic.d.cts.map +1 -0
- package/build/runtime/translate-dynamic.d.mts +29 -0
- package/build/runtime/translate-dynamic.d.mts.map +1 -0
- package/build/runtime/translate-dynamic.mjs +139 -0
- package/build/runtime/translate-dynamic.mjs.map +1 -0
- package/build/translation-server/logger.cjs +37 -0
- package/build/translation-server/logger.mjs +37 -0
- package/build/translation-server/logger.mjs.map +1 -0
- package/build/translation-server/translation-server.cjs +451 -0
- package/build/translation-server/translation-server.mjs +448 -0
- package/build/translation-server/translation-server.mjs.map +1 -0
- package/build/translators/api.cjs +12 -0
- package/build/translators/api.mjs +12 -0
- package/build/translators/api.mjs.map +1 -0
- package/build/translators/cache-factory.cjs +26 -0
- package/build/translators/cache-factory.mjs +27 -0
- package/build/translators/cache-factory.mjs.map +1 -0
- package/build/translators/local-cache.cjs +132 -0
- package/build/translators/local-cache.mjs +130 -0
- package/build/translators/local-cache.mjs.map +1 -0
- package/build/translators/translation-service.cjs +137 -0
- package/build/translators/translation-service.mjs +138 -0
- package/build/translators/translation-service.mjs.map +1 -0
- package/build/translators/weglot/api-client.cjs +79 -0
- package/build/translators/weglot/api-client.mjs +79 -0
- package/build/translators/weglot/api-client.mjs.map +1 -0
- package/build/translators/weglot/definitions/definitions.generated.cjs +53 -0
- package/build/translators/weglot/definitions/definitions.generated.mjs +52 -0
- package/build/translators/weglot/definitions/definitions.generated.mjs.map +1 -0
- package/build/translators/weglot/engine.cjs +46 -0
- package/build/translators/weglot/engine.mjs +43 -0
- package/build/translators/weglot/engine.mjs.map +1 -0
- package/build/translators/weglot/translator.cjs +61 -0
- package/build/translators/weglot/translator.mjs +62 -0
- package/build/translators/weglot/translator.mjs.map +1 -0
- package/build/translators/weglot/wire-format.cjs +128 -0
- package/build/translators/weglot/wire-format.mjs +129 -0
- package/build/translators/weglot/wire-format.mjs.map +1 -0
- package/build/types.d.cts +143 -0
- package/build/types.d.cts.map +1 -0
- package/build/types.d.mts +143 -0
- package/build/types.d.mts.map +1 -0
- package/build/utils/config-factory.cjs +86 -0
- package/build/utils/config-factory.mjs +83 -0
- package/build/utils/config-factory.mjs.map +1 -0
- package/build/utils/hash.cjs +17 -0
- package/build/utils/hash.mjs +16 -0
- package/build/utils/hash.mjs.map +1 -0
- package/build/utils/is-valid-locale.cjs +13 -0
- package/build/utils/is-valid-locale.mjs +13 -0
- package/build/utils/is-valid-locale.mjs.map +1 -0
- package/build/utils/logger.cjs +51 -0
- package/build/utils/logger.mjs +50 -0
- package/build/utils/logger.mjs.map +1 -0
- package/build/utils/path-helpers.cjs +49 -0
- package/build/utils/path-helpers.mjs +47 -0
- package/build/utils/path-helpers.mjs.map +1 -0
- package/build/utils/timeout.cjs +42 -0
- package/build/utils/timeout.mjs +41 -0
- package/build/utils/timeout.mjs.map +1 -0
- package/build/virtual/code-generator.cjs +56 -0
- package/build/virtual/code-generator.mjs +55 -0
- package/build/virtual/code-generator.mjs.map +1 -0
- package/build/virtual/config.cjs +16 -0
- package/build/virtual/config.d.cts +13 -0
- package/build/virtual/config.d.cts.map +1 -0
- package/build/virtual/config.d.mts +13 -0
- package/build/virtual/config.d.mts.map +1 -0
- package/build/virtual/config.mjs +12 -0
- package/build/virtual/config.mjs.map +1 -0
- package/build/virtual/locale/client.cjs +23 -0
- package/build/virtual/locale/client.d.cts +19 -0
- package/build/virtual/locale/client.d.cts.map +1 -0
- package/build/virtual/locale/client.d.mts +19 -0
- package/build/virtual/locale/client.d.mts.map +1 -0
- package/build/virtual/locale/client.mjs +22 -0
- package/build/virtual/locale/client.mjs.map +1 -0
- package/build/virtual/locale/server.cjs +13 -0
- package/build/virtual/locale/server.d.cts +13 -0
- package/build/virtual/locale/server.d.cts.map +1 -0
- package/build/virtual/locale/server.d.mts +13 -0
- package/build/virtual/locale/server.d.mts.map +1 -0
- package/build/virtual/locale/server.mjs +13 -0
- package/build/virtual/locale/server.mjs.map +1 -0
- package/package.json +260 -4
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
4
|
+
const require_logger = require('../../utils/logger.cjs');
|
|
5
|
+
const require_WeglotContext = require('../shared/WeglotContext.cjs');
|
|
6
|
+
const require_render_rich_text = require('../shared/render-rich-text.cjs');
|
|
7
|
+
let react = require("react");
|
|
8
|
+
|
|
9
|
+
//#region src/react/client/useTranslation.ts
|
|
10
|
+
/**
|
|
11
|
+
* useTranslation Hook
|
|
12
|
+
*
|
|
13
|
+
* Returns a translation function `t(hash, source, params?)` that:
|
|
14
|
+
* - Returns original text for source locale
|
|
15
|
+
* - Returns translated text for target locales
|
|
16
|
+
* - Supports rich text with variable and component placeholders
|
|
17
|
+
* - Automatically requests missing translations
|
|
18
|
+
* - Falls back to source text while loading
|
|
19
|
+
*
|
|
20
|
+
* This hook is automatically injected by the Babel plugin.
|
|
21
|
+
* You typically don't need to call it manually.
|
|
22
|
+
*
|
|
23
|
+
* @param hashes - Static list of all translation hashes used in this component (injected at build time)
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* 'use client';
|
|
28
|
+
*
|
|
29
|
+
* export function Welcome() {
|
|
30
|
+
* const t = useTranslation(['hash_abc123', 'hash_def456']);
|
|
31
|
+
*
|
|
32
|
+
* return (
|
|
33
|
+
* <div>
|
|
34
|
+
* <h1>{t('hash_abc123', 'Welcome')}</h1>
|
|
35
|
+
* <p>{t('hash_def456', 'Hello {name}', { name: 'Alice' })}</p>
|
|
36
|
+
* <p>{t('hash_def789', 'Click <a0>here</a0>', {
|
|
37
|
+
* a0: (chunks) => <a href="/home">{chunks}</a>
|
|
38
|
+
* })}</p>
|
|
39
|
+
* </div>
|
|
40
|
+
* );
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
const useTranslation = (hashes) => {
|
|
45
|
+
const { translations, registerHashes, locale, sourceLocale } = require_WeglotContext.useWeglotContext();
|
|
46
|
+
(0, react.useEffect)(() => {
|
|
47
|
+
require_logger.logger.debug(`Registering ${hashes.length} hashes for component`);
|
|
48
|
+
registerHashes(hashes);
|
|
49
|
+
}, [
|
|
50
|
+
hashes,
|
|
51
|
+
registerHashes,
|
|
52
|
+
locale,
|
|
53
|
+
sourceLocale
|
|
54
|
+
]);
|
|
55
|
+
return {
|
|
56
|
+
t: (0, react.useCallback)((hash, source, params) => {
|
|
57
|
+
require_logger.logger.debug(`Client. The translations for locale ${locale} are: ${JSON.stringify(translations)}`);
|
|
58
|
+
const text = translations[hash] || source;
|
|
59
|
+
if (!params) return text;
|
|
60
|
+
return require_render_rich_text.renderRichText(text, params, locale);
|
|
61
|
+
}, [
|
|
62
|
+
translations,
|
|
63
|
+
locale,
|
|
64
|
+
sourceLocale
|
|
65
|
+
]),
|
|
66
|
+
locale
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
exports.useTranslation = useTranslation;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TranslationHook } from "../types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/react/client/useTranslation.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* useTranslation Hook
|
|
7
|
+
*
|
|
8
|
+
* Returns a translation function `t(hash, source, params?)` that:
|
|
9
|
+
* - Returns original text for source locale
|
|
10
|
+
* - Returns translated text for target locales
|
|
11
|
+
* - Supports rich text with variable and component placeholders
|
|
12
|
+
* - Automatically requests missing translations
|
|
13
|
+
* - Falls back to source text while loading
|
|
14
|
+
*
|
|
15
|
+
* This hook is automatically injected by the Babel plugin.
|
|
16
|
+
* You typically don't need to call it manually.
|
|
17
|
+
*
|
|
18
|
+
* @param hashes - Static list of all translation hashes used in this component (injected at build time)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* 'use client';
|
|
23
|
+
*
|
|
24
|
+
* export function Welcome() {
|
|
25
|
+
* const t = useTranslation(['hash_abc123', 'hash_def456']);
|
|
26
|
+
*
|
|
27
|
+
* return (
|
|
28
|
+
* <div>
|
|
29
|
+
* <h1>{t('hash_abc123', 'Welcome')}</h1>
|
|
30
|
+
* <p>{t('hash_def456', 'Hello {name}', { name: 'Alice' })}</p>
|
|
31
|
+
* <p>{t('hash_def789', 'Click <a0>here</a0>', {
|
|
32
|
+
* a0: (chunks) => <a href="/home">{chunks}</a>
|
|
33
|
+
* })}</p>
|
|
34
|
+
* </div>
|
|
35
|
+
* );
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare const useTranslation: TranslationHook;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { useTranslation };
|
|
42
|
+
//# sourceMappingURL=useTranslation.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTranslation.d.cts","names":[],"sources":["../../../src/react/client/useTranslation.ts"],"sourcesContent":[],"mappings":";;;;;;AA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,gBAAgB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TranslationHook } from "../types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/react/client/useTranslation.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* useTranslation Hook
|
|
7
|
+
*
|
|
8
|
+
* Returns a translation function `t(hash, source, params?)` that:
|
|
9
|
+
* - Returns original text for source locale
|
|
10
|
+
* - Returns translated text for target locales
|
|
11
|
+
* - Supports rich text with variable and component placeholders
|
|
12
|
+
* - Automatically requests missing translations
|
|
13
|
+
* - Falls back to source text while loading
|
|
14
|
+
*
|
|
15
|
+
* This hook is automatically injected by the Babel plugin.
|
|
16
|
+
* You typically don't need to call it manually.
|
|
17
|
+
*
|
|
18
|
+
* @param hashes - Static list of all translation hashes used in this component (injected at build time)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* 'use client';
|
|
23
|
+
*
|
|
24
|
+
* export function Welcome() {
|
|
25
|
+
* const t = useTranslation(['hash_abc123', 'hash_def456']);
|
|
26
|
+
*
|
|
27
|
+
* return (
|
|
28
|
+
* <div>
|
|
29
|
+
* <h1>{t('hash_abc123', 'Welcome')}</h1>
|
|
30
|
+
* <p>{t('hash_def456', 'Hello {name}', { name: 'Alice' })}</p>
|
|
31
|
+
* <p>{t('hash_def789', 'Click <a0>here</a0>', {
|
|
32
|
+
* a0: (chunks) => <a href="/home">{chunks}</a>
|
|
33
|
+
* })}</p>
|
|
34
|
+
* </div>
|
|
35
|
+
* );
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare const useTranslation: TranslationHook;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { useTranslation };
|
|
42
|
+
//# sourceMappingURL=useTranslation.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTranslation.d.mts","names":[],"sources":["../../../src/react/client/useTranslation.ts"],"sourcesContent":[],"mappings":";;;;;;AA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,gBAAgB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { logger } from "../../utils/logger.mjs";
|
|
4
|
+
import { useWeglotContext } from "../shared/WeglotContext.mjs";
|
|
5
|
+
import { renderRichText } from "../shared/render-rich-text.mjs";
|
|
6
|
+
import { useCallback, useEffect } from "react";
|
|
7
|
+
|
|
8
|
+
//#region src/react/client/useTranslation.ts
|
|
9
|
+
/**
|
|
10
|
+
* useTranslation Hook
|
|
11
|
+
*
|
|
12
|
+
* Returns a translation function `t(hash, source, params?)` that:
|
|
13
|
+
* - Returns original text for source locale
|
|
14
|
+
* - Returns translated text for target locales
|
|
15
|
+
* - Supports rich text with variable and component placeholders
|
|
16
|
+
* - Automatically requests missing translations
|
|
17
|
+
* - Falls back to source text while loading
|
|
18
|
+
*
|
|
19
|
+
* This hook is automatically injected by the Babel plugin.
|
|
20
|
+
* You typically don't need to call it manually.
|
|
21
|
+
*
|
|
22
|
+
* @param hashes - Static list of all translation hashes used in this component (injected at build time)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* 'use client';
|
|
27
|
+
*
|
|
28
|
+
* export function Welcome() {
|
|
29
|
+
* const t = useTranslation(['hash_abc123', 'hash_def456']);
|
|
30
|
+
*
|
|
31
|
+
* return (
|
|
32
|
+
* <div>
|
|
33
|
+
* <h1>{t('hash_abc123', 'Welcome')}</h1>
|
|
34
|
+
* <p>{t('hash_def456', 'Hello {name}', { name: 'Alice' })}</p>
|
|
35
|
+
* <p>{t('hash_def789', 'Click <a0>here</a0>', {
|
|
36
|
+
* a0: (chunks) => <a href="/home">{chunks}</a>
|
|
37
|
+
* })}</p>
|
|
38
|
+
* </div>
|
|
39
|
+
* );
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
const useTranslation = (hashes) => {
|
|
44
|
+
const { translations, registerHashes, locale, sourceLocale } = useWeglotContext();
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
logger.debug(`Registering ${hashes.length} hashes for component`);
|
|
47
|
+
registerHashes(hashes);
|
|
48
|
+
}, [
|
|
49
|
+
hashes,
|
|
50
|
+
registerHashes,
|
|
51
|
+
locale,
|
|
52
|
+
sourceLocale
|
|
53
|
+
]);
|
|
54
|
+
return {
|
|
55
|
+
t: useCallback((hash, source, params) => {
|
|
56
|
+
logger.debug(`Client. The translations for locale ${locale} are: ${JSON.stringify(translations)}`);
|
|
57
|
+
const text = translations[hash] || source;
|
|
58
|
+
if (!params) return text;
|
|
59
|
+
return renderRichText(text, params, locale);
|
|
60
|
+
}, [
|
|
61
|
+
translations,
|
|
62
|
+
locale,
|
|
63
|
+
sourceLocale
|
|
64
|
+
]),
|
|
65
|
+
locale
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
export { useTranslation };
|
|
71
|
+
//# sourceMappingURL=useTranslation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTranslation.mjs","names":["useTranslation: TranslationHook"],"sources":["../../../src/react/client/useTranslation.ts"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useEffect } from \"react\";\nimport { logger } from \"../../utils/logger\";\nimport {\n renderRichText,\n type RichTextParams,\n} from \"../shared/render-rich-text\";\nimport type { TranslationHook } from \"../types\";\nimport { useWeglotContext } from \"../shared/WeglotContext\";\n\n/**\n * useTranslation Hook\n *\n * Returns a translation function `t(hash, source, params?)` that:\n * - Returns original text for source locale\n * - Returns translated text for target locales\n * - Supports rich text with variable and component placeholders\n * - Automatically requests missing translations\n * - Falls back to source text while loading\n *\n * This hook is automatically injected by the Babel plugin.\n * You typically don't need to call it manually.\n *\n * @param hashes - Static list of all translation hashes used in this component (injected at build time)\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * export function Welcome() {\n * const t = useTranslation(['hash_abc123', 'hash_def456']);\n *\n * return (\n * <div>\n * <h1>{t('hash_abc123', 'Welcome')}</h1>\n * <p>{t('hash_def456', 'Hello {name}', { name: 'Alice' })}</p>\n * <p>{t('hash_def789', 'Click <a0>here</a0>', {\n * a0: (chunks) => <a href=\"/home\">{chunks}</a>\n * })}</p>\n * </div>\n * );\n * }\n * ```\n */\nexport const useTranslation: TranslationHook = (hashes: string[]) => {\n const { translations, registerHashes, locale, sourceLocale } =\n useWeglotContext();\n\n useEffect(() => {\n logger.debug(`Registering ${hashes.length} hashes for component`);\n\n registerHashes(hashes);\n }, [hashes, registerHashes, locale, sourceLocale]);\n\n return {\n t: useCallback(\n (hash: string, source: string, params?: RichTextParams): ReactNode => {\n logger.debug(\n `Client. The translations for locale ${locale} are: ${JSON.stringify(translations)}`,\n );\n const text = translations[hash] || source;\n\n if (!params) {\n return text;\n }\n\n return renderRichText(text, params, locale);\n },\n [translations, locale, sourceLocale],\n ),\n locale,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAaA,kBAAmC,WAAqB;CACnE,MAAM,EAAE,cAAc,gBAAgB,QAAQ,iBAC5C,kBAAkB;AAEpB,iBAAgB;AACd,SAAO,MAAM,eAAe,OAAO,OAAO,uBAAuB;AAEjE,iBAAe,OAAO;IACrB;EAAC;EAAQ;EAAgB;EAAQ;EAAa,CAAC;AAElD,QAAO;EACL,GAAG,aACA,MAAc,QAAgB,WAAuC;AACpE,UAAO,MACL,uCAAuC,OAAO,QAAQ,KAAK,UAAU,aAAa,GACnF;GACD,MAAM,OAAO,aAAa,SAAS;AAEnC,OAAI,CAAC,OACH,QAAO;AAGT,UAAO,eAAe,MAAM,QAAQ,OAAO;KAE7C;GAAC;GAAc;GAAQ;GAAa,CACrC;EACD;EACD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
4
|
+
const require_logger = require('../../utils/logger.cjs');
|
|
5
|
+
const require_WeglotProvider = require('../shared/WeglotProvider.cjs');
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
let next_navigation = require("next/navigation");
|
|
8
|
+
|
|
9
|
+
//#region src/react/next/client.tsx
|
|
10
|
+
const createNextCookieLocaleResolver = () => {
|
|
11
|
+
return (locale) => {
|
|
12
|
+
require_logger.logger.warn("Is not supposed to run on client");
|
|
13
|
+
return locale;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const WeglotProvider = (props) => {
|
|
17
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_WeglotProvider.WeglotProvider, {
|
|
18
|
+
...props,
|
|
19
|
+
router: (0, next_navigation.useRouter)()
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.WeglotProvider = WeglotProvider;
|
|
25
|
+
exports.createNextCookieLocaleResolver = createNextCookieLocaleResolver;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WeglotProviderProps } from "../shared/WeglotProvider.cjs";
|
|
2
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/react/next/client.d.ts
|
|
5
|
+
declare const createNextCookieLocaleResolver: () => (locale: string) => string;
|
|
6
|
+
declare const WeglotProvider: (props: WeglotProviderProps) => react_jsx_runtime0.JSX.Element;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { WeglotProvider, type WeglotProviderProps, createNextCookieLocaleResolver };
|
|
9
|
+
//# sourceMappingURL=client.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.cts","names":[],"sources":["../../../src/react/next/client.tsx"],"sourcesContent":[],"mappings":";;;;cAUa;cAOA,wBAAyB,wBAAmB,kBAAA,CAAA,GAAA,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WeglotProviderProps } from "../shared/WeglotProvider.mjs";
|
|
2
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/react/next/client.d.ts
|
|
5
|
+
declare const createNextCookieLocaleResolver: () => (locale: string) => string;
|
|
6
|
+
declare const WeglotProvider: (props: WeglotProviderProps) => react_jsx_runtime0.JSX.Element;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { WeglotProvider, type WeglotProviderProps, createNextCookieLocaleResolver };
|
|
9
|
+
//# sourceMappingURL=client.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.mts","names":[],"sources":["../../../src/react/next/client.tsx"],"sourcesContent":[],"mappings":";;;;cAUa;cAOA,wBAAyB,wBAAmB,kBAAA,CAAA,GAAA,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { logger } from "../../utils/logger.mjs";
|
|
4
|
+
import { WeglotProvider as WeglotProvider$1 } from "../shared/WeglotProvider.mjs";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { useRouter } from "next/navigation";
|
|
7
|
+
|
|
8
|
+
//#region src/react/next/client.tsx
|
|
9
|
+
const createNextCookieLocaleResolver = () => {
|
|
10
|
+
return (locale) => {
|
|
11
|
+
logger.warn("Is not supposed to run on client");
|
|
12
|
+
return locale;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
const WeglotProvider = (props) => {
|
|
16
|
+
return /* @__PURE__ */ jsx(WeglotProvider$1, {
|
|
17
|
+
...props,
|
|
18
|
+
router: useRouter()
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { WeglotProvider, createNextCookieLocaleResolver };
|
|
24
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.mjs","names":["BaseWeglotProvider"],"sources":["../../../src/react/next/client.tsx"],"sourcesContent":["\"use client\";\nimport {\n WeglotProvider as BaseWeglotProvider,\n type WeglotProviderProps,\n} from \"../shared/WeglotProvider\";\nimport { useRouter } from \"next/navigation\";\nimport { logger } from \"../../utils/logger\";\n\nexport type { WeglotProviderProps };\n\nexport const createNextCookieLocaleResolver = () => {\n return (locale: string) => {\n logger.warn(\"Is not supposed to run on client\");\n return locale;\n };\n};\n\nexport const WeglotProvider = (props: WeglotProviderProps) => {\n // So far we are just injecting the router to reload server components when the locale changes.\n return <BaseWeglotProvider {...props} router={useRouter()} />;\n};\n"],"mappings":";;;;;;;;AAUA,MAAa,uCAAuC;AAClD,SAAQ,WAAmB;AACzB,SAAO,KAAK,mCAAmC;AAC/C,SAAO;;;AAIX,MAAa,kBAAkB,UAA+B;AAE5D,QAAO,oBAACA;EAAmB,GAAI;EAAO,QAAQ,WAAW;GAAI"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_logger = require('../../utils/logger.cjs');
|
|
3
|
+
let next_headers = require("next/headers");
|
|
4
|
+
|
|
5
|
+
//#region src/react/next/cookie-locale-resolver.ts
|
|
6
|
+
/**
|
|
7
|
+
* Create Next.js locale resolver
|
|
8
|
+
*
|
|
9
|
+
* This resolver reads the locale from Next.js cookies.
|
|
10
|
+
* It does NOT fetch translations - that's handled separately by the core translation service.
|
|
11
|
+
*
|
|
12
|
+
* @param config - Configuration options
|
|
13
|
+
* @returns Locale resolver function
|
|
14
|
+
*/
|
|
15
|
+
function createNextCookieLocaleResolver(config) {
|
|
16
|
+
const cookieName = config.cookieConfig.name;
|
|
17
|
+
const defaultLocale = config.defaultLocale;
|
|
18
|
+
return async () => {
|
|
19
|
+
try {
|
|
20
|
+
return (await (0, next_headers.cookies)()).get(cookieName)?.value || defaultLocale;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (process.env.DEBUG) require_logger.logger.error(`Error reading locale from Next.js cookies: ${error}\n`);
|
|
23
|
+
return defaultLocale;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.createNextCookieLocaleResolver = createNextCookieLocaleResolver;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LocaleCode } from "../../locale.cjs";
|
|
2
|
+
import { CookieConfig } from "../../types.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/react/next/cookie-locale-resolver.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for Next.js locale resolver
|
|
8
|
+
*/
|
|
9
|
+
interface NextLocaleResolverConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Cookie configuration (name and maxAge)
|
|
12
|
+
* @default { name: 'locale', maxAge: 31536000 }
|
|
13
|
+
*/
|
|
14
|
+
cookieConfig: CookieConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Default locale if cookie is not set
|
|
17
|
+
* @default 'en'
|
|
18
|
+
*/
|
|
19
|
+
defaultLocale: LocaleCode;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create Next.js locale resolver
|
|
23
|
+
*
|
|
24
|
+
* This resolver reads the locale from Next.js cookies.
|
|
25
|
+
* It does NOT fetch translations - that's handled separately by the core translation service.
|
|
26
|
+
*
|
|
27
|
+
* @param config - Configuration options
|
|
28
|
+
* @returns Locale resolver function
|
|
29
|
+
*/
|
|
30
|
+
declare function createNextCookieLocaleResolver(config: NextLocaleResolverConfig): () => Promise<string>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createNextCookieLocaleResolver };
|
|
33
|
+
//# sourceMappingURL=cookie-locale-resolver.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie-locale-resolver.d.cts","names":[],"sources":["../../../src/react/next/cookie-locale-resolver.ts"],"sourcesContent":[],"mappings":";;;;;;;;UAeU,wBAAA;;;;;gBAKM;;;;;iBAMC;;;;;;;;;;;iBAYD,8BAAA,SACN,iCACD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LocaleCode } from "../../locale.mjs";
|
|
2
|
+
import { CookieConfig } from "../../types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/react/next/cookie-locale-resolver.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for Next.js locale resolver
|
|
8
|
+
*/
|
|
9
|
+
interface NextLocaleResolverConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Cookie configuration (name and maxAge)
|
|
12
|
+
* @default { name: 'locale', maxAge: 31536000 }
|
|
13
|
+
*/
|
|
14
|
+
cookieConfig: CookieConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Default locale if cookie is not set
|
|
17
|
+
* @default 'en'
|
|
18
|
+
*/
|
|
19
|
+
defaultLocale: LocaleCode;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create Next.js locale resolver
|
|
23
|
+
*
|
|
24
|
+
* This resolver reads the locale from Next.js cookies.
|
|
25
|
+
* It does NOT fetch translations - that's handled separately by the core translation service.
|
|
26
|
+
*
|
|
27
|
+
* @param config - Configuration options
|
|
28
|
+
* @returns Locale resolver function
|
|
29
|
+
*/
|
|
30
|
+
declare function createNextCookieLocaleResolver(config: NextLocaleResolverConfig): () => Promise<string>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createNextCookieLocaleResolver };
|
|
33
|
+
//# sourceMappingURL=cookie-locale-resolver.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie-locale-resolver.d.mts","names":[],"sources":["../../../src/react/next/cookie-locale-resolver.ts"],"sourcesContent":[],"mappings":";;;;;;;;UAeU,wBAAA;;;;;gBAKM;;;;;iBAMC;;;;;;;;;;;iBAYD,8BAAA,SACN,iCACD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { logger } from "../../utils/logger.mjs";
|
|
2
|
+
import { cookies } from "next/headers";
|
|
3
|
+
|
|
4
|
+
//#region src/react/next/cookie-locale-resolver.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create Next.js locale resolver
|
|
7
|
+
*
|
|
8
|
+
* This resolver reads the locale from Next.js cookies.
|
|
9
|
+
* It does NOT fetch translations - that's handled separately by the core translation service.
|
|
10
|
+
*
|
|
11
|
+
* @param config - Configuration options
|
|
12
|
+
* @returns Locale resolver function
|
|
13
|
+
*/
|
|
14
|
+
function createNextCookieLocaleResolver(config) {
|
|
15
|
+
const cookieName = config.cookieConfig.name;
|
|
16
|
+
const defaultLocale = config.defaultLocale;
|
|
17
|
+
return async () => {
|
|
18
|
+
try {
|
|
19
|
+
return (await cookies()).get(cookieName)?.value || defaultLocale;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (process.env.DEBUG) logger.error(`Error reading locale from Next.js cookies: ${error}\n`);
|
|
22
|
+
return defaultLocale;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { createNextCookieLocaleResolver };
|
|
29
|
+
//# sourceMappingURL=cookie-locale-resolver.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie-locale-resolver.mjs","names":[],"sources":["../../../src/react/next/cookie-locale-resolver.ts"],"sourcesContent":["/**\n * Next.js-specific locale resolver\n * Reads locale from Next.js cookies\n *\n * This resolver ONLY handles locale resolution - it does NOT fetch translations.\n * Translation fetching is handled by the core translation service (server/translations.ts)\n */\nimport type { CookieConfig } from \"../../types\";\nimport { cookies } from \"next/headers\";\nimport { logger } from \"../../utils/logger\";\nimport type { LocaleCode } from \"../../locale\";\n\n/**\n * Configuration for Next.js locale resolver\n */\ninterface NextLocaleResolverConfig {\n /**\n * Cookie configuration (name and maxAge)\n * @default { name: 'locale', maxAge: 31536000 }\n */\n cookieConfig: CookieConfig;\n\n /**\n * Default locale if cookie is not set\n * @default 'en'\n */\n defaultLocale: LocaleCode;\n}\n\n/**\n * Create Next.js locale resolver\n *\n * This resolver reads the locale from Next.js cookies.\n * It does NOT fetch translations - that's handled separately by the core translation service.\n *\n * @param config - Configuration options\n * @returns Locale resolver function\n */\nexport function createNextCookieLocaleResolver(\n config: NextLocaleResolverConfig,\n): () => Promise<string> {\n const cookieName = config.cookieConfig.name;\n const defaultLocale = config.defaultLocale;\n\n return async () => {\n try {\n const cookieStore = await cookies();\n return cookieStore.get(cookieName)?.value || defaultLocale;\n } catch (error) {\n // Fallback on error (e.g., not in Next.js environment, or cookies() failed)\n if (process.env.DEBUG) {\n logger.error(`Error reading locale from Next.js cookies: ${error}\\n`);\n }\n return defaultLocale;\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAsCA,SAAgB,+BACd,QACuB;CACvB,MAAM,aAAa,OAAO,aAAa;CACvC,MAAM,gBAAgB,OAAO;AAE7B,QAAO,YAAY;AACjB,MAAI;AAEF,WADoB,MAAM,SAAS,EAChB,IAAI,WAAW,EAAE,SAAS;WACtC,OAAO;AAEd,OAAI,QAAQ,IAAI,MACd,QAAO,MAAM,8CAA8C,MAAM,IAAI;AAEvE,UAAO"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_logger = require('../../utils/logger.cjs');
|
|
3
|
+
const require_react_server_only_index = require('../server-only/index.cjs');
|
|
4
|
+
const require_react_next_client = require('./client.cjs');
|
|
5
|
+
const require_cookie_locale_resolver = require('./cookie-locale-resolver.cjs');
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
|
|
8
|
+
//#region src/react/next/server.tsx
|
|
9
|
+
async function WeglotProvider({ initialLocale, initialTranslations = {}, ...rest }) {
|
|
10
|
+
const { locale, translations } = await require_react_server_only_index.getServerTranslations({ locale: initialLocale });
|
|
11
|
+
require_logger.logger.debug(`Server. WeglotProvider. Initial locale: ${initialLocale}. Resolved locale: ${locale}. Translations: ${JSON.stringify(translations)}`);
|
|
12
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_react_next_client.WeglotProvider, {
|
|
13
|
+
initialLocale: locale,
|
|
14
|
+
initialTranslations: translations,
|
|
15
|
+
...rest
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.WeglotProvider = WeglotProvider;
|
|
21
|
+
exports.createNextCookieLocaleResolver = require_cookie_locale_resolver.createNextCookieLocaleResolver;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WeglotProviderProps } from "../shared/WeglotProvider.cjs";
|
|
2
|
+
import { createNextCookieLocaleResolver } from "./cookie-locale-resolver.cjs";
|
|
3
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/react/next/server.d.ts
|
|
6
|
+
declare function WeglotProvider({
|
|
7
|
+
initialLocale,
|
|
8
|
+
initialTranslations,
|
|
9
|
+
...rest
|
|
10
|
+
}: WeglotProviderProps): Promise<react_jsx_runtime0.JSX.Element>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { WeglotProvider, createNextCookieLocaleResolver };
|
|
13
|
+
//# sourceMappingURL=server.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.cts","names":[],"sources":["../../../src/react/next/server.tsx"],"sourcesContent":[],"mappings":";;;;;iBAUsB,cAAA;;;;GAInB,sBAAmB,QAAA,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { WeglotProviderProps } from "../shared/WeglotProvider.mjs";
|
|
2
|
+
import "./client.mjs";
|
|
3
|
+
import { createNextCookieLocaleResolver } from "./cookie-locale-resolver.mjs";
|
|
4
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/react/next/server.d.ts
|
|
7
|
+
declare function WeglotProvider({
|
|
8
|
+
initialLocale,
|
|
9
|
+
initialTranslations,
|
|
10
|
+
...rest
|
|
11
|
+
}: WeglotProviderProps): Promise<react_jsx_runtime0.JSX.Element>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { WeglotProvider, createNextCookieLocaleResolver };
|
|
14
|
+
//# sourceMappingURL=server.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../../../src/react/next/server.tsx"],"sourcesContent":[],"mappings":";;;;;;iBAUsB,cAAA;;;;GAInB,sBAAmB,QAAA,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { logger } from "../../utils/logger.mjs";
|
|
2
|
+
import { getServerTranslations } from "../server-only/index.mjs";
|
|
3
|
+
import { WeglotProvider as WeglotProvider$1 } from "./client.mjs";
|
|
4
|
+
import { createNextCookieLocaleResolver } from "./cookie-locale-resolver.mjs";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/react/next/server.tsx
|
|
8
|
+
async function WeglotProvider({ initialLocale, initialTranslations = {}, ...rest }) {
|
|
9
|
+
const { locale, translations } = await getServerTranslations({ locale: initialLocale });
|
|
10
|
+
logger.debug(`Server. WeglotProvider. Initial locale: ${initialLocale}. Resolved locale: ${locale}. Translations: ${JSON.stringify(translations)}`);
|
|
11
|
+
return /* @__PURE__ */ jsx(WeglotProvider$1, {
|
|
12
|
+
initialLocale: locale,
|
|
13
|
+
initialTranslations: translations,
|
|
14
|
+
...rest
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { WeglotProvider, createNextCookieLocaleResolver };
|
|
20
|
+
//# sourceMappingURL=server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.mjs","names":["BaseWeglotProvider"],"sources":["../../../src/react/next/server.tsx"],"sourcesContent":["import {\n WeglotProvider as BaseWeglotProvider,\n type WeglotProviderProps,\n} from \"./client\";\nimport { getServerTranslations } from \"../server-only\";\nimport { logger } from \"../../utils/logger\";\nimport { createNextCookieLocaleResolver } from \"./cookie-locale-resolver\";\n\nexport { createNextCookieLocaleResolver };\n\nexport async function WeglotProvider({\n initialLocale,\n initialTranslations = {},\n ...rest\n}: WeglotProviderProps) {\n const { locale, translations } = await getServerTranslations({\n locale: initialLocale,\n });\n\n logger.debug(\n `Server. WeglotProvider. Initial locale: ${initialLocale}. Resolved locale: ${locale}. Translations: ${JSON.stringify(translations)}`,\n );\n\n return (\n <BaseWeglotProvider\n initialLocale={locale}\n initialTranslations={translations}\n {...rest}\n />\n );\n}\n"],"mappings":";;;;;;;AAUA,eAAsB,eAAe,EACnC,eACA,sBAAsB,EAAE,EACxB,GAAG,QACmB;CACtB,MAAM,EAAE,QAAQ,iBAAiB,MAAM,sBAAsB,EAC3D,QAAQ,eACT,CAAC;AAEF,QAAO,MACL,2CAA2C,cAAc,qBAAqB,OAAO,kBAAkB,KAAK,UAAU,aAAa,GACpI;AAED,QACE,oBAACA;EACC,eAAe;EACf,qBAAqB;EACrB,GAAI;GACJ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_logger = require('../../utils/logger.cjs');
|
|
3
|
+
const require_WeglotProvider = require('../shared/WeglotProvider.cjs');
|
|
4
|
+
const require_react_server_only_index = require('../server-only/index.cjs');
|
|
5
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
|
+
|
|
7
|
+
//#region src/react/server/ServerWeglotProvider.tsx
|
|
8
|
+
async function WeglotProvider({ initialLocale, initialTranslations = {}, ...rest }) {
|
|
9
|
+
const { locale, translations } = await require_react_server_only_index.getServerTranslations({ locale: initialLocale });
|
|
10
|
+
require_logger.logger.debug(`Server. WeglotProvider. Resolved locale: ${locale}`);
|
|
11
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_WeglotProvider.WeglotProvider, {
|
|
12
|
+
initialLocale: locale,
|
|
13
|
+
initialTranslations: translations,
|
|
14
|
+
...rest
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.WeglotProvider = WeglotProvider;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WeglotProviderProps } from "../shared/WeglotProvider.cjs";
|
|
2
|
+
import * as react_jsx_runtime3 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/react/server/ServerWeglotProvider.d.ts
|
|
5
|
+
declare function WeglotProvider({
|
|
6
|
+
initialLocale,
|
|
7
|
+
initialTranslations,
|
|
8
|
+
...rest
|
|
9
|
+
}: WeglotProviderProps): Promise<react_jsx_runtime3.JSX.Element>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { WeglotProvider };
|
|
12
|
+
//# sourceMappingURL=ServerWeglotProvider.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerWeglotProvider.d.cts","names":[],"sources":["../../../src/react/server/ServerWeglotProvider.tsx"],"sourcesContent":[],"mappings":";;;;iBAOsB,cAAA;;;;GAInB,sBAAmB,QAAA,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WeglotProviderProps } from "../shared/WeglotProvider.mjs";
|
|
2
|
+
import * as react_jsx_runtime1 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/react/server/ServerWeglotProvider.d.ts
|
|
5
|
+
declare function WeglotProvider({
|
|
6
|
+
initialLocale,
|
|
7
|
+
initialTranslations,
|
|
8
|
+
...rest
|
|
9
|
+
}: WeglotProviderProps): Promise<react_jsx_runtime1.JSX.Element>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { WeglotProvider };
|
|
12
|
+
//# sourceMappingURL=ServerWeglotProvider.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerWeglotProvider.d.mts","names":[],"sources":["../../../src/react/server/ServerWeglotProvider.tsx"],"sourcesContent":[],"mappings":";;;;iBAOsB,cAAA;;;;GAInB,sBAAmB,QAAA,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { logger } from "../../utils/logger.mjs";
|
|
2
|
+
import { WeglotProvider as WeglotProvider$1 } from "../shared/WeglotProvider.mjs";
|
|
3
|
+
import { getServerTranslations } from "../server-only/index.mjs";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/react/server/ServerWeglotProvider.tsx
|
|
7
|
+
async function WeglotProvider({ initialLocale, initialTranslations = {}, ...rest }) {
|
|
8
|
+
const { locale, translations } = await getServerTranslations({ locale: initialLocale });
|
|
9
|
+
logger.debug(`Server. WeglotProvider. Resolved locale: ${locale}`);
|
|
10
|
+
return /* @__PURE__ */ jsx(WeglotProvider$1, {
|
|
11
|
+
initialLocale: locale,
|
|
12
|
+
initialTranslations: translations,
|
|
13
|
+
...rest
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { WeglotProvider };
|
|
19
|
+
//# sourceMappingURL=ServerWeglotProvider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerWeglotProvider.mjs","names":["BaseWeglotProvider"],"sources":["../../../src/react/server/ServerWeglotProvider.tsx"],"sourcesContent":["import {\n WeglotProvider as BaseWeglotProvider,\n type WeglotProviderProps,\n} from \"../shared/WeglotProvider\";\nimport { getServerTranslations } from \"../server-only\";\nimport { logger } from \"../../utils/logger\";\n\nexport async function WeglotProvider({\n initialLocale,\n initialTranslations = {},\n ...rest\n}: WeglotProviderProps) {\n const { locale, translations } = await getServerTranslations({\n locale: initialLocale,\n });\n\n logger.debug(`Server. WeglotProvider. Resolved locale: ${locale}`);\n\n return (\n <BaseWeglotProvider\n initialLocale={locale}\n initialTranslations={translations}\n {...rest}\n />\n );\n}\n"],"mappings":";;;;;;AAOA,eAAsB,eAAe,EACnC,eACA,sBAAsB,EAAE,EACxB,GAAG,QACmB;CACtB,MAAM,EAAE,QAAQ,iBAAiB,MAAM,sBAAsB,EAC3D,QAAQ,eACT,CAAC;AAEF,QAAO,MAAM,4CAA4C,SAAS;AAElE,QACE,oBAACA;EACC,eAAe;EACf,qBAAqB;EACrB,GAAI;GACJ"}
|