@workos-inc/widgets-i18n 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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +219 -0
- package/dist/cjs/index.cjs +38 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +4 -0
- package/dist/cjs/lib/dictionaries.cjs +178 -0
- package/dist/cjs/lib/dictionaries.cjs.map +1 -0
- package/dist/cjs/lib/dictionaries.d.cts +24924 -0
- package/dist/cjs/lib/locale-provider.cjs +92 -0
- package/dist/cjs/lib/locale-provider.cjs.map +1 -0
- package/dist/cjs/lib/locale-provider.d.cts +12 -0
- package/dist/cjs/lib/types/react.d.cjs +3 -0
- package/dist/cjs/lib/types/react.d.cjs.map +1 -0
- package/dist/cjs/lib/types/react.d.d.cts +5 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/dictionaries.d.ts +24924 -0
- package/dist/esm/lib/dictionaries.js +140 -0
- package/dist/esm/lib/dictionaries.js.map +1 -0
- package/dist/esm/lib/locale-provider.d.ts +12 -0
- package/dist/esm/lib/locale-provider.js +64 -0
- package/dist/esm/lib/locale-provider.js.map +1 -0
- package/dist/esm/lib/types/react.d.d.ts +5 -0
- package/dist/esm/lib/types/react.d.js +2 -0
- package/dist/esm/lib/types/react.d.js.map +1 -0
- package/dist/lang/translations/af.json +281 -0
- package/dist/lang/translations/am.json +281 -0
- package/dist/lang/translations/ar.json +281 -0
- package/dist/lang/translations/bg.json +281 -0
- package/dist/lang/translations/bn.json +281 -0
- package/dist/lang/translations/bs.json +281 -0
- package/dist/lang/translations/ca.json +281 -0
- package/dist/lang/translations/cs.json +281 -0
- package/dist/lang/translations/da.json +281 -0
- package/dist/lang/translations/de.json +284 -0
- package/dist/lang/translations/el.json +281 -0
- package/dist/lang/translations/en-AU.json +281 -0
- package/dist/lang/translations/en-CA.json +281 -0
- package/dist/lang/translations/en-GB.json +281 -0
- package/dist/lang/translations/en-US.json +280 -0
- package/dist/lang/translations/es-419.json +281 -0
- package/dist/lang/translations/es-US.json +281 -0
- package/dist/lang/translations/es.json +281 -0
- package/dist/lang/translations/et.json +281 -0
- package/dist/lang/translations/fa.json +281 -0
- package/dist/lang/translations/fi.json +281 -0
- package/dist/lang/translations/fil.json +281 -0
- package/dist/lang/translations/fr-BE.json +281 -0
- package/dist/lang/translations/fr-CA.json +281 -0
- package/dist/lang/translations/fr.json +281 -0
- package/dist/lang/translations/fy.json +281 -0
- package/dist/lang/translations/gl.json +281 -0
- package/dist/lang/translations/gu.json +281 -0
- package/dist/lang/translations/ha.json +281 -0
- package/dist/lang/translations/he.json +281 -0
- package/dist/lang/translations/hi.json +281 -0
- package/dist/lang/translations/hr.json +281 -0
- package/dist/lang/translations/hu.json +281 -0
- package/dist/lang/translations/hy.json +281 -0
- package/dist/lang/translations/id.json +281 -0
- package/dist/lang/translations/is.json +281 -0
- package/dist/lang/translations/it.json +281 -0
- package/dist/lang/translations/ja.json +281 -0
- package/dist/lang/translations/jv.json +281 -0
- package/dist/lang/translations/ka.json +281 -0
- package/dist/lang/translations/kk.json +281 -0
- package/dist/lang/translations/km.json +281 -0
- package/dist/lang/translations/kn.json +281 -0
- package/dist/lang/translations/ko.json +281 -0
- package/dist/lang/translations/lt.json +280 -0
- package/dist/lang/translations/lv.json +281 -0
- package/dist/lang/translations/mk.json +281 -0
- package/dist/lang/translations/ml.json +281 -0
- package/dist/lang/translations/mn.json +281 -0
- package/dist/lang/translations/mr.json +281 -0
- package/dist/lang/translations/ms.json +281 -0
- package/dist/lang/translations/my.json +281 -0
- package/dist/lang/translations/nb.json +281 -0
- package/dist/lang/translations/ne.json +281 -0
- package/dist/lang/translations/nl-BE.json +281 -0
- package/dist/lang/translations/nl.json +281 -0
- package/dist/lang/translations/nn.json +281 -0
- package/dist/lang/translations/no.json +281 -0
- package/dist/lang/translations/pa.json +281 -0
- package/dist/lang/translations/pl.json +281 -0
- package/dist/lang/translations/pt-BR.json +281 -0
- package/dist/lang/translations/pt.json +281 -0
- package/dist/lang/translations/ro.json +281 -0
- package/dist/lang/translations/ru.json +281 -0
- package/dist/lang/translations/sk.json +281 -0
- package/dist/lang/translations/sl.json +281 -0
- package/dist/lang/translations/sq.json +281 -0
- package/dist/lang/translations/sr.json +281 -0
- package/dist/lang/translations/sv.json +281 -0
- package/dist/lang/translations/sw.json +281 -0
- package/dist/lang/translations/ta.json +281 -0
- package/dist/lang/translations/te.json +281 -0
- package/dist/lang/translations/th.json +281 -0
- package/dist/lang/translations/tr.json +281 -0
- package/dist/lang/translations/uk.json +281 -0
- package/dist/lang/translations/ur.json +281 -0
- package/dist/lang/translations/uz.json +281 -0
- package/dist/lang/translations/vi.json +281 -0
- package/dist/lang/translations/zh-CN.json +280 -0
- package/dist/lang/translations/zh-HK.json +281 -0
- package/dist/lang/translations/zh-TW.json +281 -0
- package/dist/lang/translations/zu.json +281 -0
- package/package.json +63 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var locale_provider_exports = {};
|
|
31
|
+
__export(locale_provider_exports, {
|
|
32
|
+
WorkOsLocaleProvider: () => WorkOsLocaleProvider
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(locale_provider_exports);
|
|
35
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
var React = __toESM(require("react"), 1);
|
|
37
|
+
var import_react_intl = require("react-intl");
|
|
38
|
+
var import_dictionaries = require("./dictionaries.js");
|
|
39
|
+
var import_widgets = require("@workos-inc/widgets");
|
|
40
|
+
function IntlContextProvider({ children }) {
|
|
41
|
+
const intl = (0, import_react_intl.useIntl)();
|
|
42
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
43
|
+
import_widgets.internal_IntlContext.Provider,
|
|
44
|
+
{
|
|
45
|
+
value: {
|
|
46
|
+
locale: intl.locale,
|
|
47
|
+
formatMessage: React.useCallback(
|
|
48
|
+
(...args) => intl.formatMessage(...args),
|
|
49
|
+
[intl]
|
|
50
|
+
)
|
|
51
|
+
},
|
|
52
|
+
children
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
function WorkOsLocaleProvider({
|
|
57
|
+
children,
|
|
58
|
+
locale,
|
|
59
|
+
initialMessages
|
|
60
|
+
}) {
|
|
61
|
+
const [messages, setMessages] = React.useState(
|
|
62
|
+
initialMessages ?? null
|
|
63
|
+
);
|
|
64
|
+
React.useEffect(() => {
|
|
65
|
+
let isCurrent = true;
|
|
66
|
+
(0, import_dictionaries.getDictionary)(locale).then((messages2) => {
|
|
67
|
+
if (isCurrent) {
|
|
68
|
+
setMessages(messages2);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return () => {
|
|
72
|
+
isCurrent = false;
|
|
73
|
+
};
|
|
74
|
+
}, [locale]);
|
|
75
|
+
if (!messages) {
|
|
76
|
+
return children;
|
|
77
|
+
}
|
|
78
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
79
|
+
import_react_intl.IntlProvider,
|
|
80
|
+
{
|
|
81
|
+
defaultLocale: import_dictionaries.DEFAULT_LOCALE,
|
|
82
|
+
locale,
|
|
83
|
+
messages,
|
|
84
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntlContextProvider, { children })
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
WorkOsLocaleProvider
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=locale-provider.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/locale-provider.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport {\n IntlProvider as ReactIntlProvider,\n useIntl as useReactIntl,\n} from \"react-intl\";\nimport {\n DEFAULT_LOCALE,\n getDictionary,\n type LocaleCode,\n type Dictionary,\n} from \"./dictionaries.js\";\nimport { internal_IntlContext as IntlContext } from \"@workos-inc/widgets\";\n\nfunction IntlContextProvider({ children }: { children: React.ReactNode }) {\n const intl = useReactIntl();\n return (\n <IntlContext.Provider\n value={{\n locale: intl.locale,\n formatMessage: React.useCallback(\n (...args) => intl.formatMessage(...args),\n [intl],\n ),\n }}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n\nexport interface WorkOsLocaleProviderProps {\n children: React.ReactNode;\n locale: LocaleCode;\n initialMessages?: Dictionary;\n}\n\nexport function WorkOsLocaleProvider({\n children,\n locale,\n initialMessages,\n}: WorkOsLocaleProviderProps) {\n // TODO: When we decide we want to force a dependency on React 19, we can\n // remove the state and effect here and unwrap the promise via React.use +\n // Suspense. In the meantime we will do this client-side via useEffect, but\n // for users on React 19 who want to handle this on the server, we expose an\n // `initialMessages` prop and export the `getDictionary` function. So they can\n // do this themselves and get the same optimized behavior (minus the minor\n // overhead of `useEffect`). Example:\n //\n // import { getDictionary, WorkOsLocaleProvider } from \"@workos-inc/widgets-i18n\";\n // function UserApp ({ children }) {\n // const messages = React.use(getDictionary('fr-FR'));\n // return (\n // <React.Suspense fallback={<Loading />}>\n // <WorkOsLocaleProvider locale={locale}>\n // {children}\n // </WorkOsLocaleProvider>\n // </React.Suspense>\n // );\n //}\n\n const [messages, setMessages] = React.useState<Dictionary | null>(\n initialMessages ?? null,\n );\n\n React.useEffect(() => {\n let isCurrent = true;\n getDictionary(locale).then((messages) => {\n if (isCurrent) {\n setMessages(messages);\n }\n });\n return () => {\n isCurrent = false;\n };\n }, [locale]);\n\n if (!messages) {\n return children;\n }\n\n return (\n <ReactIntlProvider\n defaultLocale={DEFAULT_LOCALE}\n locale={locale}\n messages={messages}\n >\n <IntlContextProvider>{children}</IntlContextProvider>\n </ReactIntlProvider>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBI;AAhBJ,YAAuB;AACvB,wBAGO;AACP,0BAKO;AACP,qBAAoD;AAEpD,SAAS,oBAAoB,EAAE,SAAS,GAAkC;AACxE,QAAM,WAAO,kBAAAA,SAAa;AAC1B,SACE;AAAA,IAAC,eAAAC,qBAAY;AAAA,IAAZ;AAAA,MACC,OAAO;AAAA,QACL,QAAQ,KAAK;AAAA,QACb,eAAe,MAAM;AAAA,UACnB,IAAI,SAAS,KAAK,cAAc,GAAG,IAAI;AAAA,UACvC,CAAC,IAAI;AAAA,QACP;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAQO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,GAA8B;AAqB5B,QAAM,CAAC,UAAU,WAAW,IAAI,MAAM;AAAA,IACpC,mBAAmB;AAAA,EACrB;AAEA,QAAM,UAAU,MAAM;AACpB,QAAI,YAAY;AAChB,2CAAc,MAAM,EAAE,KAAK,CAACC,cAAa;AACvC,UAAI,WAAW;AACb,oBAAYA,SAAQ;AAAA,MACtB;AAAA,IACF,CAAC;AACD,WAAO,MAAM;AACX,kBAAY;AAAA,IACd;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AAEX,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,SACE;AAAA,IAAC,kBAAAC;AAAA,IAAA;AAAA,MACC,eAAe;AAAA,MACf;AAAA,MACA;AAAA,MAEA,sDAAC,uBAAqB,UAAS;AAAA;AAAA,EACjC;AAEJ;","names":["useReactIntl","IntlContext","messages","ReactIntlProvider"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LocaleCode, Dictionary } from './dictionaries.cjs';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
interface WorkOsLocaleProviderProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
locale: LocaleCode;
|
|
8
|
+
initialMessages?: Dictionary;
|
|
9
|
+
}
|
|
10
|
+
declare function WorkOsLocaleProvider({ children, locale, initialMessages, }: WorkOsLocaleProviderProps): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null | undefined;
|
|
11
|
+
|
|
12
|
+
export { WorkOsLocaleProvider, type WorkOsLocaleProviderProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/types/react.d.ts"],"sourcesContent":["import \"react\";\n\ndeclare module \"react\" {\n interface CSSProperties {\n [key: `--${string}`]: string | number;\n }\n}\n"],"mappings":";AAAA,mBAAO;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isValidLocale,
|
|
3
|
+
getDictionary,
|
|
4
|
+
getDir,
|
|
5
|
+
getLocaleCodes
|
|
6
|
+
} from "./lib/dictionaries.js";
|
|
7
|
+
import { WorkOsLocaleProvider } from "./lib/locale-provider.js";
|
|
8
|
+
export {
|
|
9
|
+
WorkOsLocaleProvider,
|
|
10
|
+
getDictionary,
|
|
11
|
+
getDir,
|
|
12
|
+
getLocaleCodes,
|
|
13
|
+
isValidLocale
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n isValidLocale,\n getDictionary,\n getDir,\n getLocaleCodes,\n type LocaleCode,\n} from \"./lib/dictionaries.js\";\nexport { WorkOsLocaleProvider } from \"./lib/locale-provider.js\";\nexport type { WorkOsLocaleProviderProps } from \"./lib/locale-provider.js\";\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,4BAA4B;","names":[]}
|