@kopexa/i18n 0.0.0-canary-20250926082443

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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @kopexa/i18n
2
+
3
+ A Quick description of the component
4
+
5
+ > This is an internal utility, not intended for public usage.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ yarn add @kopexa/i18n
11
+ # or
12
+ npm i @kopexa/i18n
13
+ ```
14
+
15
+ ## Contribution
16
+
17
+ Yes please! See the
18
+ [contributing guidelines](https://github.com/kopexa-grc/sight/blob/master/CONTRIBUTING.md)
19
+ for details.
20
+
21
+ ## License
22
+
23
+ This project is licensed under the terms of the
24
+ [MIT license](https://github.com/kopexa-grc/sight/blob/master/LICENSE).
@@ -0,0 +1,11 @@
1
+ "use client";
2
+
3
+ // src/const.ts
4
+ var DEFAULT_LOCALE_STATE = {
5
+ locale: "en",
6
+ messages: {}
7
+ };
8
+
9
+ export {
10
+ DEFAULT_LOCALE_STATE
11
+ };
@@ -0,0 +1,28 @@
1
+ "use client";
2
+ import {
3
+ DEFAULT_LOCALE_STATE
4
+ } from "./chunk-DRJHB4YN.mjs";
5
+
6
+ // src/hooks/use-safe-intl.ts
7
+ import { useContext } from "react";
8
+ import { createIntl, createIntlCache, IntlContext } from "react-intl";
9
+ var cache = createIntlCache();
10
+ var useSafeIntl = () => {
11
+ const context = useContext(IntlContext);
12
+ if (!context) {
13
+ return createIntl(DEFAULT_LOCALE_STATE, cache);
14
+ }
15
+ return context;
16
+ };
17
+ function getTranslator() {
18
+ const intl = (
19
+ // biome-ignore lint/suspicious/noExplicitAny: skip window declaration
20
+ typeof window !== "undefined" && window.__KOPEXA_INTL__ || createIntl(DEFAULT_LOCALE_STATE, cache)
21
+ );
22
+ return (id, values) => intl.formatMessage({ id }, values);
23
+ }
24
+
25
+ export {
26
+ useSafeIntl,
27
+ getTranslator
28
+ };
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import {
3
+ useMessages
4
+ } from "./chunk-TYEI7NWI.mjs";
5
+ import {
6
+ useSafeIntl
7
+ } from "./chunk-DWCWMJZD.mjs";
8
+
9
+ // src/i18n.tsx
10
+ import { useMemo } from "react";
11
+ import { IntlProvider } from "react-intl";
12
+ import { jsx } from "react/jsx-runtime";
13
+ var I18nProvider = (props) => {
14
+ const {
15
+ children,
16
+ locale: localeProp,
17
+ defaultMessages = {},
18
+ loaderFn
19
+ } = props;
20
+ const intl = useSafeIntl();
21
+ const locale = (localeProp || intl.locale || "en").toLowerCase();
22
+ const messages = useMessages(locale, loaderFn);
23
+ const mergedMessages = useMemo(() => {
24
+ return { ...defaultMessages, ...intl.messages, ...messages };
25
+ }, [intl, messages, defaultMessages]);
26
+ return /* @__PURE__ */ jsx(
27
+ IntlProvider,
28
+ {
29
+ defaultLocale: "en",
30
+ locale,
31
+ messages: mergedMessages,
32
+ onError: () => null,
33
+ children
34
+ }
35
+ );
36
+ };
37
+
38
+ export {
39
+ I18nProvider
40
+ };
@@ -0,0 +1,31 @@
1
+ "use client";
2
+ import {
3
+ DEFAULT_LOCALE_STATE
4
+ } from "./chunk-DRJHB4YN.mjs";
5
+
6
+ // src/hooks/use-messages.ts
7
+ import { useEffect, useState } from "react";
8
+ var useMessages = (locale, loaderFn) => {
9
+ const [localeState, setLocaleState] = useState(DEFAULT_LOCALE_STATE);
10
+ useEffect(() => {
11
+ if (!localeState.messages || locale !== localeState.locale) {
12
+ let current = true;
13
+ loaderFn == null ? void 0 : loaderFn(locale).then((messages) => {
14
+ if (current) {
15
+ setLocaleState({
16
+ locale,
17
+ messages: messages != null ? messages : {}
18
+ });
19
+ }
20
+ });
21
+ return () => {
22
+ current = false;
23
+ };
24
+ }
25
+ }, [loaderFn, locale, localeState]);
26
+ return localeState.messages;
27
+ };
28
+
29
+ export {
30
+ useMessages
31
+ };
@@ -0,0 +1,6 @@
1
+ declare const DEFAULT_LOCALE_STATE: {
2
+ locale: string;
3
+ messages: {};
4
+ };
5
+
6
+ export { DEFAULT_LOCALE_STATE };
@@ -0,0 +1,6 @@
1
+ declare const DEFAULT_LOCALE_STATE: {
2
+ locale: string;
3
+ messages: {};
4
+ };
5
+
6
+ export { DEFAULT_LOCALE_STATE };
package/dist/const.js ADDED
@@ -0,0 +1,34 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/const.ts
22
+ var const_exports = {};
23
+ __export(const_exports, {
24
+ DEFAULT_LOCALE_STATE: () => DEFAULT_LOCALE_STATE
25
+ });
26
+ module.exports = __toCommonJS(const_exports);
27
+ var DEFAULT_LOCALE_STATE = {
28
+ locale: "en",
29
+ messages: {}
30
+ };
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ DEFAULT_LOCALE_STATE
34
+ });
package/dist/const.mjs ADDED
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import {
3
+ DEFAULT_LOCALE_STATE
4
+ } from "./chunk-DRJHB4YN.mjs";
5
+ export {
6
+ DEFAULT_LOCALE_STATE
7
+ };
@@ -0,0 +1,10 @@
1
+ import { I18NMessages } from '../types.mjs';
2
+ import 'react-intl';
3
+
4
+ type LocaleState = {
5
+ locale: string;
6
+ messages: I18NMessages | undefined;
7
+ };
8
+ declare const useMessages: (locale: string, loaderFn?: (locale: string) => Promise<I18NMessages | undefined>) => I18NMessages | undefined;
9
+
10
+ export { type LocaleState, useMessages };
@@ -0,0 +1,10 @@
1
+ import { I18NMessages } from '../types.js';
2
+ import 'react-intl';
3
+
4
+ type LocaleState = {
5
+ locale: string;
6
+ messages: I18NMessages | undefined;
7
+ };
8
+ declare const useMessages: (locale: string, loaderFn?: (locale: string) => Promise<I18NMessages | undefined>) => I18NMessages | undefined;
9
+
10
+ export { type LocaleState, useMessages };
@@ -0,0 +1,60 @@
1
+ "use client";
2
+ "use strict";
3
+ "use client";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/hooks/use-messages.ts
23
+ var use_messages_exports = {};
24
+ __export(use_messages_exports, {
25
+ useMessages: () => useMessages
26
+ });
27
+ module.exports = __toCommonJS(use_messages_exports);
28
+ var import_react = require("react");
29
+
30
+ // src/const.ts
31
+ var DEFAULT_LOCALE_STATE = {
32
+ locale: "en",
33
+ messages: {}
34
+ };
35
+
36
+ // src/hooks/use-messages.ts
37
+ var useMessages = (locale, loaderFn) => {
38
+ const [localeState, setLocaleState] = (0, import_react.useState)(DEFAULT_LOCALE_STATE);
39
+ (0, import_react.useEffect)(() => {
40
+ if (!localeState.messages || locale !== localeState.locale) {
41
+ let current = true;
42
+ loaderFn == null ? void 0 : loaderFn(locale).then((messages) => {
43
+ if (current) {
44
+ setLocaleState({
45
+ locale,
46
+ messages: messages != null ? messages : {}
47
+ });
48
+ }
49
+ });
50
+ return () => {
51
+ current = false;
52
+ };
53
+ }
54
+ }, [loaderFn, locale, localeState]);
55
+ return localeState.messages;
56
+ };
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ useMessages
60
+ });
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ "use client";
3
+ import {
4
+ useMessages
5
+ } from "../chunk-TYEI7NWI.mjs";
6
+ import "../chunk-DRJHB4YN.mjs";
7
+ export {
8
+ useMessages
9
+ };
@@ -0,0 +1,12 @@
1
+ import * as react_intl from 'react-intl';
2
+
3
+ /**
4
+ * Returns current context from `IntlShape`. When there is no context returns
5
+ * an `IntlShape` with default `{locale: 'en', messages: {}}`
6
+ * Removes the need for an `IntlProvodier` to be present in the DOM Tree
7
+ */
8
+ declare const useSafeIntl: () => react_intl.IntlShape;
9
+ type T = (id: string, values?: Record<string, any>) => string;
10
+ declare function getTranslator(): T;
11
+
12
+ export { type T, getTranslator, useSafeIntl };
@@ -0,0 +1,12 @@
1
+ import * as react_intl from 'react-intl';
2
+
3
+ /**
4
+ * Returns current context from `IntlShape`. When there is no context returns
5
+ * an `IntlShape` with default `{locale: 'en', messages: {}}`
6
+ * Removes the need for an `IntlProvodier` to be present in the DOM Tree
7
+ */
8
+ declare const useSafeIntl: () => react_intl.IntlShape;
9
+ type T = (id: string, values?: Record<string, any>) => string;
10
+ declare function getTranslator(): T;
11
+
12
+ export { type T, getTranslator, useSafeIntl };
@@ -0,0 +1,57 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/hooks/use-safe-intl.ts
22
+ var use_safe_intl_exports = {};
23
+ __export(use_safe_intl_exports, {
24
+ getTranslator: () => getTranslator,
25
+ useSafeIntl: () => useSafeIntl
26
+ });
27
+ module.exports = __toCommonJS(use_safe_intl_exports);
28
+ var import_react = require("react");
29
+ var import_react_intl = require("react-intl");
30
+
31
+ // src/const.ts
32
+ var DEFAULT_LOCALE_STATE = {
33
+ locale: "en",
34
+ messages: {}
35
+ };
36
+
37
+ // src/hooks/use-safe-intl.ts
38
+ var cache = (0, import_react_intl.createIntlCache)();
39
+ var useSafeIntl = () => {
40
+ const context = (0, import_react.useContext)(import_react_intl.IntlContext);
41
+ if (!context) {
42
+ return (0, import_react_intl.createIntl)(DEFAULT_LOCALE_STATE, cache);
43
+ }
44
+ return context;
45
+ };
46
+ function getTranslator() {
47
+ const intl = (
48
+ // biome-ignore lint/suspicious/noExplicitAny: skip window declaration
49
+ typeof window !== "undefined" && window.__KOPEXA_INTL__ || (0, import_react_intl.createIntl)(DEFAULT_LOCALE_STATE, cache)
50
+ );
51
+ return (id, values) => intl.formatMessage({ id }, values);
52
+ }
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ getTranslator,
56
+ useSafeIntl
57
+ });
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import {
3
+ getTranslator,
4
+ useSafeIntl
5
+ } from "../chunk-DWCWMJZD.mjs";
6
+ import "../chunk-DRJHB4YN.mjs";
7
+ export {
8
+ getTranslator,
9
+ useSafeIntl
10
+ };
@@ -0,0 +1,22 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { I18NMessages } from './types.mjs';
3
+ import 'react-intl';
4
+
5
+ type I18nProviderProps = {
6
+ children?: React.ReactNode;
7
+ /**
8
+ * if not provided, the locale from useSafeIntl will be used
9
+ */
10
+ locale?: string;
11
+ /** SSR: pass preloaded messages to avoid hydration flashes. */
12
+ defaultMessages?: Record<string, string>;
13
+ /**
14
+ * Use this function to asynchronously load translated messages
15
+ * from your package and feed them to our internal IntlProvider
16
+ * This will enable translations in Product
17
+ */
18
+ loaderFn?: (locale: string) => Promise<I18NMessages | undefined>;
19
+ };
20
+ declare const I18nProvider: (props: I18nProviderProps) => react_jsx_runtime.JSX.Element;
21
+
22
+ export { I18nProvider, type I18nProviderProps };
package/dist/i18n.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { I18NMessages } from './types.js';
3
+ import 'react-intl';
4
+
5
+ type I18nProviderProps = {
6
+ children?: React.ReactNode;
7
+ /**
8
+ * if not provided, the locale from useSafeIntl will be used
9
+ */
10
+ locale?: string;
11
+ /** SSR: pass preloaded messages to avoid hydration flashes. */
12
+ defaultMessages?: Record<string, string>;
13
+ /**
14
+ * Use this function to asynchronously load translated messages
15
+ * from your package and feed them to our internal IntlProvider
16
+ * This will enable translations in Product
17
+ */
18
+ loaderFn?: (locale: string) => Promise<I18NMessages | undefined>;
19
+ };
20
+ declare const I18nProvider: (props: I18nProviderProps) => react_jsx_runtime.JSX.Element;
21
+
22
+ export { I18nProvider, type I18nProviderProps };
package/dist/i18n.js ADDED
@@ -0,0 +1,103 @@
1
+ "use client";
2
+ "use strict";
3
+ "use client";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/i18n.tsx
23
+ var i18n_exports = {};
24
+ __export(i18n_exports, {
25
+ I18nProvider: () => I18nProvider
26
+ });
27
+ module.exports = __toCommonJS(i18n_exports);
28
+ var import_react3 = require("react");
29
+ var import_react_intl2 = require("react-intl");
30
+
31
+ // src/hooks/use-messages.ts
32
+ var import_react = require("react");
33
+
34
+ // src/const.ts
35
+ var DEFAULT_LOCALE_STATE = {
36
+ locale: "en",
37
+ messages: {}
38
+ };
39
+
40
+ // src/hooks/use-messages.ts
41
+ var useMessages = (locale, loaderFn) => {
42
+ const [localeState, setLocaleState] = (0, import_react.useState)(DEFAULT_LOCALE_STATE);
43
+ (0, import_react.useEffect)(() => {
44
+ if (!localeState.messages || locale !== localeState.locale) {
45
+ let current = true;
46
+ loaderFn == null ? void 0 : loaderFn(locale).then((messages) => {
47
+ if (current) {
48
+ setLocaleState({
49
+ locale,
50
+ messages: messages != null ? messages : {}
51
+ });
52
+ }
53
+ });
54
+ return () => {
55
+ current = false;
56
+ };
57
+ }
58
+ }, [loaderFn, locale, localeState]);
59
+ return localeState.messages;
60
+ };
61
+
62
+ // src/hooks/use-safe-intl.ts
63
+ var import_react2 = require("react");
64
+ var import_react_intl = require("react-intl");
65
+ var cache = (0, import_react_intl.createIntlCache)();
66
+ var useSafeIntl = () => {
67
+ const context = (0, import_react2.useContext)(import_react_intl.IntlContext);
68
+ if (!context) {
69
+ return (0, import_react_intl.createIntl)(DEFAULT_LOCALE_STATE, cache);
70
+ }
71
+ return context;
72
+ };
73
+
74
+ // src/i18n.tsx
75
+ var import_jsx_runtime = require("react/jsx-runtime");
76
+ var I18nProvider = (props) => {
77
+ const {
78
+ children,
79
+ locale: localeProp,
80
+ defaultMessages = {},
81
+ loaderFn
82
+ } = props;
83
+ const intl = useSafeIntl();
84
+ const locale = (localeProp || intl.locale || "en").toLowerCase();
85
+ const messages = useMessages(locale, loaderFn);
86
+ const mergedMessages = (0, import_react3.useMemo)(() => {
87
+ return { ...defaultMessages, ...intl.messages, ...messages };
88
+ }, [intl, messages, defaultMessages]);
89
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
90
+ import_react_intl2.IntlProvider,
91
+ {
92
+ defaultLocale: "en",
93
+ locale,
94
+ messages: mergedMessages,
95
+ onError: () => null,
96
+ children
97
+ }
98
+ );
99
+ };
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ I18nProvider
103
+ });
package/dist/i18n.mjs ADDED
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ "use client";
3
+ import {
4
+ I18nProvider
5
+ } from "./chunk-R2PSHCC4.mjs";
6
+ import "./chunk-TYEI7NWI.mjs";
7
+ import "./chunk-DWCWMJZD.mjs";
8
+ import "./chunk-DRJHB4YN.mjs";
9
+ export {
10
+ I18nProvider
11
+ };
@@ -0,0 +1,5 @@
1
+ export { useSafeIntl } from './hooks/use-safe-intl.mjs';
2
+ export { I18nProvider, I18nProviderProps } from './i18n.mjs';
3
+ import 'react-intl';
4
+ import 'react/jsx-runtime';
5
+ import './types.mjs';
@@ -0,0 +1,5 @@
1
+ export { useSafeIntl } from './hooks/use-safe-intl.js';
2
+ export { I18nProvider, I18nProviderProps } from './i18n.js';
3
+ import 'react-intl';
4
+ import 'react/jsx-runtime';
5
+ import './types.js';
package/dist/index.js ADDED
@@ -0,0 +1,106 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ I18nProvider: () => I18nProvider,
25
+ useSafeIntl: () => useSafeIntl
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/hooks/use-safe-intl.ts
30
+ var import_react = require("react");
31
+ var import_react_intl = require("react-intl");
32
+
33
+ // src/const.ts
34
+ var DEFAULT_LOCALE_STATE = {
35
+ locale: "en",
36
+ messages: {}
37
+ };
38
+
39
+ // src/hooks/use-safe-intl.ts
40
+ var cache = (0, import_react_intl.createIntlCache)();
41
+ var useSafeIntl = () => {
42
+ const context = (0, import_react.useContext)(import_react_intl.IntlContext);
43
+ if (!context) {
44
+ return (0, import_react_intl.createIntl)(DEFAULT_LOCALE_STATE, cache);
45
+ }
46
+ return context;
47
+ };
48
+
49
+ // src/i18n.tsx
50
+ var import_react3 = require("react");
51
+ var import_react_intl2 = require("react-intl");
52
+
53
+ // src/hooks/use-messages.ts
54
+ var import_react2 = require("react");
55
+ var useMessages = (locale, loaderFn) => {
56
+ const [localeState, setLocaleState] = (0, import_react2.useState)(DEFAULT_LOCALE_STATE);
57
+ (0, import_react2.useEffect)(() => {
58
+ if (!localeState.messages || locale !== localeState.locale) {
59
+ let current = true;
60
+ loaderFn == null ? void 0 : loaderFn(locale).then((messages) => {
61
+ if (current) {
62
+ setLocaleState({
63
+ locale,
64
+ messages: messages != null ? messages : {}
65
+ });
66
+ }
67
+ });
68
+ return () => {
69
+ current = false;
70
+ };
71
+ }
72
+ }, [loaderFn, locale, localeState]);
73
+ return localeState.messages;
74
+ };
75
+
76
+ // src/i18n.tsx
77
+ var import_jsx_runtime = require("react/jsx-runtime");
78
+ var I18nProvider = (props) => {
79
+ const {
80
+ children,
81
+ locale: localeProp,
82
+ defaultMessages = {},
83
+ loaderFn
84
+ } = props;
85
+ const intl = useSafeIntl();
86
+ const locale = (localeProp || intl.locale || "en").toLowerCase();
87
+ const messages = useMessages(locale, loaderFn);
88
+ const mergedMessages = (0, import_react3.useMemo)(() => {
89
+ return { ...defaultMessages, ...intl.messages, ...messages };
90
+ }, [intl, messages, defaultMessages]);
91
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
92
+ import_react_intl2.IntlProvider,
93
+ {
94
+ defaultLocale: "en",
95
+ locale,
96
+ messages: mergedMessages,
97
+ onError: () => null,
98
+ children
99
+ }
100
+ );
101
+ };
102
+ // Annotate the CommonJS export names for ESM import in node:
103
+ 0 && (module.exports = {
104
+ I18nProvider,
105
+ useSafeIntl
106
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import {
3
+ I18nProvider
4
+ } from "./chunk-R2PSHCC4.mjs";
5
+ import "./chunk-TYEI7NWI.mjs";
6
+ import {
7
+ useSafeIntl
8
+ } from "./chunk-DWCWMJZD.mjs";
9
+ import "./chunk-DRJHB4YN.mjs";
10
+ export {
11
+ I18nProvider,
12
+ useSafeIntl
13
+ };
@@ -0,0 +1,7 @@
1
+ type Messages = Record<string, string>;
2
+ type Provider = (locale: string) => Promise<Messages>;
3
+ /** Von jedem Paket beim Import aufgerufen */
4
+ declare function registerMessages(provider: Provider): void;
5
+ declare function loadAllMessages(locale: string): Promise<Messages>;
6
+
7
+ export { type Messages, type Provider, loadAllMessages, registerMessages };
@@ -0,0 +1,7 @@
1
+ type Messages = Record<string, string>;
2
+ type Provider = (locale: string) => Promise<Messages>;
3
+ /** Von jedem Paket beim Import aufgerufen */
4
+ declare function registerMessages(provider: Provider): void;
5
+ declare function loadAllMessages(locale: string): Promise<Messages>;
6
+
7
+ export { type Messages, type Provider, loadAllMessages, registerMessages };
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/registry.ts
22
+ var registry_exports = {};
23
+ __export(registry_exports, {
24
+ loadAllMessages: () => loadAllMessages,
25
+ registerMessages: () => registerMessages
26
+ });
27
+ module.exports = __toCommonJS(registry_exports);
28
+ var providers = [];
29
+ function registerMessages(provider) {
30
+ providers.push(provider);
31
+ }
32
+ async function loadAllMessages(locale) {
33
+ const parts = await Promise.all(providers.map((p) => p(locale)));
34
+ return Object.assign({}, ...parts);
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ loadAllMessages,
39
+ registerMessages
40
+ });
@@ -0,0 +1,15 @@
1
+ "use client";
2
+
3
+ // src/registry.ts
4
+ var providers = [];
5
+ function registerMessages(provider) {
6
+ providers.push(provider);
7
+ }
8
+ async function loadAllMessages(locale) {
9
+ const parts = await Promise.all(providers.map((p) => p(locale)));
10
+ return Object.assign({}, ...parts);
11
+ }
12
+ export {
13
+ loadAllMessages,
14
+ registerMessages
15
+ };
@@ -0,0 +1,5 @@
1
+ import { MessageFormatElement } from 'react-intl';
2
+
3
+ type I18NMessages = Record<string, string> | Record<string, MessageFormatElement[]>;
4
+
5
+ export type { I18NMessages };
@@ -0,0 +1,5 @@
1
+ import { MessageFormatElement } from 'react-intl';
2
+
3
+ type I18NMessages = Record<string, string> | Record<string, MessageFormatElement[]>;
4
+
5
+ export type { I18NMessages };
package/dist/types.js ADDED
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
14
+ };
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+
17
+ // src/types.ts
18
+ var types_exports = {};
19
+ module.exports = __toCommonJS(types_exports);
package/dist/types.mjs ADDED
@@ -0,0 +1 @@
1
+ "use client";
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@kopexa/i18n",
3
+ "version": "0.0.0-canary-20250926082443",
4
+ "description": "i18n provider for kopexa apps",
5
+ "keywords": [
6
+ "i18n"
7
+ ],
8
+ "author": "Kopexa <hello@kopexa.com>",
9
+ "homepage": "https://kopexa.com",
10
+ "license": "Apache-2.0",
11
+ "main": "dist/index.js",
12
+ "sideEffects": false,
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/kopexa-grc/sight.git",
22
+ "directory": "packages/core/i18n"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/kopexa-grc/sight/issues"
26
+ },
27
+ "peerDependencies": {
28
+ "react": ">=19.0.0-rc.0",
29
+ "react-dom": ">=19.0.0-rc.0",
30
+ "motion": ">=12.23.6",
31
+ "@kopexa/theme": "0.0.0-canary-20250926082443"
32
+ },
33
+ "dependencies": {
34
+ "react-intl": "^7.1.11",
35
+ "@kopexa/shared-utils": "0.0.0-canary-20250926082443",
36
+ "@kopexa/react-utils": "0.0.0-canary-20250926082443"
37
+ },
38
+ "clean-package": "../../../clean-package.config.json",
39
+ "module": "dist/index.mjs",
40
+ "types": "dist/index.d.ts",
41
+ "exports": {
42
+ ".": {
43
+ "types": "./dist/index.d.ts",
44
+ "import": "./dist/index.mjs",
45
+ "require": "./dist/index.js"
46
+ },
47
+ "./package.json": "./package.json"
48
+ },
49
+ "scripts": {
50
+ "build": "tsup src --dts",
51
+ "build:fast": "tsup src",
52
+ "dev": "pnpm build:fast --watch",
53
+ "clean": "rimraf dist .turbo",
54
+ "typecheck": "tsc --noEmit"
55
+ }
56
+ }