@lingui/react 3.14.0 → 3.16.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 +367 -0
- package/build/LICENSE +21 -0
- package/{cjs/react.development.js → build/cjs/index.js} +71 -78
- package/build/cjs/index.js.map +1 -0
- package/{esm/react.development.js → build/esm/index.js} +55 -54
- package/build/esm/index.js.map +1 -0
- package/{esm → build/esm}/package.json +0 -0
- package/build/index.d.ts +47 -0
- package/build/index.js +1 -0
- package/package.json +16 -10
- package/cjs/I18nProvider.d.ts +0 -18
- package/cjs/I18nProvider.d.ts.map +0 -1
- package/cjs/Trans.d.ts +0 -29
- package/cjs/Trans.d.ts.map +0 -1
- package/cjs/format.d.ts +0 -13
- package/cjs/format.d.ts.map +0 -1
- package/cjs/index.d.ts +0 -3
- package/cjs/index.d.ts.map +0 -1
- package/cjs/react.development.js.map +0 -1
- package/cjs/react.production.min.js +0 -2
- package/cjs/react.production.min.js.map +0 -1
- package/esm/I18nProvider.d.ts +0 -18
- package/esm/I18nProvider.d.ts.map +0 -1
- package/esm/Trans.d.ts +0 -29
- package/esm/Trans.d.ts.map +0 -1
- package/esm/format.d.ts +0 -13
- package/esm/format.d.ts.map +0 -1
- package/esm/index.d.ts +0 -3
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -12
- package/esm/react.development.js.map +0 -1
- package/esm/react.production.min.js +0 -2
- package/esm/react.production.min.js.map +0 -1
- package/index.js +0 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/I18nProvider.tsx","../../src/format.ts","../../src/Trans.tsx"],"sourcesContent":["import React, { ComponentType, FunctionComponent } from \"react\"\nimport { I18n } from \"@lingui/core\"\nimport { TransRenderProps } from \"./Trans\"\n\nexport type I18nContext = {\n i18n: I18n\n defaultComponent?: ComponentType<TransRenderProps>\n}\n\nexport type withI18nProps = {\n i18n: I18n\n}\n\nexport type I18nProviderProps = I18nContext & {\n forceRenderOnLocaleChange?: boolean\n children?: React.ReactNode\n}\n\nconst LinguiContext = React.createContext<I18nContext>(null)\n\nexport function useLingui(): I18nContext {\n const context = React.useContext<I18nContext>(LinguiContext)\n\n if (process.env.NODE_ENV !== \"production\") {\n if (context == null) {\n throw new Error(\"useLingui hook was used without I18nProvider.\")\n }\n }\n\n return context\n}\n\nexport function withI18n(\n o?: object\n): <P extends withI18nProps>(\n Component: ComponentType<P>\n) => React.ComponentType<Omit<P, 'i18n'>> {\n return <P extends withI18nProps>(\n WrappedComponent: ComponentType<P>\n ): ComponentType<P> => {\n return (props) => {\n if (process.env.NODE_ENV !== \"production\") {\n if (typeof o === \"function\" || React.isValidElement(o)) {\n throw new Error(\n \"withI18n([options]) takes options as a first argument, \" +\n \"but received React component itself. Without options, the Component \" +\n \"should be wrapped as withI18n()(Component), not withI18n(Component).\"\n )\n }\n }\n\n const { i18n } = useLingui()\n return <WrappedComponent {...props} i18n={i18n} />\n }\n }\n}\n\nexport const I18nProvider: FunctionComponent<I18nProviderProps> = ({\n i18n,\n defaultComponent,\n forceRenderOnLocaleChange = true,\n children,\n}) => {\n /**\n * We can't pass `i18n` object directly through context, because even when locale\n * or messages are changed, i18n object is still the same. Context provider compares\n * reference identity and suggested workaround is create a wrapper object every time\n * we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.\n *\n * Due to this effect we also pass `defaultComponent` in the same context, instead\n * of creating a separate Provider/Consumer pair.\n *\n * We can't use useMemo hook either, because we want to recalculate value manually.\n */\n const makeContext = () => ({\n i18n,\n defaultComponent,\n })\n const getRenderKey = () => {\n return (forceRenderOnLocaleChange ? (i18n.locale || 'default') : 'default') as string\n }\n\n const [context, setContext] = React.useState<I18nContext>(makeContext()),\n [renderKey, setRenderKey] = React.useState<string>(getRenderKey())\n\n /**\n * Subscribe for locale/message changes\n *\n * I18n object from `@lingui/core` is the single source of truth for all i18n related\n * data (active locale, catalogs). When new messages are loaded or locale is changed\n * we need to trigger re-rendering of LinguiContext.Consumers.\n *\n * We call `setContext(makeContext())` after adding the observer in case the `change`\n * event would already have fired between the inital renderKey calculation and the\n * `useEffect` hook being called. This can happen if locales are loaded/activated\n * async.\n */\n React.useEffect(() => {\n const unsubscribe = i18n.on(\"change\", () => {\n setContext(makeContext())\n setRenderKey(getRenderKey())\n })\n if (renderKey === 'default') {\n setRenderKey(getRenderKey())\n }\n if (forceRenderOnLocaleChange && renderKey === 'default') {\n console.log(\"I18nProvider did not render. A call to i18n.activate still needs to happen or forceRenderOnLocaleChange must be set to false.\")\n }\n return () => unsubscribe()\n }, [])\n\n if (forceRenderOnLocaleChange && renderKey === 'default') return null\n\n return (\n <LinguiContext.Provider value={context} key={renderKey}>\n {children}\n </LinguiContext.Provider>\n )\n}\n","import React from \"react\"\n\n// match <0>paired</0> and <1/> unpaired tags\nconst tagRe = /<(\\d+)>(.*?)<\\/\\1>|<(\\d+)\\/>/\nconst nlRe = /(?:\\r\\n|\\r|\\n)/g\n\n// For HTML, certain tags should omit their close tag. We keep a whitelist for\n// those special-case tags.\nconst voidElementTags = {\n area: true,\n base: true,\n br: true,\n col: true,\n embed: true,\n hr: true,\n img: true,\n input: true,\n keygen: true,\n link: true,\n meta: true,\n param: true,\n source: true,\n track: true,\n wbr: true,\n menuitem: true\n}\n\n/**\n * `formatElements` - parse string and return tree of react elements\n *\n * `value` is string to be formatted with <0>Paired<0/> or <0/> (unpaired)\n * placeholders. `elements` is a array of react elements which indexes\n * correspond to element indexes in formatted string\n */\nfunction formatElements(\n value: string,\n elements: { [key: string]: React.ReactElement<any> } = {}\n): string | Array<any> {\n const uniqueId = makeCounter(0, '$lingui$')\n const parts = value.replace(nlRe, \"\").split(tagRe)\n\n // no inline elements, return\n if (parts.length === 1) return value\n\n const tree = []\n\n const before = parts.shift()\n if (before) tree.push(before)\n\n for (const [index, children, after] of getElements(parts)) {\n let element = elements[index]\n\n if (!element || (voidElementTags[element.type as string] && children)) {\n if (!element) {\n console.error(\n `Can use element at index '${index}' as it is not declared in the original translation`\n )\n } else {\n console.error(\n `${element.type} is a void element tag therefore it must have no children`\n )\n }\n\n // ignore problematic element but push its children and elements after it\n element = React.createElement(React.Fragment)\n }\n\n tree.push(\n React.cloneElement(\n element,\n { key: uniqueId() },\n\n // format children for pair tags\n // unpaired tags might have children if it's a component passed as a variable\n children ? formatElements(children, elements) : element.props.children\n )\n )\n\n if (after) tree.push(after)\n }\n\n return tree\n}\n\n/*\n * `getElements` - return array of element indexes and element childrens\n *\n * `parts` is array of [pairedIndex, children, unpairedIndex, textAfter, ...]\n * where:\n * - `pairedIndex` is index of paired element (undef for unpaired)\n * - `children` are children of paired element (undef for unpaired)\n * - `unpairedIndex` is index of unpaired element (undef for paired)\n * - `textAfter` is string after all elements (empty string, if there's nothing)\n *\n * `parts` length is always multiply of 4\n *\n * Returns: Array<[elementIndex, children, after]>\n */\nfunction getElements(parts) {\n if (!parts.length) return []\n\n const [paired, children, unpaired, after] = parts.slice(0, 4)\n\n return [[parseInt(paired || unpaired), children || \"\", after]].concat(\n getElements(parts.slice(4, parts.length))\n )\n}\n\nconst makeCounter = (count = 0, prefix = \"\") => () => `${prefix}_${count++}`\n\nexport { formatElements }\n","import React from \"react\"\n\nimport { useLingui } from \"./I18nProvider\"\nimport { formatElements } from \"./format\"\n\nexport type TransRenderProps = {\n id?: string\n translation?: React.ReactNode\n children?: React.ReactNode\n message?: string | null\n isTranslated?: boolean\n}\n\nexport type TransProps = {\n id: string\n message?: string\n values: Record<string, unknown>\n context?: string\n components: { [key: string]: React.ElementType | any }\n formats?: Record<string, unknown>\n children?: React.ReactNode\n component?: React.ComponentType<TransRenderProps>\n render?: (props: TransRenderProps) => React.ReactElement<any, any> | null\n}\n\nexport function Trans(props: TransProps): React.ReactElement<any, any> | null {\n const { i18n, defaultComponent } = useLingui()\n const { render, component, id, message, formats } = props\n\n const values = { ...props.values }\n const components = { ...props.components }\n\n if (values) {\n /*\n Related discussion: https://github.com/lingui/js-lingui/issues/183\n\n Values *might* contain React elements with static content.\n They're replaced with <INDEX /> placeholders and added to `components`.\n\n Example:\n Translation: Hello {name}\n Values: { name: <strong>Jane</strong> }\n\n It'll become \"Hello <0 />\" with components=[<strong>Jane</strong>]\n */\n\n Object.keys(values).forEach((key) => {\n const value = values[key]\n if (!React.isValidElement(value)) return\n\n const index = Object.keys(components).length\n\n components[index] = value\n values[key] = `<${index}/>`\n })\n }\n\n const _translation: string =\n i18n && typeof i18n._ === \"function\"\n ? i18n._(id, values, { message, formats })\n : id // i18n provider isn't loaded at all\n\n const translation = _translation\n ? formatElements(_translation, components)\n : null\n\n if (render === null || component === null) {\n // Although `string` is a valid react element, types only allow `Element`\n // Upstream issue: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544\n return (translation as unknown) as React.ReactElement<any, any>\n }\n\n const FallbackComponent = (defaultComponent ||\n React.Fragment) as React.ComponentType<any>\n\n const i18nProps = {\n id,\n message,\n translation,\n isTranslated: id !== translation && message !== translation,\n }\n\n // Validation of `render` and `component` props\n if (render && component) {\n console.error(\n \"You can't use both `component` and `render` prop at the same time. `component` is ignored.\"\n )\n } else if (render && typeof render !== \"function\") {\n console.error(\n `Invalid value supplied to prop \\`render\\`. It must be a function, provided ${render}`\n )\n } else if (component && typeof component !== \"function\") {\n // Apparently, both function components and class components are functions\n // See https://stackoverflow.com/a/41658173/1535540\n console.error(\n `Invalid value supplied to prop \\`component\\`. It must be a React component, provided ${component}`\n )\n return <FallbackComponent {...i18nProps}>{translation}</FallbackComponent>\n }\n\n // Rendering using a render prop\n if (typeof render === \"function\") {\n // Component: render={(props) => <a title={props.translation}>x</a>}\n return render(i18nProps)\n }\n\n // `component` prop has a higher precedence over `defaultComponent`\n const Component = (component || FallbackComponent) as React.ComponentType<any>\n const DefaultComponent = defaultComponent\n\n return DefaultComponent && !component ? (\n <DefaultComponent {...i18nProps}>{translation}</DefaultComponent>\n ) : (\n <Component>{translation}</Component>\n )\n}\n\nTrans.defaultProps = {\n values: {},\n components: {},\n}\n"],"names":["LinguiContext","React","createContext","useLingui","context","useContext","process","env","NODE_ENV","Error","withI18n","o","WrappedComponent","props","isValidElement","i18n","I18nProvider","defaultComponent","forceRenderOnLocaleChange","children","makeContext","getRenderKey","locale","useState","setContext","renderKey","setRenderKey","useEffect","unsubscribe","on","console","log","tagRe","nlRe","voidElementTags","area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr","menuitem","formatElements","value","elements","uniqueId","makeCounter","parts","replace","split","length","tree","before","shift","push","getElements","index","after","element","type","error","createElement","Fragment","cloneElement","key","slice","paired","unpaired","parseInt","concat","count","prefix","Trans","render","component","id","message","formats","values","components","Object","keys","forEach","_translation","_","translation","FallbackComponent","i18nProps","isTranslated","Component","DefaultComponent","defaultProps"],"mappings":";;;;;;;AAkBA,IAAMA,aAAa,gBAAGC,KAAK,CAACC,aAAN,CAAiC,IAAjC,CAAtB,CAAA;AAEO,SAASC,SAAT,GAAkC;AACvC,EAAA,IAAMC,OAAO,GAAGH,KAAK,CAACI,UAAN,CAA8BL,aAA9B,CAAhB,CAAA;;AAEA,EAAA,IAAIM,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,IAAIJ,IAAAA,OAAO,IAAI,IAAf,EAAqB;AACnB,MAAA,MAAM,IAAIK,KAAJ,CAAU,+CAAV,CAAN,CAAA;AACD,KAAA;AACF,GAAA;;AAED,EAAA,OAAOL,OAAP,CAAA;AACD,CAAA;AAEM,SAASM,QAAT,CACLC,CADK,EAImC;AACxC,EAAO,OAAA,UACLC,gBADK,EAEgB;AACrB,IAAO,OAAA,UAACC,KAAD,EAAW;AAChB,MAAA,IAAIP,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,QAAI,IAAA,OAAOG,CAAP,KAAa,UAAb,iBAA2BV,KAAK,CAACa,cAAN,CAAqBH,CAArB,CAA/B,EAAwD;AACtD,UAAA,MAAM,IAAIF,KAAJ,CACJ,4DACE,sEADF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AAA,OAAO,CAACuC,KAAR,CAAA,2EAAA,CAAA,MAAA,CACgFa,MADhF,CAAA,CAAA,CAAA;AAGD,GAJM,MAIA,IAAIC,SAAS,IAAI,OAAOA,SAAP,KAAqB,UAAtC,EAAkD;AACvD;AACA;AACArD,IAAAA,OAAO,CAACuC,KAAR,CAAA,qFAAA,CAAA,MAAA,CAC0Fc,SAD1F,CAAA,CAAA,CAAA;AAGA,IAAA,oBAAO,oBAAC,iBAAD,EAAuBa,SAAvB,EAAmCF,WAAnC,CAAP,CAAA;AACD,GAzE2E;;;AA4E5E,EAAA,IAAI,OAAOZ,MAAP,KAAkB,UAAtB,EAAkC;AAChC;AACA,IAAOA,OAAAA,MAAM,CAACc,SAAD,CAAb,CAAA;AACD,GA/E2E;;;AAkF5E,EAAA,IAAME,SAAS,GAAIf,SAAS,IAAIY,iBAAhC,CAAA;AACA,EAAMI,IAAAA,gBAAgB,GAAGlF,gBAAzB,CAAA;AAEA,EAAA,OAAOkF,gBAAgB,IAAI,CAAChB,SAArB,gBACL,oBAAC,gBAAD,EAAsBa,SAAtB,EAAkCF,WAAlC,CADK,gBAGL,oBAAC,SAAD,EAAA,IAAA,EAAYA,WAAZ,CAHF,CAAA;AAKD,CAAA;AAEDb,KAAK,CAACmB,YAAN,GAAqB;AACnBb,EAAAA,MAAM,EAAE,EADW;AAEnBC,EAAAA,UAAU,EAAE,EAAA;AAFO,CAArB;;;;;;;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
+
import _extends from '@babel/runtime/helpers/extends';
|
|
2
3
|
import React from 'react';
|
|
3
4
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
5
|
|
|
@@ -6,7 +7,7 @@ var LinguiContext = /*#__PURE__*/React.createContext(null);
|
|
|
6
7
|
function useLingui() {
|
|
7
8
|
var context = React.useContext(LinguiContext);
|
|
8
9
|
|
|
9
|
-
{
|
|
10
|
+
if (process.env.NODE_ENV !== "production") {
|
|
10
11
|
if (context == null) {
|
|
11
12
|
throw new Error("useLingui hook was used without I18nProvider.");
|
|
12
13
|
}
|
|
@@ -17,7 +18,7 @@ function useLingui() {
|
|
|
17
18
|
function withI18n(o) {
|
|
18
19
|
return function (WrappedComponent) {
|
|
19
20
|
return function (props) {
|
|
20
|
-
{
|
|
21
|
+
if (process.env.NODE_ENV !== "production") {
|
|
21
22
|
if (typeof o === "function" || /*#__PURE__*/React.isValidElement(o)) {
|
|
22
23
|
throw new Error("withI18n([options]) takes options as a first argument, " + "but received React component itself. Without options, the Component " + "should be wrapped as withI18n()(Component), not withI18n(Component).");
|
|
23
24
|
}
|
|
@@ -26,7 +27,7 @@ function withI18n(o) {
|
|
|
26
27
|
var _useLingui = useLingui(),
|
|
27
28
|
i18n = _useLingui.i18n;
|
|
28
29
|
|
|
29
|
-
return /*#__PURE__*/React.createElement(WrappedComponent,
|
|
30
|
+
return /*#__PURE__*/React.createElement(WrappedComponent, _extends({}, props, {
|
|
30
31
|
i18n: i18n
|
|
31
32
|
}));
|
|
32
33
|
};
|
|
@@ -39,16 +40,16 @@ var I18nProvider = function I18nProvider(_ref) {
|
|
|
39
40
|
forceRenderOnLocaleChange = _ref$forceRenderOnLoc === void 0 ? true : _ref$forceRenderOnLoc,
|
|
40
41
|
children = _ref.children;
|
|
41
42
|
|
|
42
|
-
/**
|
|
43
|
-
* We can't pass `i18n` object directly through context, because even when locale
|
|
44
|
-
* or messages are changed, i18n object is still the same. Context provider compares
|
|
45
|
-
* reference identity and suggested workaround is create a wrapper object every time
|
|
46
|
-
* we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.
|
|
47
|
-
*
|
|
48
|
-
* Due to this effect we also pass `defaultComponent` in the same context, instead
|
|
49
|
-
* of creating a separate Provider/Consumer pair.
|
|
50
|
-
*
|
|
51
|
-
* We can't use useMemo hook either, because we want to recalculate value manually.
|
|
43
|
+
/**
|
|
44
|
+
* We can't pass `i18n` object directly through context, because even when locale
|
|
45
|
+
* or messages are changed, i18n object is still the same. Context provider compares
|
|
46
|
+
* reference identity and suggested workaround is create a wrapper object every time
|
|
47
|
+
* we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.
|
|
48
|
+
*
|
|
49
|
+
* Due to this effect we also pass `defaultComponent` in the same context, instead
|
|
50
|
+
* of creating a separate Provider/Consumer pair.
|
|
51
|
+
*
|
|
52
|
+
* We can't use useMemo hook either, because we want to recalculate value manually.
|
|
52
53
|
*/
|
|
53
54
|
var makeContext = function makeContext() {
|
|
54
55
|
return {
|
|
@@ -69,17 +70,17 @@ var I18nProvider = function I18nProvider(_ref) {
|
|
|
69
70
|
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
70
71
|
renderKey = _React$useState4[0],
|
|
71
72
|
setRenderKey = _React$useState4[1];
|
|
72
|
-
/**
|
|
73
|
-
* Subscribe for locale/message changes
|
|
74
|
-
*
|
|
75
|
-
* I18n object from `@lingui/core` is the single source of truth for all i18n related
|
|
76
|
-
* data (active locale, catalogs). When new messages are loaded or locale is changed
|
|
77
|
-
* we need to trigger re-rendering of LinguiContext.Consumers.
|
|
78
|
-
*
|
|
79
|
-
* We call `setContext(makeContext())` after adding the observer in case the `change`
|
|
80
|
-
* event would already have fired between the inital renderKey calculation and the
|
|
81
|
-
* `useEffect` hook being called. This can happen if locales are loaded/activated
|
|
82
|
-
* async.
|
|
73
|
+
/**
|
|
74
|
+
* Subscribe for locale/message changes
|
|
75
|
+
*
|
|
76
|
+
* I18n object from `@lingui/core` is the single source of truth for all i18n related
|
|
77
|
+
* data (active locale, catalogs). When new messages are loaded or locale is changed
|
|
78
|
+
* we need to trigger re-rendering of LinguiContext.Consumers.
|
|
79
|
+
*
|
|
80
|
+
* We call `setContext(makeContext())` after adding the observer in case the `change`
|
|
81
|
+
* event would already have fired between the inital renderKey calculation and the
|
|
82
|
+
* `useEffect` hook being called. This can happen if locales are loaded/activated
|
|
83
|
+
* async.
|
|
83
84
|
*/
|
|
84
85
|
|
|
85
86
|
|
|
@@ -136,12 +137,12 @@ var voidElementTags = {
|
|
|
136
137
|
wbr: true,
|
|
137
138
|
menuitem: true
|
|
138
139
|
};
|
|
139
|
-
/**
|
|
140
|
-
* `formatElements` - parse string and return tree of react elements
|
|
141
|
-
*
|
|
142
|
-
* `value` is string to be formatted with <0>Paired<0/> or <0/> (unpaired)
|
|
143
|
-
* placeholders. `elements` is a array of react elements which indexes
|
|
144
|
-
* correspond to element indexes in formatted string
|
|
140
|
+
/**
|
|
141
|
+
* `formatElements` - parse string and return tree of react elements
|
|
142
|
+
*
|
|
143
|
+
* `value` is string to be formatted with <0>Paired<0/> or <0/> (unpaired)
|
|
144
|
+
* placeholders. `elements` is a array of react elements which indexes
|
|
145
|
+
* correspond to element indexes in formatted string
|
|
145
146
|
*/
|
|
146
147
|
|
|
147
148
|
function formatElements(value) {
|
|
@@ -192,19 +193,19 @@ function formatElements(value) {
|
|
|
192
193
|
|
|
193
194
|
return tree;
|
|
194
195
|
}
|
|
195
|
-
/*
|
|
196
|
-
* `getElements` - return array of element indexes and element childrens
|
|
197
|
-
*
|
|
198
|
-
* `parts` is array of [pairedIndex, children, unpairedIndex, textAfter, ...]
|
|
199
|
-
* where:
|
|
200
|
-
* - `pairedIndex` is index of paired element (undef for unpaired)
|
|
201
|
-
* - `children` are children of paired element (undef for unpaired)
|
|
202
|
-
* - `unpairedIndex` is index of unpaired element (undef for paired)
|
|
203
|
-
* - `textAfter` is string after all elements (empty string, if there's nothing)
|
|
204
|
-
*
|
|
205
|
-
* `parts` length is always multiply of 4
|
|
206
|
-
*
|
|
207
|
-
* Returns: Array<[elementIndex, children, after]>
|
|
196
|
+
/*
|
|
197
|
+
* `getElements` - return array of element indexes and element childrens
|
|
198
|
+
*
|
|
199
|
+
* `parts` is array of [pairedIndex, children, unpairedIndex, textAfter, ...]
|
|
200
|
+
* where:
|
|
201
|
+
* - `pairedIndex` is index of paired element (undef for unpaired)
|
|
202
|
+
* - `children` are children of paired element (undef for unpaired)
|
|
203
|
+
* - `unpairedIndex` is index of unpaired element (undef for paired)
|
|
204
|
+
* - `textAfter` is string after all elements (empty string, if there's nothing)
|
|
205
|
+
*
|
|
206
|
+
* `parts` length is always multiply of 4
|
|
207
|
+
*
|
|
208
|
+
* Returns: Array<[elementIndex, children, after]>
|
|
208
209
|
*/
|
|
209
210
|
|
|
210
211
|
|
|
@@ -248,14 +249,14 @@ function Trans(props) {
|
|
|
248
249
|
var components = _objectSpread({}, props.components);
|
|
249
250
|
|
|
250
251
|
if (values) {
|
|
251
|
-
/*
|
|
252
|
-
Related discussion: https://github.com/lingui/js-lingui/issues/183
|
|
253
|
-
|
|
254
|
-
They're replaced with <INDEX /> placeholders and added to `components`.
|
|
255
|
-
|
|
256
|
-
Translation: Hello {name}
|
|
257
|
-
Values: { name: <strong>Jane</strong> }
|
|
258
|
-
|
|
252
|
+
/*
|
|
253
|
+
Related discussion: https://github.com/lingui/js-lingui/issues/183
|
|
254
|
+
Values *might* contain React elements with static content.
|
|
255
|
+
They're replaced with <INDEX /> placeholders and added to `components`.
|
|
256
|
+
Example:
|
|
257
|
+
Translation: Hello {name}
|
|
258
|
+
Values: { name: <strong>Jane</strong> }
|
|
259
|
+
It'll become "Hello <0 />" with components=[<strong>Jane</strong>]
|
|
259
260
|
*/
|
|
260
261
|
Object.keys(values).forEach(function (key) {
|
|
261
262
|
var value = values[key];
|
|
@@ -296,7 +297,7 @@ function Trans(props) {
|
|
|
296
297
|
// Apparently, both function components and class components are functions
|
|
297
298
|
// See https://stackoverflow.com/a/41658173/1535540
|
|
298
299
|
console.error("Invalid value supplied to prop `component`. It must be a React component, provided ".concat(component));
|
|
299
|
-
return /*#__PURE__*/React.createElement(FallbackComponent,
|
|
300
|
+
return /*#__PURE__*/React.createElement(FallbackComponent, i18nProps, translation);
|
|
300
301
|
} // Rendering using a render prop
|
|
301
302
|
|
|
302
303
|
|
|
@@ -308,7 +309,7 @@ function Trans(props) {
|
|
|
308
309
|
|
|
309
310
|
var Component = component || FallbackComponent;
|
|
310
311
|
var DefaultComponent = defaultComponent;
|
|
311
|
-
return DefaultComponent && !component ? /*#__PURE__*/React.createElement(DefaultComponent,
|
|
312
|
+
return DefaultComponent && !component ? /*#__PURE__*/React.createElement(DefaultComponent, i18nProps, translation) : /*#__PURE__*/React.createElement(Component, null, translation);
|
|
312
313
|
}
|
|
313
314
|
Trans.defaultProps = {
|
|
314
315
|
values: {},
|
|
@@ -316,4 +317,4 @@ Trans.defaultProps = {
|
|
|
316
317
|
};
|
|
317
318
|
|
|
318
319
|
export { I18nProvider, Trans, useLingui, withI18n };
|
|
319
|
-
//# sourceMappingURL=
|
|
320
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/I18nProvider.tsx","../../src/format.ts","../../src/Trans.tsx"],"sourcesContent":["import React, { ComponentType, FunctionComponent } from \"react\"\nimport { I18n } from \"@lingui/core\"\nimport { TransRenderProps } from \"./Trans\"\n\nexport type I18nContext = {\n i18n: I18n\n defaultComponent?: ComponentType<TransRenderProps>\n}\n\nexport type withI18nProps = {\n i18n: I18n\n}\n\nexport type I18nProviderProps = I18nContext & {\n forceRenderOnLocaleChange?: boolean\n children?: React.ReactNode\n}\n\nconst LinguiContext = React.createContext<I18nContext>(null)\n\nexport function useLingui(): I18nContext {\n const context = React.useContext<I18nContext>(LinguiContext)\n\n if (process.env.NODE_ENV !== \"production\") {\n if (context == null) {\n throw new Error(\"useLingui hook was used without I18nProvider.\")\n }\n }\n\n return context\n}\n\nexport function withI18n(\n o?: object\n): <P extends withI18nProps>(\n Component: ComponentType<P>\n) => React.ComponentType<Omit<P, 'i18n'>> {\n return <P extends withI18nProps>(\n WrappedComponent: ComponentType<P>\n ): ComponentType<P> => {\n return (props) => {\n if (process.env.NODE_ENV !== \"production\") {\n if (typeof o === \"function\" || React.isValidElement(o)) {\n throw new Error(\n \"withI18n([options]) takes options as a first argument, \" +\n \"but received React component itself. Without options, the Component \" +\n \"should be wrapped as withI18n()(Component), not withI18n(Component).\"\n )\n }\n }\n\n const { i18n } = useLingui()\n return <WrappedComponent {...props} i18n={i18n} />\n }\n }\n}\n\nexport const I18nProvider: FunctionComponent<I18nProviderProps> = ({\n i18n,\n defaultComponent,\n forceRenderOnLocaleChange = true,\n children,\n}) => {\n /**\n * We can't pass `i18n` object directly through context, because even when locale\n * or messages are changed, i18n object is still the same. Context provider compares\n * reference identity and suggested workaround is create a wrapper object every time\n * we need to trigger re-render. See https://reactjs.org/docs/context.html#caveats.\n *\n * Due to this effect we also pass `defaultComponent` in the same context, instead\n * of creating a separate Provider/Consumer pair.\n *\n * We can't use useMemo hook either, because we want to recalculate value manually.\n */\n const makeContext = () => ({\n i18n,\n defaultComponent,\n })\n const getRenderKey = () => {\n return (forceRenderOnLocaleChange ? (i18n.locale || 'default') : 'default') as string\n }\n\n const [context, setContext] = React.useState<I18nContext>(makeContext()),\n [renderKey, setRenderKey] = React.useState<string>(getRenderKey())\n\n /**\n * Subscribe for locale/message changes\n *\n * I18n object from `@lingui/core` is the single source of truth for all i18n related\n * data (active locale, catalogs). When new messages are loaded or locale is changed\n * we need to trigger re-rendering of LinguiContext.Consumers.\n *\n * We call `setContext(makeContext())` after adding the observer in case the `change`\n * event would already have fired between the inital renderKey calculation and the\n * `useEffect` hook being called. This can happen if locales are loaded/activated\n * async.\n */\n React.useEffect(() => {\n const unsubscribe = i18n.on(\"change\", () => {\n setContext(makeContext())\n setRenderKey(getRenderKey())\n })\n if (renderKey === 'default') {\n setRenderKey(getRenderKey())\n }\n if (forceRenderOnLocaleChange && renderKey === 'default') {\n console.log(\"I18nProvider did not render. A call to i18n.activate still needs to happen or forceRenderOnLocaleChange must be set to false.\")\n }\n return () => unsubscribe()\n }, [])\n\n if (forceRenderOnLocaleChange && renderKey === 'default') return null\n\n return (\n <LinguiContext.Provider value={context} key={renderKey}>\n {children}\n </LinguiContext.Provider>\n )\n}\n","import React from \"react\"\n\n// match <0>paired</0> and <1/> unpaired tags\nconst tagRe = /<(\\d+)>(.*?)<\\/\\1>|<(\\d+)\\/>/\nconst nlRe = /(?:\\r\\n|\\r|\\n)/g\n\n// For HTML, certain tags should omit their close tag. We keep a whitelist for\n// those special-case tags.\nconst voidElementTags = {\n area: true,\n base: true,\n br: true,\n col: true,\n embed: true,\n hr: true,\n img: true,\n input: true,\n keygen: true,\n link: true,\n meta: true,\n param: true,\n source: true,\n track: true,\n wbr: true,\n menuitem: true\n}\n\n/**\n * `formatElements` - parse string and return tree of react elements\n *\n * `value` is string to be formatted with <0>Paired<0/> or <0/> (unpaired)\n * placeholders. `elements` is a array of react elements which indexes\n * correspond to element indexes in formatted string\n */\nfunction formatElements(\n value: string,\n elements: { [key: string]: React.ReactElement<any> } = {}\n): string | Array<any> {\n const uniqueId = makeCounter(0, '$lingui$')\n const parts = value.replace(nlRe, \"\").split(tagRe)\n\n // no inline elements, return\n if (parts.length === 1) return value\n\n const tree = []\n\n const before = parts.shift()\n if (before) tree.push(before)\n\n for (const [index, children, after] of getElements(parts)) {\n let element = elements[index]\n\n if (!element || (voidElementTags[element.type as string] && children)) {\n if (!element) {\n console.error(\n `Can use element at index '${index}' as it is not declared in the original translation`\n )\n } else {\n console.error(\n `${element.type} is a void element tag therefore it must have no children`\n )\n }\n\n // ignore problematic element but push its children and elements after it\n element = React.createElement(React.Fragment)\n }\n\n tree.push(\n React.cloneElement(\n element,\n { key: uniqueId() },\n\n // format children for pair tags\n // unpaired tags might have children if it's a component passed as a variable\n children ? formatElements(children, elements) : element.props.children\n )\n )\n\n if (after) tree.push(after)\n }\n\n return tree\n}\n\n/*\n * `getElements` - return array of element indexes and element childrens\n *\n * `parts` is array of [pairedIndex, children, unpairedIndex, textAfter, ...]\n * where:\n * - `pairedIndex` is index of paired element (undef for unpaired)\n * - `children` are children of paired element (undef for unpaired)\n * - `unpairedIndex` is index of unpaired element (undef for paired)\n * - `textAfter` is string after all elements (empty string, if there's nothing)\n *\n * `parts` length is always multiply of 4\n *\n * Returns: Array<[elementIndex, children, after]>\n */\nfunction getElements(parts) {\n if (!parts.length) return []\n\n const [paired, children, unpaired, after] = parts.slice(0, 4)\n\n return [[parseInt(paired || unpaired), children || \"\", after]].concat(\n getElements(parts.slice(4, parts.length))\n )\n}\n\nconst makeCounter = (count = 0, prefix = \"\") => () => `${prefix}_${count++}`\n\nexport { formatElements }\n","import React from \"react\"\n\nimport { useLingui } from \"./I18nProvider\"\nimport { formatElements } from \"./format\"\n\nexport type TransRenderProps = {\n id?: string\n translation?: React.ReactNode\n children?: React.ReactNode\n message?: string | null\n isTranslated?: boolean\n}\n\nexport type TransProps = {\n id: string\n message?: string\n values: Record<string, unknown>\n context?: string\n components: { [key: string]: React.ElementType | any }\n formats?: Record<string, unknown>\n children?: React.ReactNode\n component?: React.ComponentType<TransRenderProps>\n render?: (props: TransRenderProps) => React.ReactElement<any, any> | null\n}\n\nexport function Trans(props: TransProps): React.ReactElement<any, any> | null {\n const { i18n, defaultComponent } = useLingui()\n const { render, component, id, message, formats } = props\n\n const values = { ...props.values }\n const components = { ...props.components }\n\n if (values) {\n /*\n Related discussion: https://github.com/lingui/js-lingui/issues/183\n\n Values *might* contain React elements with static content.\n They're replaced with <INDEX /> placeholders and added to `components`.\n\n Example:\n Translation: Hello {name}\n Values: { name: <strong>Jane</strong> }\n\n It'll become \"Hello <0 />\" with components=[<strong>Jane</strong>]\n */\n\n Object.keys(values).forEach((key) => {\n const value = values[key]\n if (!React.isValidElement(value)) return\n\n const index = Object.keys(components).length\n\n components[index] = value\n values[key] = `<${index}/>`\n })\n }\n\n const _translation: string =\n i18n && typeof i18n._ === \"function\"\n ? i18n._(id, values, { message, formats })\n : id // i18n provider isn't loaded at all\n\n const translation = _translation\n ? formatElements(_translation, components)\n : null\n\n if (render === null || component === null) {\n // Although `string` is a valid react element, types only allow `Element`\n // Upstream issue: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544\n return (translation as unknown) as React.ReactElement<any, any>\n }\n\n const FallbackComponent = (defaultComponent ||\n React.Fragment) as React.ComponentType<any>\n\n const i18nProps = {\n id,\n message,\n translation,\n isTranslated: id !== translation && message !== translation,\n }\n\n // Validation of `render` and `component` props\n if (render && component) {\n console.error(\n \"You can't use both `component` and `render` prop at the same time. `component` is ignored.\"\n )\n } else if (render && typeof render !== \"function\") {\n console.error(\n `Invalid value supplied to prop \\`render\\`. It must be a function, provided ${render}`\n )\n } else if (component && typeof component !== \"function\") {\n // Apparently, both function components and class components are functions\n // See https://stackoverflow.com/a/41658173/1535540\n console.error(\n `Invalid value supplied to prop \\`component\\`. It must be a React component, provided ${component}`\n )\n return <FallbackComponent {...i18nProps}>{translation}</FallbackComponent>\n }\n\n // Rendering using a render prop\n if (typeof render === \"function\") {\n // Component: render={(props) => <a title={props.translation}>x</a>}\n return render(i18nProps)\n }\n\n // `component` prop has a higher precedence over `defaultComponent`\n const Component = (component || FallbackComponent) as React.ComponentType<any>\n const DefaultComponent = defaultComponent\n\n return DefaultComponent && !component ? (\n <DefaultComponent {...i18nProps}>{translation}</DefaultComponent>\n ) : (\n <Component>{translation}</Component>\n )\n}\n\nTrans.defaultProps = {\n values: {},\n components: {},\n}\n"],"names":["LinguiContext","React","createContext","useLingui","context","useContext","process","env","NODE_ENV","Error","withI18n","o","WrappedComponent","props","isValidElement","i18n","I18nProvider","defaultComponent","forceRenderOnLocaleChange","children","makeContext","getRenderKey","locale","useState","setContext","renderKey","setRenderKey","useEffect","unsubscribe","on","console","log","tagRe","nlRe","voidElementTags","area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr","menuitem","formatElements","value","elements","uniqueId","makeCounter","parts","replace","split","length","tree","before","shift","push","getElements","index","after","element","type","error","createElement","Fragment","cloneElement","key","slice","paired","unpaired","parseInt","concat","count","prefix","Trans","render","component","id","message","formats","values","components","Object","keys","forEach","_translation","_","translation","FallbackComponent","i18nProps","isTranslated","Component","DefaultComponent","defaultProps"],"mappings":";;;;;AAkBA,IAAMA,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AME,SAAS,GAAIf,SAAS,IAAIY,iBAAhC,CAAA;AACA,EAAMI,IAAAA,gBAAgB,GAAGlF,gBAAzB,CAAA;AAEA,EAAA,OAAOkF,gBAAgB,IAAI,CAAChB,SAArB,gBACL,oBAAC,gBAAD,EAAsBa,SAAtB,EAAkCF,WAAlC,CADK,gBAGL,oBAAC,SAAD,EAAA,IAAA,EAAYA,WAAZ,CAHF,CAAA;AAKD,CAAA;AAEDb,KAAK,CAACmB,YAAN,GAAqB;AACnBb,EAAAA,MAAM,EAAE,EADW;AAEnBC,EAAAA,UAAU,EAAE,EAAA;AAFO,CAArB;;;;"}
|
|
File without changes
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React, { ComponentType, FunctionComponent } from 'react';
|
|
2
|
+
import { I18n } from '@lingui/core';
|
|
3
|
+
|
|
4
|
+
declare type TransRenderProps = {
|
|
5
|
+
id?: string;
|
|
6
|
+
translation?: React.ReactNode;
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
message?: string | null;
|
|
9
|
+
isTranslated?: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare type TransProps = {
|
|
12
|
+
id: string;
|
|
13
|
+
message?: string;
|
|
14
|
+
values: Record<string, unknown>;
|
|
15
|
+
context?: string;
|
|
16
|
+
components: {
|
|
17
|
+
[key: string]: React.ElementType | any;
|
|
18
|
+
};
|
|
19
|
+
formats?: Record<string, unknown>;
|
|
20
|
+
children?: React.ReactNode;
|
|
21
|
+
component?: React.ComponentType<TransRenderProps>;
|
|
22
|
+
render?: (props: TransRenderProps) => React.ReactElement<any, any> | null;
|
|
23
|
+
};
|
|
24
|
+
declare function Trans(props: TransProps): React.ReactElement<any, any> | null;
|
|
25
|
+
declare namespace Trans {
|
|
26
|
+
var defaultProps: {
|
|
27
|
+
values: {};
|
|
28
|
+
components: {};
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare type I18nContext = {
|
|
33
|
+
i18n: I18n;
|
|
34
|
+
defaultComponent?: ComponentType<TransRenderProps>;
|
|
35
|
+
};
|
|
36
|
+
declare type withI18nProps = {
|
|
37
|
+
i18n: I18n;
|
|
38
|
+
};
|
|
39
|
+
declare type I18nProviderProps = I18nContext & {
|
|
40
|
+
forceRenderOnLocaleChange?: boolean;
|
|
41
|
+
children?: React.ReactNode;
|
|
42
|
+
};
|
|
43
|
+
declare function useLingui(): I18nContext;
|
|
44
|
+
declare function withI18n(o?: object): <P extends withI18nProps>(Component: ComponentType<P>) => React.ComponentType<Omit<P, 'i18n'>>;
|
|
45
|
+
declare const I18nProvider: FunctionComponent<I18nProviderProps>;
|
|
46
|
+
|
|
47
|
+
export { I18nContext, I18nProvider, I18nProviderProps, Trans, TransProps, TransRenderProps, useLingui, withI18n, withI18nProps };
|
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("./cjs/index.js")
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.16.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "React components for translations",
|
|
6
|
-
"main": "index.js",
|
|
7
|
-
"module": "esm/index.js",
|
|
8
|
-
"types": "
|
|
6
|
+
"main": "./build/cjs/index.js",
|
|
7
|
+
"module": "./build/esm/index.js",
|
|
8
|
+
"types": "./build/index.d.ts",
|
|
9
9
|
"author": {
|
|
10
10
|
"name": "Tomáš Ehrlich",
|
|
11
11
|
"email": "tomas.ehrlich@gmail.com"
|
|
@@ -29,23 +29,29 @@
|
|
|
29
29
|
"url": "https://github.com/lingui/js-lingui/issues"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
|
-
"node": ">=
|
|
32
|
+
"node": ">=14.0.0"
|
|
33
|
+
},
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"require": "./build/cjs/index.js",
|
|
37
|
+
"import": "./build/esm/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
33
40
|
},
|
|
34
41
|
"files": [
|
|
35
42
|
"LICENSE",
|
|
36
43
|
"README.md",
|
|
37
|
-
"
|
|
38
|
-
"cjs/",
|
|
39
|
-
"esm/"
|
|
44
|
+
"build/"
|
|
40
45
|
],
|
|
41
46
|
"peerDependencies": {
|
|
42
47
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
43
48
|
},
|
|
44
49
|
"dependencies": {
|
|
45
50
|
"@babel/runtime": "^7.11.2",
|
|
46
|
-
"@lingui/core": "
|
|
51
|
+
"@lingui/core": "3.16.0"
|
|
47
52
|
},
|
|
48
53
|
"devDependencies": {
|
|
49
54
|
"react-testing-library": "^8.0.1"
|
|
50
|
-
}
|
|
55
|
+
},
|
|
56
|
+
"gitHead": "e8c1f518b988f45f3f6da84333550b215dcde94b"
|
|
51
57
|
}
|
package/cjs/I18nProvider.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React, { ComponentType, FunctionComponent } from "react";
|
|
2
|
-
import { I18n } from "@lingui/core";
|
|
3
|
-
import { TransRenderProps } from "./Trans";
|
|
4
|
-
export declare type I18nContext = {
|
|
5
|
-
i18n: I18n;
|
|
6
|
-
defaultComponent?: ComponentType<TransRenderProps>;
|
|
7
|
-
};
|
|
8
|
-
export declare type withI18nProps = {
|
|
9
|
-
i18n: I18n;
|
|
10
|
-
};
|
|
11
|
-
export declare type I18nProviderProps = I18nContext & {
|
|
12
|
-
forceRenderOnLocaleChange?: boolean;
|
|
13
|
-
children?: React.ReactNode;
|
|
14
|
-
};
|
|
15
|
-
export declare function useLingui(): I18nContext;
|
|
16
|
-
export declare function withI18n(o?: object): <P extends withI18nProps>(Component: ComponentType<P>) => React.ComponentType<Omit<P, 'i18n'>>;
|
|
17
|
-
export declare const I18nProvider: FunctionComponent<I18nProviderProps>;
|
|
18
|
-
//# sourceMappingURL=I18nProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"I18nProvider.d.ts","sourceRoot":"","sources":["packages/react/src/I18nProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C,oBAAY,WAAW,GAAG;IACxB,IAAI,EAAE,IAAI,CAAA;IACV,gBAAgB,CAAC,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAA;CACnD,CAAA;AAED,oBAAY,aAAa,GAAG;IAC1B,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AAED,oBAAY,iBAAiB,GAAG,WAAW,GAAG;IAC5C,yBAAyB,CAAC,EAAE,OAAO,CAAA;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B,CAAA;AAID,wBAAgB,SAAS,IAAI,WAAW,CAUvC;AAED,wBAAgB,QAAQ,CACtB,CAAC,CAAC,EAAE,MAAM,GACT,CAAC,CAAC,SAAS,aAAa,EACzB,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,KACxB,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAmBxC;AAED,eAAO,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CA6D7D,CAAA"}
|
package/cjs/Trans.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
export declare type TransRenderProps = {
|
|
3
|
-
id?: string;
|
|
4
|
-
translation?: React.ReactNode;
|
|
5
|
-
children?: React.ReactNode;
|
|
6
|
-
message?: string | null;
|
|
7
|
-
isTranslated?: boolean;
|
|
8
|
-
};
|
|
9
|
-
export declare type TransProps = {
|
|
10
|
-
id: string;
|
|
11
|
-
message?: string;
|
|
12
|
-
values: Object;
|
|
13
|
-
context?: string;
|
|
14
|
-
components: {
|
|
15
|
-
[key: string]: React.ElementType | any;
|
|
16
|
-
};
|
|
17
|
-
formats?: Object;
|
|
18
|
-
children?: React.ReactNode;
|
|
19
|
-
component?: React.ComponentType<TransRenderProps>;
|
|
20
|
-
render?: (props: TransRenderProps) => React.ReactElement<any, any> | null;
|
|
21
|
-
};
|
|
22
|
-
export declare function Trans(props: TransProps): React.ReactElement<any, any> | null;
|
|
23
|
-
export declare namespace Trans {
|
|
24
|
-
var defaultProps: {
|
|
25
|
-
values: {};
|
|
26
|
-
components: {};
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=Trans.d.ts.map
|
package/cjs/Trans.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Trans.d.ts","sourceRoot":"","sources":["packages/react/src/Trans.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,oBAAY,gBAAgB,GAAG;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAED,oBAAY,UAAU,GAAG;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,WAAW,GAAG,GAAG,CAAA;KAAE,CAAA;IACtD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAA;IACjD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;CAC1E,CAAA;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CA0F5E;yBA1Fe,KAAK"}
|
package/cjs/format.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
/**
|
|
3
|
-
* `formatElements` - parse string and return tree of react elements
|
|
4
|
-
*
|
|
5
|
-
* `value` is string to be formatted with <0>Paired<0/> or <0/> (unpaired)
|
|
6
|
-
* placeholders. `elements` is a array of react elements which indexes
|
|
7
|
-
* correspond to element indexes in formatted string
|
|
8
|
-
*/
|
|
9
|
-
declare function formatElements(value: string, elements?: {
|
|
10
|
-
[key: string]: React.ReactElement<any>;
|
|
11
|
-
}): string | Array<any>;
|
|
12
|
-
export { formatElements };
|
|
13
|
-
//# sourceMappingURL=format.d.ts.map
|
package/cjs/format.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["packages/react/src/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AA2BzB;;;;;;GAMG;AACH,iBAAS,cAAc,CACrB,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;CAAO,GACxD,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CA6CrB;AA4BD,OAAO,EAAE,cAAc,EAAE,CAAA"}
|
package/cjs/index.d.ts
DELETED
package/cjs/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["packages/react/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,iBAAiB,EACjB,WAAW,EACX,aAAa,GACd,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react.development.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/slicedToArray"),t=require("react"),n=require("@babel/runtime/helpers/defineProperty");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(e),a=r(t),u=r(n),i=a.default.createContext(null);function l(){var e=a.default.useContext(i);return e}function c(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,u=!0,i=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return u=e.done,e},e:function(e){i=!0,a=e},f:function(){try{u||null==n.return||n.return()}finally{if(i)throw a}}}}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var s=/<(\d+)>(.*?)<\/\1>|<(\d+)\/>/,d=/(?:\r\n|\r|\n)/g,p={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0,menuitem:!0};function m(e){if(!e.length)return[];var t=e.slice(0,4),n=o.default(t,4),r=n[0],a=n[1],u=n[2],i=n[3];return[[parseInt(r||u),a||"",i]].concat(m(e.slice(4,e.length)))}var v=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return function(){return"".concat(t,"_").concat(e++)}};function y(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function b(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?y(Object(n),!0).forEach((function(t){u.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function h(e){var t=l(),n=t.i18n,r=t.defaultComponent,u=e.render,i=e.component,f=e.id,y=e.message,h=e.formats,g=b({},e.values),O=b({},e.components);g&&Object.keys(g).forEach((function(e){var t=g[e];if(a.default.isValidElement(t)){var n=Object.keys(O).length;O[n]=t,g[e]="<".concat(n,"/>")}}));var j=n&&"function"==typeof n._?n._(f,g,{message:y,formats:h}):f,P=j?function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=v(0,"$lingui$"),u=t.replace(d,"").split(s);if(1===u.length)return t;var i=[],l=u.shift();l&&i.push(l);var f,y=c(m(u));try{for(y.s();!(f=y.n()).done;){var b=o.default(f.value,3),h=b[0],g=b[1],O=b[2],j=n[h];(!j||p[j.type]&&g)&&(j?console.error("".concat(j.type," is a void element tag therefore it must have no children")):console.error("Can use element at index '".concat(h,"' as it is not declared in the original translation")),j=a.default.createElement(a.default.Fragment)),i.push(a.default.cloneElement(j,{key:r()},g?e(g,n):j.props.children)),O&&i.push(O)}}catch(e){y.e(e)}finally{y.f()}return i}(j,O):null;if(null===u||null===i)return P;var w=r||a.default.Fragment,E={id:f,message:y,translation:P,isTranslated:f!==P&&y!==P};if(u&&i)console.error("You can't use both `component` and `render` prop at the same time. `component` is ignored.");else if(u&&"function"!=typeof u)console.error("Invalid value supplied to prop `render`. It must be a function, provided ".concat(u));else if(i&&"function"!=typeof i)return console.error("Invalid value supplied to prop `component`. It must be a React component, provided ".concat(i)),a.default.createElement(w,Object.assign({},E),P);if("function"==typeof u)return u(E);var I=i||w,S=r;return S&&!i?a.default.createElement(S,Object.assign({},E),P):a.default.createElement(I,null,P)}h.defaultProps={values:{},components:{}},exports.I18nProvider=function(e){var t=e.i18n,n=e.defaultComponent,r=e.forceRenderOnLocaleChange,u=void 0===r||r,l=e.children,c=function(){return{i18n:t,defaultComponent:n}},f=function(){return u&&t.locale||"default"},s=a.default.useState(c()),d=o.default(s,2),p=d[0],m=d[1],v=a.default.useState(f()),y=o.default(v,2),b=y[0],h=y[1];return a.default.useEffect((function(){var e=t.on("change",(function(){m(c()),h(f())}));return"default"===b&&h(f()),u&&"default"===b&&console.log("I18nProvider did not render. A call to i18n.activate still needs to happen or forceRenderOnLocaleChange must be set to false."),function(){return e()}}),[]),u&&"default"===b?null:a.default.createElement(i.Provider,{value:p,key:b},l)},exports.Trans=h,exports.useLingui=l,exports.withI18n=function(e){return function(e){return function(t){var n=l(),r=n.i18n;return a.default.createElement(e,Object.assign({},t,{i18n:r}))}}};
|
|
2
|
-
//# sourceMappingURL=react.production.min.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react.production.min.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/esm/I18nProvider.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React, { ComponentType, FunctionComponent } from "react";
|
|
2
|
-
import { I18n } from "@lingui/core";
|
|
3
|
-
import { TransRenderProps } from "./Trans";
|
|
4
|
-
export declare type I18nContext = {
|
|
5
|
-
i18n: I18n;
|
|
6
|
-
defaultComponent?: ComponentType<TransRenderProps>;
|
|
7
|
-
};
|
|
8
|
-
export declare type withI18nProps = {
|
|
9
|
-
i18n: I18n;
|
|
10
|
-
};
|
|
11
|
-
export declare type I18nProviderProps = I18nContext & {
|
|
12
|
-
forceRenderOnLocaleChange?: boolean;
|
|
13
|
-
children?: React.ReactNode;
|
|
14
|
-
};
|
|
15
|
-
export declare function useLingui(): I18nContext;
|
|
16
|
-
export declare function withI18n(o?: object): <P extends withI18nProps>(Component: ComponentType<P>) => React.ComponentType<Omit<P, 'i18n'>>;
|
|
17
|
-
export declare const I18nProvider: FunctionComponent<I18nProviderProps>;
|
|
18
|
-
//# sourceMappingURL=I18nProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"I18nProvider.d.ts","sourceRoot":"","sources":["packages/react/src/I18nProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C,oBAAY,WAAW,GAAG;IACxB,IAAI,EAAE,IAAI,CAAA;IACV,gBAAgB,CAAC,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAA;CACnD,CAAA;AAED,oBAAY,aAAa,GAAG;IAC1B,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AAED,oBAAY,iBAAiB,GAAG,WAAW,GAAG;IAC5C,yBAAyB,CAAC,EAAE,OAAO,CAAA;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B,CAAA;AAID,wBAAgB,SAAS,IAAI,WAAW,CAUvC;AAED,wBAAgB,QAAQ,CACtB,CAAC,CAAC,EAAE,MAAM,GACT,CAAC,CAAC,SAAS,aAAa,EACzB,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,KACxB,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAmBxC;AAED,eAAO,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CA6D7D,CAAA"}
|
package/esm/Trans.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
export declare type TransRenderProps = {
|
|
3
|
-
id?: string;
|
|
4
|
-
translation?: React.ReactNode;
|
|
5
|
-
children?: React.ReactNode;
|
|
6
|
-
message?: string | null;
|
|
7
|
-
isTranslated?: boolean;
|
|
8
|
-
};
|
|
9
|
-
export declare type TransProps = {
|
|
10
|
-
id: string;
|
|
11
|
-
message?: string;
|
|
12
|
-
values: Object;
|
|
13
|
-
context?: string;
|
|
14
|
-
components: {
|
|
15
|
-
[key: string]: React.ElementType | any;
|
|
16
|
-
};
|
|
17
|
-
formats?: Object;
|
|
18
|
-
children?: React.ReactNode;
|
|
19
|
-
component?: React.ComponentType<TransRenderProps>;
|
|
20
|
-
render?: (props: TransRenderProps) => React.ReactElement<any, any> | null;
|
|
21
|
-
};
|
|
22
|
-
export declare function Trans(props: TransProps): React.ReactElement<any, any> | null;
|
|
23
|
-
export declare namespace Trans {
|
|
24
|
-
var defaultProps: {
|
|
25
|
-
values: {};
|
|
26
|
-
components: {};
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=Trans.d.ts.map
|
package/esm/Trans.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Trans.d.ts","sourceRoot":"","sources":["packages/react/src/Trans.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,oBAAY,gBAAgB,GAAG;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAED,oBAAY,UAAU,GAAG;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,WAAW,GAAG,GAAG,CAAA;KAAE,CAAA;IACtD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAA;IACjD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;CAC1E,CAAA;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CA0F5E;yBA1Fe,KAAK"}
|
package/esm/format.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
/**
|
|
3
|
-
* `formatElements` - parse string and return tree of react elements
|
|
4
|
-
*
|
|
5
|
-
* `value` is string to be formatted with <0>Paired<0/> or <0/> (unpaired)
|
|
6
|
-
* placeholders. `elements` is a array of react elements which indexes
|
|
7
|
-
* correspond to element indexes in formatted string
|
|
8
|
-
*/
|
|
9
|
-
declare function formatElements(value: string, elements?: {
|
|
10
|
-
[key: string]: React.ReactElement<any>;
|
|
11
|
-
}): string | Array<any>;
|
|
12
|
-
export { formatElements };
|
|
13
|
-
//# sourceMappingURL=format.d.ts.map
|
package/esm/format.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["packages/react/src/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AA2BzB;;;;;;GAMG;AACH,iBAAS,cAAc,CACrB,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;CAAO,GACxD,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CA6CrB;AA4BD,OAAO,EAAE,cAAc,EAAE,CAAA"}
|
package/esm/index.d.ts
DELETED
package/esm/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["packages/react/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,iBAAiB,EACjB,WAAW,EACX,aAAa,GACd,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA"}
|
package/esm/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
I18nProvider as devI18nProvider, Trans as devTrans, useLingui as devuseLingui, withI18n as devwithI18n
|
|
3
|
-
} from "./react.development.js"
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
I18nProvider as I18nProviderProd, Trans as TransProd, useLingui as useLinguiProd, withI18n as withI18nProd
|
|
7
|
-
} from "./react.production.min.js"
|
|
8
|
-
|
|
9
|
-
export const I18nProvider = process.env.NODE_ENV === "production" ? I18nProviderProd : devI18nProvider;
|
|
10
|
-
export const Trans = process.env.NODE_ENV === "production" ? TransProd : devTrans;
|
|
11
|
-
export const useLingui = process.env.NODE_ENV === "production" ? useLinguiProd : devuseLingui;
|
|
12
|
-
export const withI18n = process.env.NODE_ENV === "production" ? withI18nProd : devwithI18n;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react.development.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|